Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-40932: Note security caveat of shlex.quote on Windows #21502

Merged
merged 6 commits into from Nov 11, 2020

Conversation

ammaraskar
Copy link
Member

@ammaraskar ammaraskar commented Jul 16, 2020

Added a note in the subprocess docs that recommend using shlex.quote without mentioning that this is only applicable to Unix.

Also added a warning straight into the shlex docs since it only says "for simple syntaxes resembling that of the Unix shell" and says using quote plugs the security hole without mentioning this important caveat.

https://bugs.python.org/issue40932

Automerge-Triggered-By: GH:zware

@zooba
Copy link
Member

zooba commented Jul 20, 2020

See my comment on the issue, but if we decide that dividing by OS is clear enough (even though there are non-conforming shells on both OSs) then this is fine.

@sovetov
Copy link

sovetov commented Jul 27, 2020

It's a worthy note indeed. It's not only security: it'll likely fail or work incorrectly with a single quote ' in the argument.

A similar function for Windows is subprocess.list2cmdline, which quotes according to C runtime rules. Although it's up to the a program to decide how to parse a command string. E.g. cmd /c obeys it's own quoting rules.

@ammaraskar
Copy link
Member Author

ammaraskar commented Aug 24, 2020

Adjusted wording for the shlex warning based on feedback on the bug.

Doc/library/subprocess.rst Outdated Show resolved Hide resolved
Doc/library/shlex.rst Outdated Show resolved Hide resolved
Copy link
Member

@zware zware left a comment

Other than a spelling typo, I think this looks good now.

Doc/library/shlex.rst Outdated Show resolved Hide resolved
Co-authored-by: Zachary Ware <zachary.ware@gmail.com>
zware
zware approved these changes Aug 24, 2020

The ``shlex`` module is **only designed for Unix shells**.

The :func:`quote` function is not guaranteed to be safe on non-POSIX
Copy link
Member

@zooba zooba Oct 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there such a thing as a POSIX-compliant shell? Also I think "guaranteed to be correct" is better than "safe", here.

Copy link
Member Author

@ammaraskar ammaraskar Oct 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a POSIX-compliant shell

I think it's a pretty common term I've seen, loosely meaning shells that follow the posix specs here https://pubs.opengroup.org/onlinepubs/009695399/utilities/contents.html

Your wording definitely seems a bit better, changed.

@zware zware added the 🤖 automerge PR will be merged once it's been approved and all CI passed label Nov 11, 2020
@miss-islington miss-islington merged commit f9a8386 into python:master Nov 11, 2020
3 checks passed
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
…1502)

Added a note in the `subprocess` docs that recommend using `shlex.quote` without mentioning that this is only applicable to Unix. 

Also added a warning straight into the `shlex` docs since it only says "for simple syntaxes resembling that of the Unix shell" and says using `quote` plugs the security hole without mentioning this important caveat.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir 🤖 automerge PR will be merged once it's been approved and all CI passed skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants