Skip to content

🐛 fix(create): respect umask for copied Python - #3641

Merged
gaborbernat merged 1 commit into
pypa:mainfrom
gaborbernat:sec/mkjr-copied-exe-umask
Nov 20, 2026
Merged

gaborbernat merged 1 commit into
pypa:mainfrom
gaborbernat:sec/mkjr-copied-exe-umask

Conversation

@gaborbernat

Copy link
Copy Markdown
Contributor

With --copies, the builtin creator previously called make_exe() after copying each interpreter and alias. That changed a copy made under umask 077 from 0700 to 0711 in a traversable reused environment, where another local account could execute it. The copy now retains its creation mode. This addresses draft advisory ANT-2026-MKJR7DE8.

A later chmod restored masked execute bits

copy() requests mode 0755 for an executable source. Python's os.open() documentation says the current umask filters that mode at creation. The subsequent make_exe() call used chmod() to add execute bits after creation. The updated reference path leaves the copy's mode in place for both the base name and aliases.

sequenceDiagram
    participant R as ExePathRefToDest.run
    participant C as copy
    participant D as Destination file
    participant M as make_exe
    R->>+C: copy executable source
    C->>+D: create with mode filtered by umask
    D-->>-C: initial mode
    C-->>-R: copy complete
    rect rgb(255, 214, 214)
    R->>+M: before: mark copy executable
    M->>D: chmod adds execute bits
    M-->>-R: mode widened
    end
    rect rgb(216, 243, 220)
    R-->>R: now: keep creation mode
    end
Loading

Behavior changes

On POSIX, a copied executable source and its aliases retain the mode allowed by the umask: 0755 under 022, 0750 under 027, 0700 under 077, and 0744 under 011. A source with no execute bits is no longer made executable by this copy path. Symlink creation and the public make_exe() helper are unchanged; this change adds no new errors. The shared wheel image permission path is separate.

Reported by oss-scanner: ANT-2026-MKJR7DE8.

Interpreter copies already get execute bits through the copy operation,
filtered by the current umask. A later chmod restored bits the umask had
removed, allowing another local account to run copies in a traversable
environment.
@gaborbernat gaborbernat added bug security Fixes a vulnerability or hardens the supply chain, CI or release labels Nov 20, 2026
@gaborbernat
gaborbernat merged commit 4afc646 into pypa:main Nov 20, 2026
81 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug security Fixes a vulnerability or hardens the supply chain, CI or release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant