Fix arbitrary file write in /validate endpoint (VDP-2966) - #42
Merged
Conversation
The unauthenticated POST /validate endpoint passed a client-controlled filename directly into os.path.join(TMP_DIR, filename). Because os.path.join discards the base when the second argument is absolute, and no traversal/separator checks existed, a caller could write uploaded content to arbitrary locations in the Lambda's writable area (/tmp), poisoning the shared pyQuARC cache (CACHE_DIR=/tmp) or filling the disk. Changes: - Add safe_upload_path(): keep only a sanitized basename of the client filename and write into a fresh per-request /tmp/uploads/<uuid>/ directory, with a post-resolution containment check. Neutralizes absolute paths, ../ traversal, nested paths, and cross-request collisions in warm containers. Also fixes a crash when filename is omitted (path.join(TMP_DIR, None) -> TypeError). - Move wrap_inputs() inside try/finally so the per-request AUTH_TOKEN env var is always cleared and uploads are always removed, preventing token leakage into a subsequent request in a warm container. - Stop echoing auth_key and raw file content back in the response params. - Return only the uploaded file's basename in results, never the server path. - Throttle the public API stage (rate 20/burst 40) as defense in depth. CWE-22, CWE-73.
The runners dropped Python 3.8, so the lint workflow failed with "Version 3.8 with arch x64 not found", and the older action majors run on the now-deprecated Node 20. - lint.yml: setup-python@v1 (3.8) -> @v6 (3.9), matching the Lambda runtime and the deploy workflows; checkout@v2 -> @v5; wearerequired/lint-action@v1 -> @v2. - deploy.yml / update_pyquarc.yml: checkout@v2 -> @v5, configure-aws-credentials@v1 -> @v4, setup-python@v2 -> @v6. - deploy.yml: setup-node@v2 -> @v5 and bump the CDK build Node from the EOL 14.15.1 to 20 LTS.
The lint workflow flagged pre-existing issues in the deploy package: - flake8 F401: remove unused DockerImage import in stack.py. - black: reformat the BundlingOptions command list onto separate lines and drop the extra blank line in app.py. All 8 tracked Python files now pass `black --check --line-length 100` and `flake8`.
…ation Update GitHub Actions to Node 24 majors and Python 3.9
xhagrg
approved these changes
Jul 27, 2026
Merged
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.
Addresses the NASA VDP-2966 finding reported in cloud-management-project#256.
Problem
The unauthenticated
POST /validateendpoint passed a client-controlledfilenamedirectly intoos.path.join(TMP_DIR, filename). Sinceos.path.joindiscards the base path when the second argument is absolute — and there were no traversal/separator checks — a caller could steer uploaded content to arbitrary locations in the Lambda's writable area.Scope note: the Lambda root filesystem is read-only, so this is not a full arbitrary-write-to-code. But
/tmpis writable and persists across warm invocations, and the function usesCACHE_DIR=/tmpfor pyQuARC's cache. An attacker controlling the full path within/tmpcould poison that shared cache (corrupting validation results served to other users) or fill the 512 MB/tmpto DoS the function. CWE-22, CWE-73.Changes
safe_upload_path()— the client filename is never trusted for path construction. Only a sanitized basename is kept (for display), written into a fresh per-request/tmp/uploads/<uuid>/directory, with a post-resolution containment check. Neutralizes absolute paths,../traversal, nested paths, and cross-request filename collisions in warm containers. Also fixes a latent crash whenfilenameis omitted (path.join(TMP_DIR, None)→TypeError).try/finallyaround request handling —wrap_inputs()now runs inside thetry, and the per-requestAUTH_TOKENenv var is cleared and uploads are removed infinally. Previously an exception inwrap_inputs()(e.g. the missing-filename crash) skipped theAUTH_TOKENpop, leaking one user's Earthdata token into the next request in a warm container.auth_keyor rawfilecontent back inparams.[5:]/tmp/slice).Testing
Verified
safe_upload_path()contains every payload from the report (/tmp/evil.txt,../../etc/passwd,a/b/c.xml,/etc/cron.d/pwn) plusNone/empty within/tmp/uploads/<uuid>/;handler.pycompiles clean.