Disable Netlify passing query params on 302 redirect

Hello,

I’ve read through the documentation around redirects and how Netlify automatically passes the query params to the forward url when redirecting, but what I can’t figure out is how to disable this behavior when the redirect comes from a Netlify Function and not through the _redirects file or the netlify.toml.

I’m using Auth0’s NextJS library and it has an auth flow as follows:

  • User goes to /api/auth/login and is prompted to login
  • User is taken to /api/auth/callback with some query params for authentication (in this case code and state)
  • User is redirected (the Auth0 library uses res.writeHead(302, { Location: 'myapp.netlify.app/' }))
  • User lands on myapp.netlify.app/?code=...&state=...

Netlify is deploying these /api/ endpoints as Netlify Functions.

Is there a way to disable Netlify’s query param forwarding for a specific set of urls or for Functions in general? The code and state params are only relevant for the /callback endpoint and shouldn’t be maintained through the redirect.

The query parameters are removed if they’re replaced with another set of parameters. For example, a URL with /?foo=1, if redirected to /?bar will be stripped off the foo parameter. Is it possible for you to do that?

Yes, but that doesn’t really solve the issue, it replaces it with a different one.
Instead of the user getting /?code=...&state=... they would get whatever param i specified, which is better, but it’s still odd to have a random param added on that doesn’t do anything like ?t.

If this is the only solution then the feature request would be an escape hatch to skip this process when needed.
For example, if the param is ?netlify-no-query-redirect then Netlify won’t redirect any query params.