fix(sync): reject --subdir that escapes --dest - #13
Open
MarkAtwood wants to merge 2 commits into
Open
Conversation
Signed-off-by: Sameeh Jubran <sameeh@wolfssl.com>
dest_root = os.path.join(--dest, --subdir) let an absolute --subdir discard --dest entirely, and a --subdir containing .. walk out of the dest tree; copy mode then shutil.copy2-overwrote files there. Require --subdir to be relative and to resolve to a path inside --dest. Adds tests/test_wolfglass_sync.py (absolute and .. rejected, relative copies inside) and wires it into selftest.yml.
There was a problem hiding this comment.
Pull request overview
Hardens tools/wolfglass-sync against path traversal/escape via --subdir so syncing cannot overwrite files outside the intended --dest tree, and adds CI-backed regression tests for the new guard.
Changes:
- Add
--subdirvalidation to require a relative path that resolves within--dest. - Add unit tests covering absolute and
..-based escape attempts, plus a valid relative subdir case. - Wire the new test into
selftest.yml(compile + unittest execution).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tools/wolfglass-sync | Adds --subdir containment checks to prevent writing outside --dest. |
| tests/test_wolfglass_sync.py | New tests validating the containment guard (absolute and .. rejected; relative allowed). |
| .github/workflows/selftest.yml | Runs the new unit test in CI and includes it in the syntax-compile step. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+61
to
+66
| dest_abs = os.path.realpath(args.dest) | ||
| dest_root_abs = os.path.realpath(dest_root) | ||
| if dest_root_abs != dest_abs and \ | ||
| not dest_root_abs.startswith(dest_abs + os.sep): | ||
| sys.exit(f"ERROR: --subdir {args.subdir!r} escapes --dest; it must " | ||
| f"resolve to a path inside {args.dest!r}.") |
sameehj
force-pushed
the
master
branch
4 times, most recently
from
July 24, 2026 14:09
3ab77f9 to
9bdf5b7
Compare
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.
dest_root = os.path.join(--dest, --subdir)let an absolute--subdirdiscard--destentirely (os.path.join("/product", "/etc/x")→/etc/x), and a--subdircontaining..walk out of the dest tree; copy mode thenshutil.copy2-overwrote files there. Now requires--subdirto be relative and to resolve to a path inside--dest.New
tests/test_wolfglass_sync.py(absolute and..rejected with nothing written outside; a relative subdir still copies in), wired intoselftest.yml. Independent of the other open review PRs (onlyselftest.ymlis also touched by #7, in a different region).Addresses SBOM-gpex.12.