Skip to content

fix: strip internal prerender auth header from external rewrites#808

Merged
southpolesteve merged 1 commit intomainfrom
fix/strip-prerender-secret-from-external-rewrites
Apr 9, 2026
Merged

fix: strip internal prerender auth header from external rewrites#808
southpolesteve merged 1 commit intomainfrom
fix/strip-prerender-secret-from-external-rewrites

Conversation

@southpolesteve
Copy link
Copy Markdown
Collaborator

Summary

The shared external rewrite proxy now strips x-vinext-prerender-secret before forwarding requests upstream.

Details

proxyExternalRequest() intentionally forwards most request headers to match external rewrite proxying behavior, while stripping hop-by-hop and x-middleware-* headers. During vinext's prerender pipeline, internal HTTP requests carry x-vinext-prerender-secret so hidden prerender endpoints can authenticate.

That internal auth header should never be forwarded to external rewrite destinations.

This change adds a targeted strip in proxyExternalRequest() and extends the existing external rewrite forwarding tests to verify:

  • credential headers still forward
  • x-middleware-* headers are still stripped
  • x-vinext-prerender-secret is also stripped

Tests

  • tests/shims.test.ts external rewrite proxy unit test
  • tests/app-router.test.ts external rewrite integration test

The external rewrite proxy forwarded nearly all request headers upstream,
only stripping hop-by-hop and x-middleware-* headers. During the
prerender pipeline, vinext injects x-vinext-prerender-secret onto
internal HTTP requests so hidden prerender endpoints can authenticate.

If a prerendered route was externally rewritten, that internal auth
header would be forwarded to the external destination.

Strip x-vinext-prerender-secret in proxyExternalRequest(), and extend
existing unit and integration tests that cover external rewrite header
forwarding to verify the header is not leaked upstream.
@southpolesteve
Copy link
Copy Markdown
Collaborator Author

/bigbonk review this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 9, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@808

commit: eadec1d

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 9, 2026

Example Preview Production Original
app-router-cloudflare preview production
pages-router-cloudflare preview production
app-router-playground preview production original
realworld-api-rest preview production
nextra-docs-template preview production
benchmarks preview production
hackernews preview production original

Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, well-scoped security fix. The change is correct and the tests are thorough.

What this fixes: During vinext's prerender pipeline, internal HTTP requests carry x-vinext-prerender-secret to authenticate against hidden endpoints like /__vinext/prerender/static-params (verified in prod-server.ts:814 and build/prerender.ts:410,737). Without this fix, if a user configures an external rewrite and a request hits it during prerender, the internal auth secret would leak to the external service.

Correctness: The headers.delete("x-vinext-prerender-secret") call is placed correctly — after hop-by-hop and x-middleware-* header stripping, before the request is dispatched upstream. This is the only code path that proxies requests to external URLs via proxyExternalRequest(), so the fix is sufficient.

Test coverage: Both the unit test (tests/shims.test.ts) and integration test (tests/app-router.test.ts) for external rewrite proxy credential forwarding are extended to include the header in the request and assert it's stripped. The tests slot naturally into the existing "credential forwarding" test structure, verifying that:

  • Credential headers (authorization, cookie, proxy-authorization) are still forwarded
  • x-middleware-* headers are still stripped
  • x-vinext-prerender-secret is also stripped
  • Non-sensitive custom headers are preserved

CI is green across all completed checks.

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Apr 9, 2026

Reviewed and approved PR #808. The fix correctly strips the internal x-vinext-prerender-secret authentication header from external rewrite proxied requests in proxyExternalRequest(). The change is minimal (one headers.delete() call), correctly placed after existing header stripping logic, and well-tested at both the unit and integration level. CI is green.

github run

@southpolesteve southpolesteve merged commit bf37f7b into main Apr 9, 2026
32 checks passed
@southpolesteve southpolesteve deleted the fix/strip-prerender-secret-from-external-rewrites branch April 9, 2026 14:34
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.

1 participant