Skip to content

fix: reject path traversal in alias extras and validate redirect location - #645

Merged
trygve-lie merged 3 commits into
mainfrom
fix/alias-open-redirect
Aug 21, 2026
Merged

fix: reject path traversal in alias extras and validate redirect location#645
trygve-lie merged 3 commits into
mainfrom
fix/alias-open-redirect

Conversation

@trygve-lie

@trygve-lie trygve-lie commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Extras containing path traversal sequences are rejected before the alias redirect is constructed. A secondary check ensures the constructed redirect location does not resolve outside the expected origin.

The problem

A request such as:

GET /pkg/@warp-ds/css/v2/..%252F..%252F..%252F..%252F%255Cexternal.example

After one round of percent-decoding (performed by the handler), the extras become:

..%2F..%2F..%2F..%2F%5Cexternal.example

path.join treats %2F and %5C as opaque literals, so no traversal happens at the application level. However, when the redirect Location header is followed by an HTTP client that decodes percent-encoding, the path resolves through the .. segments and %5C (backslash) becomes /, producing a protocol-relative URL (//external.example) that points to an external host.

What this PR adds

Input validationvalidators.extra() from @eik/common (now non-trivial as of v5.2.1) rejects extras containing traversal sequences before the redirect is constructed.

Location guard — after constructing the redirect location, a check asserts it does not start with // or match an absolute URL scheme (https?://). This is defence-in-depth on the output, independent of input validation.

What remains allowed

Normal extras are unaffected:

  • dist/style.css → redirects to /pkg/@warp-ds/css/1.5.3/dist/style.css
  • main/index.js → redirects to /pkg/@warp-ds/css/1.5.3/main/index.js

CSS and JS relative references (e.g. url('../fonts/font.woff2')) are also unaffected. Browsers resolve .. client-side before making any HTTP request; the literal .. never arrives at EIK.

Tests

Tests are added that fail before the fix and pass after.

…tion

Extras containing parent directory references (..), backslashes, or
encoded path separators are rejected before the alias redirect is
constructed. A secondary check ensures the constructed location does not
resolve to a protocol-relative or absolute URL outside the expected
origin.
Comment thread lib/handlers/alias.get.js Outdated
validators.extra() from @eik/common now performs this validation.
The handler retains only the defence-in-depth location check that
ensures the constructed redirect stays within the expected origin.
@trygve-lie

Copy link
Copy Markdown
Contributor Author

The @eik/common package needs to be published before this one can pass test vise.

@trygve-lie
trygve-lie merged commit be1a9ef into main Aug 21, 2026
6 checks passed
@trygve-lie
trygve-lie deleted the fix/alias-open-redirect branch August 21, 2026 11:03
github-actions Bot pushed a commit that referenced this pull request Aug 21, 2026
## [2.2.2](v2.2.1...v2.2.2) (2026-08-21)

### Bug Fixes

* reject path traversal in alias extras and validate redirect location ([#645](#645)) ([be1a9ef](be1a9ef))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 2.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants