Skip to content

Use absolute paths when invoking built-in shell commands #137586

Closed

Description

@fionn

Bug report

Bug description:

On macOS, web browsers are opened via popen calling osascript.

osapipe = os.popen("osascript", "w")

However, if a user has a colliding osascript executable earlier in their PATH, this may fail or cause unwanted behaviour.

Depending on one's environment or level of paranoia, this may be considered a security vulnerability.

CPython versions tested on:

CPython main branch, 3.13

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Aug 9, 2025
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Aug 9, 2025
  3. picnixz commented on Aug 9, 2025

    @picnixz
    Member

    Note that there's also an occurrence in Lib/turtledemo/__init__.py which uses subprocess.run instead. There is also a similar occurrence in Lib/platform.py where we directly use file instead of /usr/bin/file and uname instead of /usr/bin/uname. Finally, there's another occurrence in webbrowser.py that uses xdg-settings directly.

    Unless I'm mistaken, taking control over the PATH environment variable of another user is quite complex, if not impossible most of the time if we don't have enough privilieges or if the PATH is already misconfigured. Therefore, I wouldn't really count it as a security issue as the attack surface is quite small. However, I think it's better if we use full paths instead, especially for built-in commands.

    It's quite hard to spot all places where we don't use an absolute path though.

  4. changed the title [-]Use absolute path when calling osascript[/-] [+]Use absolute paths when invoking built-in shell commands[/+] on Aug 9, 2025
  5. terryjreedy commented on Oct 17, 2025

    @terryjreedy
    Member

    This is about a simple change of the osascript path on mac for webbrowser, its test, and in turtledemo.
    @ronaldoussoren, @ned-deily can one of you verify/review the few lines of changes in the PR?

  6. added 3 commits that reference this issue on Mar 26, 2026
  7. secengjeff commented on Mar 26, 2026

    @secengjeff
    Contributor

    #146439 addresses this by replacing MacOSXOSAScript entirely with a new MacOSX class that uses /usr/bin/open via subprocess.run. This eliminates the osascript dependency rather than patching the path, which also resolves the broader usability problem of webbrowser.open() failing silently on managed endpoints where osascript is blocked.

  8. added 3 commits that reference this issue on Mar 26, 2026
  9. 21 remaining items

  10. added 4 commits that reference this issue on Apr 7, 2026
  11. added 5 commits that reference this issue on Apr 23, 2026
  12. added a commit that references this issue on Apr 25, 2026
  13. added 2 commits that reference this issue on May 6, 2026
  14. added 2 commits that reference this issue on May 8, 2026
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

    OS-macstdlibStandard Library Python modules in the Lib/ directorytype-securityA security issue

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions