fix(scripting-core): let LoadResourceFile read through symlinks again - #4108
Open
valerisn wants to merge 1 commit into
Open
fix(scripting-core): let LoadResourceFile read through symlinks again#4108valerisn wants to merge 1 commit into
valerisn wants to merge 1 commit into
Conversation
The containment check added in bef45f2 ran weakly_canonical over both the resource root and the requested path. That resolves symbolic links, so a symlinked directory inside a resource canonicalized to its target, landed outside the resource root and got rejected. Check the requested path lexically instead: reject absolute paths, paths with a root name and any path with a parent-directory component. That keeps the traversal protection the check was added for while leaving links, which only the server owner can create, alone.
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.
Goal of this PR
Fixes #4071.
LoadResourceFilestopped being able to read files that live behind a symbolic link inside a resource directory, a regression between artifacts 30819 and 30863. Symlinked subfolders inside a resource are placed there deliberately by the server owner and used to work.Cause
The containment check added in bef45f2 (
tweak(scripting/core): restrict LoadResourceFile) builds both sides of the comparison withstd::filesystem::weakly_canonical:weakly_canonicalresolves symbolic links. For the layout in the issue:LoadResourceFile(resourceA, locales/en.json)canonicalizes to/srv/shared/locales/en.json, which is not a prefix match against the resource root, so the native returnsnil. The file is inside the resource as far as the resource is concerned; only link resolution moves it out.How is this PR achieving the goal
Validates the requested path lexically instead of resolving it on disk. A path is rejected if it is absolute, has a root name, or contains any parent-directory (
..) component. Nothing touches the filesystem, so links are never followed during validation and the sandbox no longer depends on what the path happens to point at.This keeps the protection the original change was added for.
../../server.cfg,..,../x,a/../../b,C:/Windows/win.iniandC:file.txtare all still rejected, and the existing leading-slash stripping from c858b0e is untouched.The rule is slightly stricter than before in one spot:
sub/../file.jsonused to normalize back into the root and pass, and is now rejected. That is intentional. Once links are in play,..after a linked directory does not lead back to the resource root, so a path containing..cannot be reasoned about lexically and is not worth allowing. A resource has no reason to ask for one.Worth noting that scripts cannot create symbolic links in the first place, there is no native for it, so a link inside a resource is always operator intent rather than something a resource can arrange for itself.
This PR applies to the following area(s)
FXServer, Natives
Successfully tested on
The path predicate was extracted and run standalone against the cases above (allowed:
locales/en.json,en.json,./data/x.json,sub/dir/file.txt,..foo.json,a..b/c.json; rejected:../../server.cfg,..,../x,a/../../b,sub/../file.json,C:/Windows/win.ini,C:file.txt,data\..\..\x). I do not have a full server build environment set up, so this has not been exercised end to end against a live server.Checklist