Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stop pass through request params for function redirects #4897

Merged
merged 4 commits into from Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/utils/proxy.js
Expand Up @@ -201,10 +201,9 @@ const serveRedirect = async function ({ match, options, proxy, req, res }) {
// construct destination URL from redirect rule match
const dest = new URL(match.to, `${reqUrl.protocol}//${reqUrl.host}`)

// We pass through request params in one of the following cases:
// 1. The redirect rule doesn't have any query params
// 2. This is a function redirect https://github.com/netlify/cli/issues/1605
if ([...dest.searchParams].length === 0 || isFunction(options.functionsPort, stripOrigin(dest))) {
// We pass through request params if the redirect rule
// doesn't have any query params
if ([...dest.searchParams].length === 0) {
dest.searchParams.forEach((_, key) => {
dest.searchParams.delete(key)
})
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/200.command.dev.test.js
Expand Up @@ -61,7 +61,8 @@ testMatrix.forEach(({ args }) => {
])

// query params should be taken from the request
t.deepEqual(fromFunction.multiValueQueryStringParameters, { foo: ['1', '2'], bar: ['1', '2'] })
// eslint-disable-next-line id-length
t.deepEqual(fromFunction.multiValueQueryStringParameters, { a: ['1', '2'] })

// query params should be passed through from the request
t.is(queryPassthrough.headers.location, '/?foo=1&foo=2&bar=1&bar=2')
Expand Down