fix: add path containment check in View.prototype.lookup()#7142
Open
som14062005 wants to merge 1 commit intoexpressjs:masterfrom
Open
fix: add path containment check in View.prototype.lookup()#7142som14062005 wants to merge 1 commit intoexpressjs:masterfrom
som14062005 wants to merge 1 commit intoexpressjs:masterfrom
Conversation
View.prototype.lookup() used path.resolve(root, name) without verifying the resolved path stayed within the configured views directory. This inconsistency with res.sendFile() (which uses the send library root containment check) could allow path traversal when user input is passed to res.render() unsanitized. Added a containment check that skips any resolved path not starting with resolve(root) + sep. Absolute paths are intentionally exempted since Express supports passing absolute paths directly to res.render(). Fixes expressjs#7140
36830df to
84d809d
Compare
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
Adds path containment check in
View.prototype.lookup()to preventpath traversal, consistent with how
res.sendFile()handles it viathe
sendlibrary.Problem
View.prototype.lookup()calledpath.resolve(root, name)withoutverifying the result stayed inside the configured views directory.
Combined with route paaram decoding, passing user input to
res.render()could allow traversal outside the views root.
Changes
lib/view.js: AddedsepandisAbsoluteto module variablesresolve(root, name)— skips pathsthat escape the views root
Testing
Fixes #7140