Skip to content

Remove usage of tempfile.mktemp in stdlib #86444

Closed

Description

@E-Paine
mannequin
BPO 42278
Nosy @pfmoore, @ericvsmith, @tjguk, @merwok, @ambv, @zware, @serhiy-storchaka, @zooba, @dstufft, @miss-islington, @E-Paine
PRs
  • bpo-42278: Use tempfile.TemporaryDirectory rather than tempfile.mktemp in pydoc #23200
  • [3.10] bpo-42278: Use tempfile.TemporaryDirectory rather than tempfile.mktemp in pydoc (GH-23200) #28024
  • [3.9] bpo-42278: Use tempfile.TemporaryDirectory rather than tempfile.mktemp in pydoc (GH-23200) #28025
  • [3.8] bpo-42278: Use tempfile.TemporaryDirectory rather than tempfile.mktemp in pydoc (GH-23200) #28026
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-08-29.12:57:59.497>
    created_at = <Date 2020-11-06.14:57:52.124>
    labels = ['type-security', '3.8', '3.9', '3.10', '3.11', 'library', 'OS-windows']
    title = 'Remove usage of tempfile.mktemp in stdlib'
    updated_at = <Date 2021-08-29.12:57:59.496>
    user = 'https://github.com/E-Paine'

    bugs.python.org fields:

    activity = <Date 2021-08-29.12:57:59.496>
    actor = 'lukasz.langa'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-08-29.12:57:59.497>
    closer = 'lukasz.langa'
    components = ['Library (Lib)', 'Windows']
    creation = <Date 2020-11-06.14:57:52.124>
    creator = 'epaine'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42278
    keywords = ['patch']
    message_count = 11.0
    messages = ['380450', '380535', '380537', '380553', '381168', '386232', '400524', '400529', '400530', '400531', '400532']
    nosy_count = 11.0
    nosy_names = ['paul.moore', 'eric.smith', 'tim.golden', 'eric.araujo', 'lukasz.langa', 'zach.ware', 'serhiy.storchaka', 'steve.dower', 'dstufft', 'miss-islington', 'epaine']
    pr_nums = ['23200', '28024', '28025', '28026']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'security'
    url = 'https://bugs.python.org/issue42278'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10', 'Python 3.11']

    Activity

    1. E-Paine commented on Nov 6, 2020

      E-Painemannequin
      MannequinAuthor

      Currently, there are many uses of tempfile.mktemp in the stdlib. I couldn't find an issue where this has already been discussed, but I think the usage of mktemp in the stdlib should be completely reviewed. I grepped the Lib and a slightly filtered version is the following:

      Lib/asyncio/windows_utils.py:34: address = tempfile.mktemp(
      Lib/distutils/command/bdist_wininst.py:185: archive_basename = mktemp()
      Lib/distutils/util.py:386: (script_fd, script_name) = None, mktemp(".py")
      Lib/msilib/__init__.py:214: filename = mktemp()
      Lib/multiprocessing/connection.py:81: return tempfile.mktemp(prefix='listener-', dir=util.get_temp_dir())
      Lib/multiprocessing/connection.py:83: return tempfile.mktemp(prefix=r'\.\pipe\pyc-%d-%d-' %
      Lib/pydoc.py:1620: filename = tempfile.mktemp()
      Lib/test/bisect_cmd.py:75: tmp = tempfile.mktemp()
      Lib/test/test_bytes.py:1193: tfn = tempfile.mktemp()
      Lib/test/test_contextlib.py:316: tfn = tempfile.mktemp()
      Lib/test/test_doctest.py:2724: >>> fn = tempfile.mktemp()
      Lib/test/test_doctest.py:2734: >>> fn = tempfile.mktemp()
      Lib/test/test_doctest.py:2744: >>> fn = tempfile.mktemp()
      Lib/test/test_faulthandler.py:51: filename = tempfile.mktemp()
      Lib/test/test_shutil.py:1624: filename = tempfile.mktemp(dir=dirname)
      Lib/test/test_shutil.py:1935: dst_dir = tempfile.mktemp(dir=self.mkdtemp())
      Lib/test/test_shutil.py:2309: name = tempfile.mktemp(dir=os.getcwd())
      Lib/test/test_shutil.py:272: filename = tempfile.mktemp(dir=self.mkdtemp())
      Lib/test/test_shutil.py:677: dst = tempfile.mktemp(dir=self.mkdtemp())
      Lib/test/test_socket.py:699: path = tempfile.mktemp(dir=self.dir_path)
      Lib/test/test_socketserver.py:100: fn = tempfile.mktemp(prefix='unix_socket.', dir=dir)

      I am hoping this issue will be spotted as I couldn't find who to add to the nosy for this. I think, bearing in mind that use of this method is a security issue, we should reduce this number as low as feasible (though, I am sure that a number of those will have good reasons for using mktemp, and will be doing so in a safe way).

    2. added
      3.7 (EOL)
      3.10 (EOL)
      3.8 (EOL)
      3.9 (EOL)
      stdlib
      type-security
      on Nov 6, 2020
    3. 10 remaining items

    4. reopened this on Feb 3, 2021
    5. removed
      stdlib
      on Feb 3, 2021
    6. reopened this on Feb 3, 2021
    7. ambv commented on Aug 29, 2021

      @ambv
      Contributor

      New changeset c9227df by E-Paine in branch 'main':
      bpo-42278: Use tempfile.TemporaryDirectory rather than tempfile.mktemp in pydoc (GH-23200)
      c9227df

    8. ambv commented on Aug 29, 2021

      @ambv
      Contributor

      New changeset 4540951 by Miss Islington (bot) in branch '3.9':
      bpo-42278: Use tempfile.TemporaryDirectory rather than tempfile.mktemp in pydoc (GH-23200) (GH-28025)
      4540951

    9. ambv commented on Aug 29, 2021

      @ambv
      Contributor

      New changeset 193443b by Miss Islington (bot) in branch '3.8':
      bpo-42278: Use tempfile.TemporaryDirectory rather than tempfile.mktemp in pydoc (GH-23200) (GH-28026)
      193443b

    10. miss-islington commented on Aug 29, 2021

      @miss-islington
      Contributor

      New changeset 532ebba by Miss Islington (bot) in branch '3.10':
      bpo-42278: Use tempfile.TemporaryDirectory rather than tempfile.mktemp in pydoc (GH-23200)
      532ebba

    11. ambv commented on Aug 29, 2021

      @ambv
      Contributor

      Thanks, E. Paine! ✨ 🍰 ✨

    12. added
      3.11
      and removed
      3.7 (EOL)
      on Aug 29, 2021
    13. added
      3.11
      and removed
      3.7 (EOL)
      on Aug 29, 2021
    14. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)3.113.8 (EOL)3.9 (EOL)OS-windowsstdlibtype-security

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions