Skip to content

subprocess.Popen documentation should contain a good warning about the security implications when using shell=True #52198

Closed

Description

@christophneuroth
BPO 7950
Nosy @birkenfeld, @ncoghlan, @pitrou, @ericvsmith, @benjaminp, @merwok, @bitdancer, @briancurtin
Files
  • subprocess.rst.diff: first draft docs patch
  • subprocess.rst.diff: give cat an argument
  • subprocess.rst.diff: last part snipped per R. David
  • 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 = <Date 2010-11-12.00:36:42.580>
    created_at = <Date 2010-02-17.10:15:57.640>
    labels = ['type-bug', 'docs']
    title = 'subprocess.Popen documentation should contain a good warning about the security implications when using shell=True'
    updated_at = <Date 2010-11-12.00:36:42.579>
    user = 'https://bugs.python.org/christophneuroth'

    bugs.python.org fields:

    activity = <Date 2010-11-12.00:36:42.579>
    actor = 'r.david.murray'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2010-11-12.00:36:42.580>
    closer = 'r.david.murray'
    components = ['Documentation']
    creation = <Date 2010-02-17.10:15:57.640>
    creator = 'christoph.neuroth'
    dependencies = []
    files = ['18136', '18210', '18670']
    hgrepos = []
    issue_num = 7950
    keywords = ['patch']
    message_count = 14.0
    messages = ['99465', '99467', '99504', '99505', '99506', '111135', '111140', '111250', '111598', '113578', '115175', '120980', '120981', '120996']
    nosy_count = 11.0
    nosy_names = ['georg.brandl', 'ncoghlan', 'pitrou', 'eric.smith', 'benjamin.peterson', 'eric.araujo', 'r.david.murray', 'brian.curtin', 'cvrebert', 'christoph.neuroth', 'docs@python']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue7950'
    versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

    Activity

    1. christophneuroth commented on Feb 17, 2010

      christophneurothmannequin
      MannequinAuthor

      Currently, the documentation of subprocess only says "Calling the program through the shell is usually not required.". IMHO there should be a real warning (like, in its own box with a couple of big exclamation marks ;)) about the security implications of using this and detailed instructions of how to avoid it. People tend to use this functionality just because they "know how to use the shell" and its just so convenient - and by doing so they create huge security holes in their applications.

    2. ericvsmith commented on Feb 17, 2010

      @ericvsmith
      Member

      This was just discussed in bpo-6760.

    3. christophneuroth commented on Feb 18, 2010

      christophneurothmannequin
      MannequinAuthor

      You're right, that has been improved in regard to how you can do it instead. However, I still think it lacks to mention the security risk involved - compare this to e.g. os.tempnam(), which has a warning in a red box.

    4. ericvsmith commented on Feb 18, 2010

      @ericvsmith
      Member

      If you want to generate some more discussion, I suggest you close this issue and reopen the other one, since that has more people on the nosy list.

    5. christophneuroth commented on Feb 18, 2010

      christophneurothmannequin
      MannequinAuthor

      Good idea :)

    6. bitdancer commented on Jul 22, 2010

      @bitdancer
      Member

      Since the other bug was about a different topic and was closed as fixed, I'd rather have this issue open. What I've done instead is merge the nosy list from the other bug...anyone who is not interested can of course opt out of this one.

      Christoph, would you care to suggest a patch?

    7. cvrebert commented on Jul 22, 2010

      cvrebertmannequin
      Mannequin

      I'm busy with finding an apartment and taking exams for the next week-or-so, but after that I'll try and suggest a patch. If anyone wants to have a crack at it between now and then, don't let me stop you.

    8. cvrebert commented on Jul 23, 2010

      cvrebertmannequin
      Mannequin

      I found some extra time. Here's an initial suggested patch against py3k head.

      Disclaimer: I have no special expertise in computer security beyond having read "Secure Coding: Principles and Practices" a while back.

    9. cvrebert commented on Jul 26, 2010

      cvrebertmannequin
      Mannequin

      My apologies for the extra email...

    10. bitdancer commented on Aug 11, 2010

      @bitdancer
      Member

      Chris, thank you for the patch, sorry I didn't acknowledge it earlier. I think the core of the patch is good, though I will probably drop the text starting from "To safely use..." when I get time to apply it. I will also add a note along the lines of "this applies also to Windows, although the details of the exploits differ".

      I would like input from others as to whether this should indeed be a red warning box, or is adequate as a note. We try to minimize the number of red boxes, but this may well be an appropriate case for one (I'm leaning that way myself).

    11. cvrebert commented on Aug 29, 2010

      cvrebertmannequin
      Mannequin

      Adjusted patch per R. David's comment.

      I obviously think it should be a full red warning box (that's how it is in my patch), but my opinion clearly isn't an outside one.

      Also, Ping/Bump on finally getting this applied.

    12. merwok commented on Nov 11, 2010

      @merwok
      Member

      Looks good to me, except the last two lines which I would reword or just remove.

      I wonder how many people use shell=True merely for the convenience of passing a string instead of a list. What do you think about adding a mention of str.split and shlex.split?

    13. added
      type-bugAn unexpected behavior, bug, or error
      and removed on Nov 11, 2010
    14. cvrebert commented on Nov 11, 2010

      cvrebertmannequin
      Mannequin

      "the above Note" mentioned in those last two lines demonstrates shlex.split() and correct tokenization.

    15. bitdancer commented on Nov 12, 2010

      @bitdancer
      Member

      Committed (as a warning) in r86419. Thanks, Chris.

    16. transferred this issue fromon Apr 10, 2022
    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

      docsDocumentation in the Doc dirtype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions