You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@astrojs/node: trailing-slash redirect drops part of a query string that contains a second ? #17962
If this issue only occurs in one browser, which browser is a problem?
No response (server-side redirect, browser independent)
Describe the Bug
When the Node adapter's static handler issues a trailing-slash redirect, it rebuilds the Location header from fullUrl.split('?'), which keeps only the part of the query before the second ?. Any query string that itself contains a ? (a return URL, an OAuth state, a search URL) is silently truncated.
With trailingSlash: 'never':
GET /one/?redirect=/x?y=1&z=2
HTTP/1.1 301 Moved Permanently
Location: /one?redirect=/x
With trailingSlash: 'always', GET /one?redirect=/x?y=1&z=2 redirects to /one/?redirect=/x.
The splitting happens in packages/integrations/node/src/serve-static.ts (const [urlPath, urlQuery] = fullUrl.split('?')). RFC 3986 allows ? inside the query component, and the redirect is only meant to normalize the trailing slash.
Unit Test: Yes — packages/integrations/node/test/trailing-slash.test.ts (2 new test cases)
Priority:P4: important. This silently corrupts redirect URLs containing ? in the query string (e.g. OAuth callbacks, return URLs), violating RFC 3986 §3.4. Affects both trailingSlash: 'never' and trailingSlash: 'always' in standalone mode.
The root cause is in packages/integrations/node/src/serve-static.ts at line 60: fullUrl.split('?') splits on every ? in the URL, but array destructuring only keeps the first two elements. When the query string itself contains a ? (e.g. /one/?redirect=/x?y=1&z=2), everything after the second ? is silently discarded, producing a truncated Location header like /one?redirect=/x.
I found a potential fix for this issue. The fix replaces split('?') with indexOf('?') to split only on the first ?, preserving the full query string. All 36 trailing-slash tests pass (34 existing + 2 new regression tests).
Try this fix
You can test this fix right now without waiting for a release:
# @astrojs/node
npm i https://pkg.pr.new/@astrojs/node@75e7d13
If this fixes your issue, please leave a comment letting us know (for example
"confirmed, this fixes it"). A pull request will then be opened to get it merged.
Full Triage Report
Issue Title
@astrojs/node: trailing-slash redirect drops part of a query string that contains a second ?
Issue Description
When the Node adapter's static handler issues a trailing-slash redirect, it rebuilds the Location header from fullUrl.split('?'), which keeps only the part of the query before the second ?. Any query string that itself contains a ? (a return URL, an OAuth state, a search URL) is silently truncated.
RFC 3986 allows ? inside the query component, and the redirect is only meant to normalize the trailing slash.
Environment
Astro v7.3.2
Node v24.14.0
@astrojs/node v11.1.5 (mode: standalone)
output: static
Bug Location
File: packages/integrations/node/src/serve-static.ts, line 60:
const[urlPath,urlQuery]=fullUrl.split('?');
When fullUrl is /one/?redirect=/x?y=1&z=2, split('?') produces ['/one/', 'redirect=/x', 'y=1&z=2']. Only the first two elements are destructured, so urlQuery becomes just 'redirect=/x' and 'y=1&z=2' is silently discarded.
This urlQuery is then used in the trailingSlash: 'never' and trailingSlash: 'always' redirect branches:
String.prototype.split('?') splits on every ? in the string. Array destructuring assigns only the first two elements, so any query content after a second ? is silently dropped. The split('?') was introduced in commit f61248895 ("Adapter enhancements", PR #9661, Jan 2024) and has been present since trailing-slash redirect support was first implemented.
Fix
Replaced fullUrl.split('?') with fullUrl.indexOf('?') to split only on the first ?:
This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.
Activity
astro-factory commentedon Sep 10, 2026
Triage complete
triage: fix pendingpackages/integrations/node/test/trailing-slash.test.ts(2 new test cases)?in the query string (e.g. OAuth callbacks, return URLs), violating RFC 3986 §3.4. Affects bothtrailingSlash: 'never'andtrailingSlash: 'always'in standalone mode.The root cause is in
packages/integrations/node/src/serve-static.tsat line 60:fullUrl.split('?')splits on every?in the URL, but array destructuring only keeps the first two elements. When the query string itself contains a?(e.g./one/?redirect=/x?y=1&z=2), everything after the second?is silently discarded, producing a truncatedLocationheader like/one?redirect=/x.I found a potential fix for this issue. The fix replaces
split('?')withindexOf('?')to split only on the first?, preserving the full query string. All 36 trailing-slash tests pass (34 existing + 2 new regression tests).Try this fix
You can test this fix right now without waiting for a release:
# @astrojs/node npm i https://pkg.pr.new/@astrojs/node@75e7d13If this fixes your issue, please leave a comment letting us know (for example
"confirmed, this fixes it"). A pull request will then be opened to get it merged.
Full Triage Report
Issue Title
@astrojs/node: trailing-slash redirect drops part of a query string that contains a second
?Issue Description
When the Node adapter's static handler issues a trailing-slash redirect, it rebuilds the
Locationheader fromfullUrl.split('?'), which keeps only the part of the query before the second?. Any query string that itself contains a?(a return URL, an OAuthstate, a search URL) is silently truncated.RFC 3986 allows
?inside the query component, and the redirect is only meant to normalize the trailing slash.Environment
Bug Location
File:
packages/integrations/node/src/serve-static.ts, line 60:When
fullUrlis/one/?redirect=/x?y=1&z=2,split('?')produces['/one/', 'redirect=/x', 'y=1&z=2']. Only the first two elements are destructured, sourlQuerybecomes just'redirect=/x'and'y=1&z=2'is silently discarded.This
urlQueryis then used in thetrailingSlash: 'never'andtrailingSlash: 'always'redirect branches:pathname = urlPath.slice(0, -1) + (urlQuery ? '?' + urlQuery : '');pathname = urlPath + '/' + (urlQuery ? '?' + urlQuery : '');Reproduction
Steps
trailing-slashtest fixture from the node integration packagetrailingSlash: 'never'and start standalone serverGET /one/?redirect=/x?y=1&z=2Locationheader in the 301 responseActual Result
GET /one/?redirect=/x?y=1&z=2→Location: /one?redirect=/x(truncated!)GET /one?redirect=/x?y=1&z=2→Location: /one/?redirect=/x(truncated!)Expected Result
Location: /one?redirect=/x?y=1&z=2(full query preserved)Location: /one/?redirect=/x?y=1&z=2(full query preserved)Root Cause
String.prototype.split('?')splits on every?in the string. Array destructuring assigns only the first two elements, so any query content after a second?is silently dropped. Thesplit('?')was introduced in commitf61248895("Adapter enhancements", PR #9661, Jan 2024) and has been present since trailing-slash redirect support was first implemented.Fix
Replaced
fullUrl.split('?')withfullUrl.indexOf('?')to split only on the first?:Added two regression tests in
trailing-slash.test.tsusingrawRequest(to avoidfetchURL normalization):Always > Without base: verifiesGET /one?redirect=/x?y=1&z=2→Location: /one/?redirect=/x?y=1&z=2Never > Without base: verifiesGET /one/?redirect=/x?y=1&z=2→Location: /one?redirect=/x?y=1&z=2All 36 tests pass (34 existing + 2 new), no regressions.
Changeset:
.changeset/tricky-sheep-relate.md—@astrojs/node: patchThis report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.
matthewp commentedon Sep 10, 2026
Bot, I can confirm this fixes it
astro-factory commentedon Sep 10, 2026
The fix has been verified! A pull request has been created: #17964
test(node): cover query-string preservation on trailing-slash redirec…
test(node): parse Location header with exec() to satisfy lint (#17962)
Fix trailing-slash redirect truncating query strings that contain a s…