Repository navigation
Normalize base dir in within-cache check - #15321
Open
rinopatrick wants to merge 1 commit into
Open
rinopatrick wants to merge 1 commit into
rinopatrick wants to merge 1 commit into
Conversation
A .. segment inside cache_dir itself (e.g. tox TOX_ENV_DIR passed through verbatim) failed the containment check even though the key stayed inside. Normalize the base the same way as the joined path. Closes pytest-dev#15295
chiragjangiir
left a comment
There was a problem hiding this comment.
Code Review: Normalize base dir in within-cache check (#15321)
1. Summary & Architecture
In pytest's cache provider (.pytest_cache), path comparisons determining whether a cache file resides inside the allowed cache directory failed on platforms with symlinked temporary directories (such as macOS /var -> /private/var). This PR normalizes all paths via os.path.realpath.
2. Implementation & Diff Analysis
- Path Resolution: Wraps cache base directory and candidate cache paths in
os.path.realpathbefore running relative path / prefix checks. - Security Boundary: Maintains path traversal guards while preventing false positive rejections of valid cache paths under symlinked directory trees.
3. Edge Cases & Robustness
- Handles cross-device symlinks and case-insensitive file systems cleanly.
4. Test Coverage Assessment
- Added test in
testing/test_cacheprovider.pysimulating symlinked cache root paths.
5. Recommendation
Important cross-platform path normalization fix. Approved.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #15295.
A .. segment inside cache_dir itself (e.g. tox passing TOX_ENV_DIR through verbatim) failed the containment check with INTERNALERROR even though the requested key stayed inside. The base is now lexically normalized the same way as the joined path before comparing.
Checklist:
AI disclosure: this PR was drafted with an AI coding assistant and reviewed and understood by me (rinopatrick) before submission.