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

gh-68966: Document mailcap shell injection vulnerability #92024

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Doc/library/mailcap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ The mailcap format is documented in :rfc:`1524`, "A User Agent Configuration
Mechanism For Multimedia Mail Format Information", but is not an internet
standard. However, mailcap files are supported on most Unix systems.

.. _ailcap-shell-injection:

.. warning::

The Python implementation is vulnerable to shell command injection. By
design, the mailcap format uses shell commands. The caller is responsible to
validate the filename. The caller can create temporary filename, using
Copy link
Member

Choose a reason for hiding this comment

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

It's not only about the filename. The MIME type and parameter list need to be validated as well.
Also, how should they be validated? That's not clear.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, I rephrased the warning.

Copy link
Member Author

Choose a reason for hiding this comment

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

"The caller is responsible to validate and sanitize input arguments."

:func:`tempfile.NamedTemporaryFile` or :func:`tempfile.mkstemp` for example,
to get a safe filename.


.. function:: findmatch(caps, MIMEtype, key='view', filename='/dev/null', plist=[])

Expand Down
1 change: 1 addition & 0 deletions Doc/library/security_warnings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The following modules have specific security considerations:
basic security checks
* :mod:`logging`: :ref:`Logging configuration uses eval()
<logging-eval-security>`
* :mod:`mailcap`: :ref:`Shell command injection <mailcap-shell-injection>`
* :mod:`multiprocessing`: :ref:`Connection.recv() uses pickle
<multiprocessing-recv-pickle-security>`
* :mod:`pickle`: :ref:`Restricting globals in pickle <pickle-restrict>`
Expand Down