Escape "."/".." path components so a lane name cannot escape lanes/#1703
Open
jax-0n-git wants to merge 1 commit into
Open
Escape "."/".." path components so a lane name cannot escape lanes/#1703jax-0n-git wants to merge 1 commit into
jax-0n-git wants to merge 1 commit into
Conversation
`CoordinatorPaths.fileComponent(for:)` percent-encodes path separators so a
resource/lane name stays a single child component, but it passes `.` (byte 46)
through verbatim. A component of only "." or ".." therefore survives unescaped,
and `laneDirectory(named:)` appends it directly:
- `laneDirectory(named: "..")` -> `<root>/lanes/..` -> standardizes to `<root>`
(one level *above* the lanes/ container)
- `laneDirectory(named: ".")` -> `<root>/lanes/.` -> the lanes/ dir itself
This defeats the function's own contract (the existing
`testLockFileComponentEscapesPathSeparators` exists to enforce that a name
cannot leave its container). Multi-segment traversal like `../../etc` is
already blocked because `/` is escaped to `%2F`; only a bare single-segment
"." / ".." slips through.
Percent-encode the dots when the whole sanitized component is "." or "..".
Dots inside longer names (`Foo.swift`, `v1.2.3`) are unaffected, so the
existing separator-escaping test still passes.
Adds tests for the dot-segment encoding, the unchanged in-name dots, and that
`laneDirectory(named:)` stays strictly under lanes/ for both "." and "..".
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Summary
CoordinatorPaths.fileComponent(for:)exists to neutralize path separators so a resource/lane name stays a single child component (the existingtestLockFileComponentEscapesPathSeparatorsenforcesPackages/Foo.swift->Packages%2FFoo.swift). But it passes.(byte 46) through verbatim, so a component of only.or..survives unescaped, andlaneDirectory(named:)appends it directly:laneDirectory(named: "..")-><root>/lanes/..-> standardizes to<root>— one level above thelanes/containerlaneDirectory(named: ".")-><root>/lanes/.-> thelanes/directory itselfMulti-segment traversal like
../../etcis already blocked (/is escaped to%2F); only a bare single-segment./..slips through. There is no untrusted caller today (CoordinatorBootstrapuses a fixed lane list), so this is a defense-in-depth correctness fix for a public sanitization API, not an exploitable path in current code.The fix percent-encodes the dots when the whole sanitized component is
.or... Dots inside longer names (Foo.swift,v1.2.3) are unaffected, so the existing separator test still passes.Changes
Test Plan
swift testinPackages/OsaurusCLI(91 tests green, +3 new) +swift-format lint --strictclean. New tests:./..encode to%2E/%2E%2E(fail on pre-fix), dots inside names pass through unchanged, andlaneDirectory(named:)stays strictly underlanes/for both.and... No MLX/GUI dependency.