fix: prevent backward relative paths in readme #2354
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.35) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.35 · 170 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.308
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #2354"
general
weight: 0.35
cjames23
Fixes #2353
What this PR does
This PR prevents a directory traversal risk and downstream extraction failures caused by backward relative paths in the
readmefield ofpyproject.toml.Previously, if a user specified
readme = "../README.md", Hatchling would silently package the sdist with../README.mdin the archive's file list. When users attempted to extract this sdist, modern versions of Python'starfilemodule would raise a security exception (e.g.,tarfile.OutsideDestinationError), or older versions would risk overwriting files outside the extraction directory.How it was fixed
Added security checks in
backend/src/hatchling/metadata/core.pyto validate that the resolvedreadmepath resides within the project root.readme = "...") and the dictionary definition (readme = {file = "..."}).os.path.isabs()andos.path.relpath().startswith("..")to detect invalid paths.ValueErrorat build time if a violation is detected.Manual Testing
Tested locally using
--no-isolationon a mock project withreadme = "../README.md". The build now correctly fails fast before packaging:```text
ValueError: Readme path must be within the project directory: ../README.md
ERROR Backend subprocess exited when trying to invoke build_sdist