fix(planner): replace insecure pickle artifacts with path-confined, validated NPZ loading - #1
Open
mozluk wants to merge 2 commits into
Open
fix(planner): replace insecure pickle artifacts with path-confined, validated NPZ loading#1mozluk wants to merge 2 commits into
mozluk wants to merge 2 commits into
Conversation
…alidated NPZ loading ### Description This PR addresses high-severity input validation and deserialization safety vulnerabilities within the `PCT_planner` repository[cite: 11]. It completely migrates the tomogram artifact system from vulnerable executable `.pickle` files to secure, non-object NumPy `.npz` archives, effectively neutralizing arbitrary code execution and path traversal risks[cite: 11]. ### Key Changes * **Safe Artifact Generation (`tomography/scripts/tomography.py`):** - Changed the tomogram export format from `pickle` to compressed NumPy archives (`.npz`)[cite: 11]. - The `exportTomogram` function now explicitly uses `np.savez_compressed` to package the required data structures safely[cite: 21]. * **Strict Loading & Path Confinement (`planner/scripts/planner_wrapper.py`):** - Replaced the vulnerable `pickle` reader with `np.load(..., allow_pickle=False)` to strictly disable NumPy object loading[cite: 11, 20]. - Introduced the `_resolve_tomogram_path` helper to enforce path confinement, ensuring that caller-controlled filenames cannot break out of the configured `tomo_dir` via path traversal attacks[cite: 11, 20]. - Added strict schema validation upon load to verify that all required keys (`data`, `resolution`, `center`, `slice_h0`, `slice_dh`) are present and that the tensor shape is exactly as expected[cite: 11, 20]. * **Documentation & Tooling (`planner/scripts/plan_global.py`, `README.md`, `.gitignore`):** - Updated CLI arguments in `plan_global.py` to specify that tomogram filenames should be provided without the `.npz` extension[cite: 22]. - Updated `README.md` to document the new `.npz` export format and explicitly state that legacy pickle artifacts are intentionally rejected and must be regenerated[cite: 11, 23]. - Added `*.npz` to `.gitignore` to prevent tracking generated artifacts, while retaining the legacy `*.pickle` exclusion[cite: 11, 24]. ### Action Required * Existing tomogram `.pickle` artifacts are incompatible with this update and must be regenerated as `.npz` files[cite: 11, 23]. * A human reviewer must verify the native NumPy runtime execution locally, as the test environment lacked the required `numpy` dependencies to perform a full integration round-trip[cite: 11].
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.
Description
This PR addresses high-severity input validation and deserialization safety vulnerabilities within the
PCT_plannerrepository[cite: 11]. It completely migrates the tomogram artifact system from vulnerable executable.picklefiles to secure, non-object NumPy.npzarchives, effectively neutralizing arbitrary code execution and path traversal risks[cite: 11].Key Changes
tomography/scripts/tomography.py):pickleto compressed NumPy archives (.npz)[cite: 11].exportTomogramfunction now explicitly usesnp.savez_compressedto package the required data structures safely[cite: 21].planner/scripts/planner_wrapper.py):picklereader withnp.load(..., allow_pickle=False)to strictly disable NumPy object loading[cite: 11, 20]._resolve_tomogram_pathhelper to enforce path confinement, ensuring that caller-controlled filenames cannot break out of the configuredtomo_dirvia path traversal attacks[cite: 11, 20].data,resolution,center,slice_h0,slice_dh) are present and that the tensor shape is exactly as expected[cite: 11, 20].planner/scripts/plan_global.py,README.md,.gitignore):plan_global.pyto specify that tomogram filenames should be provided without the.npzextension[cite: 22].README.mdto document the new.npzexport format and explicitly state that legacy pickle artifacts are intentionally rejected and must be regenerated[cite: 11, 23].*.npzto.gitignoreto prevent tracking generated artifacts, while retaining the legacy*.pickleexclusion[cite: 11, 24].Action Required
.pickleartifacts are incompatible with this update and must be regenerated as.npzfiles[cite: 11, 23].numpydependencies to perform a full integration round-trip[cite: 11].