docs: warn that getFromResource does not filter its resource name - #1263
Open
pjfanning wants to merge 1 commit into
Open
docs: warn that getFromResource does not filter its resource name#1263pjfanning wants to merge 1 commit into
pjfanning wants to merge 1 commit into
Conversation
Motivation: `getFromResource` passes the resource name to the class loader as given. Its only guard is the trailing-slash check that stops directory resources being served; unlike `getFromResourceDirectory`, which routes the request path through `safeJoinPaths` and rejects `..` and separator characters, it applies no traversal filtering at all. An application that builds the name from request input, for example `getFromResource(s"public/$name")`, can therefore be made to resolve a resource outside the intended prefix against a directory-backed class loader. The scaladoc did not say so, and the contrast with the sibling directive makes that easy to miss. Modification: Document the behaviour on both the Scala and the Java DSL entry points, pointing at `getFromResourceDirectory` as the filtering alternative. Result: The trust boundary of the directive is stated where a caller reads it. Tests: Not run - docs only References: None - documents that getFromResource does not filter its resource name
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.
Motivation
getFromResourcepasses the resource name to the class loader as given:Its only guard is the trailing-slash check that stops directory resources being served. Unlike
getFromResourceDirectory— which routes the request path throughsafeJoinPathsand rejects..and separator characters — it applies no traversal filtering at all.An application that builds the name from request input, for example
getFromResource(s"public/$name"), can therefore be made to resolve a resource outside the intended prefix against a directory-backed class loader (application.conf,logback.xml, …). That matches the trust model of the low-levelgetFromFile, but the scaladoc did not say so, and the contrast with the sibling directive makes it easy to miss.Not exploitable through the
getFromResourceDirectorywrapper, which is unaffected.Modification
Document the behaviour on both the Scala and the Java DSL entry points, pointing at
getFromResourceDirectoryas the filtering alternative. No behaviour change.Result
The trust boundary of the directive is stated where a caller reads it.
Tests
Not run - docs only
(
sbt http/compileandsbt http/mimaReportBinaryIssuesboth pass; nativescalafmtclean.)References
None - documents that getFromResource does not filter its resource name
🤖 Generated with Claude Code