fix(runtime): decide path containment with relative(), not a string prefix - #518
Merged
Conversation
…refix
The runtime package server tested containment with
absPath.startsWith(`${nodeModulesDir}/`). The separator is hard-coded to
POSIX, so on Windows hosts, where resolve() yields backslashes, the check
was false for every legitimate path and the endpoint 404'd all runtime
package assets. It fails closed, so this is an availability bug rather
than a bypass, but the code is wrong either way.
Containment now goes through a shared isPathWithin helper that decides
with path.relative(), which is separator-correct on both platforms.
assertPathWithin delegates to it, and the '..' test compares a whole
segment so a child legitimately named '..foo' is no longer read as an
escape.
The same sweep found the inverse spelling in virtualSiteWorkspace, a
prefix check with no separator at all, which would accept a sibling
directory whose name merely begins with the root. Routed through the same
helper.
Reported as GHSA-hwp9-vc7h-gvvf.
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.
The bug
The runtime package server tested containment with
absPath.startsWith(${nodeModulesDir}/). The separator is hard-coded to POSIX, so on Windows hosts, whereresolve()yields backslashes, the check was false for every legitimate path and the endpoint 404'd all runtime package assets. Windows is a supported target: the release workflow ships awindows-x64server build.It fails closed, so this is an availability bug rather than a bypass. The code is wrong either way.
The fix
Containment now goes through a shared
isPathWithinhelper that decides withpath.relative(), which is separator-correct on both platforms.assertPathWithindelegates to it, and the..test compares a whole segment so a child legitimately named..foois no longer read as an escape.The same sweep found the inverse spelling in
virtualSiteWorkspace, a prefix check with no separator at all, which would accept a sibling directory whose name merely begins with the root. Routed through the same helper.Reported as GHSA-hwp9-vc7h-gvvf.
Verification
Notes
New unit tests cover the sibling-prefix and
..foocases, which are observable on POSIX. The Windows separator behaviour itself comes frompath.relative()being platform-native.