Skip to content

fix: add path containment check in View.prototype.lookup()#7142

Open
som14062005 wants to merge 1 commit intoexpressjs:masterfrom
som14062005:fix/view-lookup-path-containment
Open

fix: add path containment check in View.prototype.lookup()#7142
som14062005 wants to merge 1 commit intoexpressjs:masterfrom
som14062005:fix/view-lookup-path-containment

Conversation

@som14062005
Copy link
Copy Markdown

Summary

Adds path containment check in View.prototype.lookup() to prevent
path traversal, consistent with how res.sendFile() handles it via
the send library.

Problem

View.prototype.lookup() called path.resolve(root, name) without
verifying 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: Added sep and isAbsolute to module variables
  • Added containment check after resolve(root, name) — skips paths
    that escape the views root
  • Absolute paths are exempted (Express intentionally supports them)

Testing

  • All 1247 existing tests pass
  • 2 pending tests are pree-existing, unrelated to this change

Fixes #7140

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
@som14062005 som14062005 force-pushed the fix/view-lookup-path-containment branch from 36830df to 84d809d Compare March 31, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

View.prototype.lookup() lacks path containment check (unlike send library for res.sendFile)

1 participant