GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Restore os.makedirs ability to apply mode to all directories created · Issue #86533 · python/cpython

Restore os.makedirs ability to apply mode to all directories created #86533

New issue
Copy link
New issue
Copy link
Closed
Closed
Restore os.makedirs ability to apply mode to all directories created#86533
Copy link
Assignees
gpshead
Labels
3.15bugs and security fixesbugs and security fixessprintstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

@gpshead
gpshead
opened on Nov 16, 2020
Issue body actions
BPO 42367
Nosy @gpshead, @tiran, @serhiy-storchaka, @ZackerySpytz, @JustAnotherArchivist, @kartiksubbarao
PRs
  • gh-86533: Restore os.makedirs() ability to apply *mode* recursively #23901
  • 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 = None
    created_at = <Date 2020-11-16.09:54:11.492>
    labels = ['type-feature', 'library', '3.11']
    title = 'Restore os.makedirs ability to apply mode to all directories created'
    updated_at = <Date 2021-11-22.21:16:30.185>
    user = 'https://github.com/gpshead'

    bugs.python.org fields:

    activity = <Date 2021-11-22.21:16:30.185>
    actor = 'gregory.p.smith'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2020-11-16.09:54:11.492>
    creator = 'gregory.p.smith'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42367
    keywords = ['patch', '3.7regression']
    message_count = 5.0
    messages = ['381082', '381084', '381086', '381087', '406802']
    nosy_count = 7.0
    nosy_names = ['gregory.p.smith', 'christian.heimes', 'serhiy.storchaka', 'ZackerySpytz', 'JustAnotherArchivist', 'kartiksubbarao', 'awtimmering']
    pr_nums = ['23901']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue42367'
    versions = ['Python 3.11']

    Linked PRs

    • gh-86533: Restore os.makedirs() ability to apply *mode* recursively #150011
    • [3.15] gh-86533: Restore os.makedirs() ability to apply *mode* recursively (GH-150011) #150036
    • gh-86533: Make Path.mkdir parent_mode tests umask-independent #150040
    Reacted by Jakub Wilk and nessita

    Activity

    Next
    1. gpshead commented on Nov 16, 2020

      @gpshead
      gpshead
      on Nov 16, 2020
      MemberAuthor
      More actions

      os.makedirs used to pass its mode argument on down recursively so that every level of directory it created would have the specified permissions.

      That was removed in Python 3.7 as https://bugs.python.org/issue19930 as if it were a mis-feature. Maybe it was in one situation, but it was also a desirable *feature*. It wasn't a bug.

      We've got 15 year old code depending on that and the only solution for it to work on Python 3.7-3.9 is to reimplement recursive directory creation. :(

      This feature needs to be brought back. Rather than flip flop on the API, adding an flag to indicate if the permissions should be applied recursively or not seems like the best way forward.

      The "workaround" documented in the above bug is invalid. umask cannot be used to control the intermediate directory creation permissions as that is a process wide global that would impact other threads or signal handlers. umask also cannot be used as umask does not allow setting of special bits such as stat.S_ISVTX.

      result: Our old os.makedirs() code that tried to set the sticky bit (ISVTX) on all directories now fails to set it at all levels.

    2. gpshead
      added
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      3.10 (EOL)end of lifeend of life
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      on Nov 16, 2020
    3. gpshead commented on Nov 16, 2020

      @gpshead
      gpshead
      on Nov 16, 2020
      MemberAuthor
      More actions

      For consistency, pathlib.Path.mkdir should also gain this option.

    4. gpshead
      added
      type-featureA feature request or enhancementA feature request or enhancement
      and removed
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Nov 16, 2020
    5. serhiy-storchaka commented on Nov 16, 2020

      @serhiy-storchaka
      serhiy-storchaka
      on Nov 16, 2020
      Member
      More actions

      Alternatively we can add an optional argument for the mode of intermediate directories.

      makedirs(name, mode=0o777, exist_ok=False, intermediate_mode=0o777)
    6. tiran commented on Nov 16, 2020

      @tiran
      tiran
      on Nov 16, 2020
      Member
      More actions

      +1 for restoring the feature

      +0 for Serhiy's proposal iff intermediate_mode defaults to the value of mode:

          def makedirs(name, mode=0o777, exist_ok=False, *, intermediate_mode=None):
              if intermediate_mode is None:
                  intermediate_mode = mode
    7. gpshead
      added
      3.11only security fixesonly security fixes
      on Oct 26, 2021
    8. 20 remaining items

    9. github-project-automation
      added this to Sprinton May 18, 2026
    10. github-project-automation
      moved this to Todo in Sprinton May 18, 2026
    11. gpshead commented on May 18, 2026

      @gpshead
      gpshead
      on May 18, 2026
      MemberAuthor
      More actions

      @hugovk as 3.15 release manager: Would you consider the fix for this adding a new parent_mode=None keyword only argument to os.makedirs() and for use in pathlib.mkdir(..., parents=True) viable as a feature to add to 3.15? It is security related and we've had it open for ages as it exists to fix a it is security regression that shipped in 3.7. it doesn't change behavior, just adds a new optional keyword argument. I could make the argument that we should backport it to others given the security workarounds things like Django have had to adopt as a result (but they'll need to carry those anyways so probably best not to)... but adding it to 3.15beta2 seems uncontroversial and not likely to trip anyone up and avoids delaying yet another year. - #150011

      Reacted by nessita
    12. gpshead
      removed this from Sprinton May 18, 2026
    13. hugovk commented on May 18, 2026

      @hugovk
      hugovk
      on May 18, 2026
      Member
      More actions

      Yes, that's fine for 3.15beta2.

      Reacted by Seth Larson and Gregory P. Smith
    14. JordanHyatt
      added a commit that references this issue on May 18, 2026

      Fixed CVE-2026-25674 -- Prevented potentially incorrect permissions o…

      e944cf1
    15. gpshead
      added 6 commits that reference this issue on May 18, 2026

      pythongh-86533: Clarify parent_mode umask docs and harden makedirs/mk…

      6870753

      gh-86533: Restore os.makedirs() ability to apply *mode* recursively (G…

      9770e32

      pythongh-86533: Make Path.mkdir parent_mode tests umask-independent

      036510e

      Merge branch 'main' into pythongh-86533-fix-mkdir-test-umask

      064e43d

      gh-86533: Make Path.mkdir parent_mode tests umask-independent (#150040)

      68ebc05

      [3.15] gh-86533: Restore os.makedirs() ability to apply *mode* recurs…

      28f275f
    16. gpshead commented on May 19, 2026

      @gpshead
      gpshead
      on May 19, 2026
      MemberAuthor
      More actions

      thanks! this ships in 3.15beta2 onwards.

      Reacted by Hugo van Kemenade
    17. gpshead
      closed this as completedon May 19, 2026
    18. MarkoM-dot
      added a commit that references this issue on Aug 28, 2026

      Fixed CVE-2026-25674 -- Prevented potentially incorrect permissions o…

      cfc53b0
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    • @gpshead
      gpshead

    Labels

    3.15bugs and security fixesbugs and security fixessprintstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.