Skip to content

Harden redirect handling for catch-all parameters#15743

Merged
matthewp merged 1 commit intomainfrom
fix/redirect-open-redirect
Mar 4, 2026
Merged

Harden redirect handling for catch-all parameters#15743
matthewp merged 1 commit intomainfrom
fix/redirect-open-redirect

Conversation

@matthewp
Copy link
Contributor

@matthewp matthewp commented Mar 3, 2026

Changes

  • redirectIsExternal() now detects protocol-relative URLs (//) in addition to http:// and https://
  • Route generator uses collapseDuplicateLeadingSlashes when building segments to prevent double leading slashes in output

Practically what htis means is a redirect like:

  • redirects: { '/old/[...slug]': '/[...slug]' }

With a request like /old//evil.com/ would redirect to evil.com. This is defense in depth, a vulnerability would be required that creates path relative links to take advantage of this.

Testing

Unit tests added in packages/astro/test/units/redirects/open-redirect.test.js covering both redirectIsExternal and getRouteGenerator.

Docs

N/A, bug fix

@changeset-bot
Copy link

changeset-bot bot commented Mar 3, 2026

🦋 Changeset detected

Latest commit: a9cb14a

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Mar 3, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 3, 2026

Merging this PR will not alter performance

✅ 18 untouched benchmarks


Comparing fix/redirect-open-redirect (a9cb14a) with main (e6e146c)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (29682f3) during the generation of this report, so e6e146c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@matthewp matthewp marked this pull request as ready for review March 3, 2026 21:53
@matthewp matthewp merged commit 3b4252a into main Mar 4, 2026
26 checks passed
@matthewp matthewp deleted the fix/redirect-open-redirect branch March 4, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants