Skip to content

Conversation

ParzivalHack
Copy link

@ParzivalHack ParzivalHack commented Aug 25, 2025

This pull request addresses a path traversal vulnerability in the Tools/ssl/multissltests.py script. The vulnerability allows for a crafted tarball to write an arbitrary file to a location outside of the intended build directory due to a lack of sanitization in the _unpack_src method's handling of tarball member names.

A comprehensive, self-contained PoC script was used to demonstrate the issue (and shared with the PSRT), confirming the Path Traversal. The fix implemented in this PR ensures that each tarball member is manually extracted with a path check, preventing any file from escaping the designated directory. This approach provides a clear and robust solution to the issue.

As this is a test script, and not a production component, the Python Security Response Team (PSRT) has advised me to submitt it as a public enhancement. This fix ensures the integrity and robustness of the tool, by preventing an unprivileged file write that could lead to unexpected behavior.

I am submitting this enhancement to improve the overall quality of the CPython test suite. If necessary, I'm available to provide any additional information required for review.

Fix of a Path Traversal vulnerability in a test script in multissltests.py
@python-cla-bot
Copy link

python-cla-bot bot commented Aug 25, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

This comment was marked as resolved.

@StanFromIreland StanFromIreland added skip news tests Tests in the Lib/test dir topic-SSL labels Aug 25, 2025
Copy link
Member

@AA-Turner AA-Turner left a comment

Choose a reason for hiding this comment

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

It seems you have several unrelated whitespace changes; please revert.

A

@bedevere-app
Copy link

bedevere-app bot commented Aug 26, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@StanFromIreland
Copy link
Member

StanFromIreland commented Aug 26, 2025

FYI These are the whitespace changes that should be reverted:

image

Reverted the unrelated whitespace changes
@ParzivalHack
Copy link
Author

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented Aug 26, 2025

Thanks for making the requested changes!

@AA-Turner: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from AA-Turner August 26, 2025 07:58
Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

This PR overcomplicates a script that is already complex. The URLs are safe as they are hardcoded. I don't think we need to worry about this kind of attack, unless upstream is affected (namely official openssl, libressl or aws-lc repositories).

Has this PR been generated by AI?

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

Whatever we choose to do, an issue should be opened first. However, I don't think such change is needed, but to be on the perfectly safe side, we could just specify the filter in extractall.

@bedevere-app
Copy link

bedevere-app bot commented Aug 26, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

ParzivalHack and others added 2 commits August 26, 2025 11:40
Remove additional whitespace

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
This commit refactors the _unpack_src function to use the filter='data' argument in tarfile.extractall(). This change addresses the path traversal vulnerability more robustly, as suggested during code review. It also improves code clarity and removes the need for manual path validation checks.
@ParzivalHack
Copy link
Author

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented Aug 26, 2025

Thanks for making the requested changes!

@AA-Turner, @picnixz: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from picnixz August 26, 2025 10:16
Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

Could you open an issue as well? TiA.

@picnixz picnixz dismissed their stale review August 26, 2025 10:23

Changes were made.

@picnixz
Copy link
Member

picnixz commented Aug 26, 2025

I will be leaving soon and will only come back on Thursday so I won't be able to check/merge this one.

Removed the remaining whitespace
@ParzivalHack ParzivalHack changed the title Fix Path Traversal in multissltests.py gh-138158: Fix Path Traversal in multissltests.py Aug 26, 2025
@AA-Turner AA-Turner changed the title gh-138158: Fix Path Traversal in multissltests.py gh-138158: Use the 'data' tarfile filter for Tools/ssl/multissltests Aug 26, 2025
@AA-Turner AA-Turner changed the title gh-138158: Use the 'data' tarfile filter for Tools/ssl/multissltests gh-138158: Use the 'data' tarfile filter for multissltests Aug 26, 2025
Copy link
Member

@AA-Turner AA-Turner left a comment

Choose a reason for hiding this comment

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

Using the data filter seems harmless. I agree with Ben (& the PSRT) though that there is no practical 'vulnerability' here, so this is largely a change for theoretical purposes. As such, I'm +0; will leave to someone else to decide to merge.

A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants