Skip to content

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

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

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

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

Copy link
Member

@zware zware left a comment

Choose a reason for hiding this comment

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

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

Co-authored-by: Zachary Ware <[email protected]>

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

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

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.

@miss-islington miss-islington merged commit f9a8386 into python:master Nov 11, 2020
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 skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants