Repository navigation
security: harden release artifact validation - #495
codeforester wants to merge 3 commits into
Conversation
c8541ec to
3660261
Compare
| relative = name[len(root_prefix) :] | ||
| if relative not in ALLOWED_SDIST_FILES and not relative.startswith(ALLOWED_SDIST_PREFIXES): | ||
| fail(f"{path.name} contains non-allowlisted archive member {relative!r}") | ||
| package_prefix = "lib/python/base_cli/" |
There was a problem hiding this comment.
Robustness: this hardcodes the package path prefix as the literal string "lib/python/base_cli/" instead of deriving it from the IMPORT_NAME constant used everywhere else in this file. If IMPORT_NAME is ever changed, every other call site updates automatically via the constant, but this literal silently stops matching any real package file — relative.startswith(package_prefix) then never fires, and the new sha256 hash-verification control for sdist package files silently stops applying to anything, with no error raised.
| @@ -64,7 +67,40 @@ def expected_package_files() -> set[str]: | |||
| package_root = Path(__file__).resolve().parents[1] / "lib" / "python" / IMPORT_NAME | |||
There was a problem hiding this comment.
Cleanup (dead code / drift risk): expected_package_files() is now dead — main() only calls expected_package_hashes() and derives the files set from its keys — but expected_package_hashes() re-implements the identical rglob/filter traversal from scratch instead of reusing expected_package_files(). Both copies independently skip __pycache__/.pyc; a future edit to that filtering rule applied to only one copy would silently desync the file-allowlist from the hash-allowlist, and the unused function remains as a misleading signal that it's still part of the validation path.
|
Implemented the review fixes in commit
|
|
Addressed the remaining lint and maintainability feedback in commit
The directory-entry and symlink regression tests remain in place. |
Summary
base_clifiles byte-for-byte with the reviewed source treescripts/in sdistsSecurity rationale
The release validator now fails closed before installation. It checks both wheel and sdist content and does not import or execute the artifact while validating it.
Validation
UV_CACHE_DIR=/private/tmp/base-cli-uv-cache uv run --extra dev pytest -q tests/test_validate_package_artifact.pyUV_CACHE_DIR=/private/tmp/base-cli-uv-cache uv run --extra dev python -m build --wheel --sdistUV_CACHE_DIR=/private/tmp/base-cli-uv-cache uv run --extra dev python scripts/validate_package_artifact.py distgit diff --checkpassRelates to #486.