You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PathFence.apply() calls path.normalize().toAbsolutePath(), so leading .. segments survive normalize() and toAbsolutePath() then prepends the working directory. The component-wise startsWith(root) check matches the prefix even though the real path escapes the fence, e.g. ${file:UTF-8:../secret} reads outside a fence rooted at the working directory. Resolve to absolute first, then normalize, for both the roots and the candidate path.
@dxbjavid
Thank you for the PR.
You must provide a unit test that fails when the changes to main are not applied. Otherwise, this is a regression waiting to happen.
Added one. The existing ../ tests only passed because the escaped file didn't exist, so the read failed and got rethrown as IllegalArgumentException anyway. The new test in FileStringLookupTest points a relative .. path at a real file outside the fence: on current main the fence lets it through and the file is read (nothing thrown), with the fix it's rejected.
Hello @dxbjavid
Thank you for your prompt update.
I can see the new test failing now without the main changes; BUT the changes to the constructor are not needed for the test to pass.
Would you please add another test to validate the change to the constructor?
TY!
Added testFenceRootWithParentSegment. It builds a fence rooted at target/.. (which resolves to the working dir) and reads an in-fence file. Without the constructor normalize the root keeps the trailing .., so the component-wise startsWith never matches and the legit file is wrongly rejected. The test fails on main and passes with the fix.
garydgregory
changed the title
fix path fence bypass for relative paths with leading ..
Fix path fence bypass for relative paths with leading ..
Jun 1, 2026
garydgregory
changed the title
Fix path fence bypass for relative paths with leading ..
Fix path fence bypass for relative paths with leading ".."
Jun 1, 2026
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
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.
PathFence.apply() calls path.normalize().toAbsolutePath(), so leading .. segments survive normalize() and toAbsolutePath() then prepends the working directory. The component-wise startsWith(root) check matches the prefix even though the real path escapes the fence, e.g. ${file:UTF-8:../secret} reads outside a fence rooted at the working directory. Resolve to absolute first, then normalize, for both the roots and the candidate path.