Query parameters in redirects

I have a case, where a lambda function is modifying my response Location header by adding current query parameters during redirect. How can we avoid that?

Function accepts callback from OAuth provider, and it is invoked like this: /.netlify/functions/oauth-callback?token=1&secret=2

At the end of function, user should be redirected to / (I tried both absolute and relative paths)

return {
  headers: { Location: "/" },
  statusCode: 301,
};

But this Location header is added to the response:

Location: /?token=1&secret=2

As I understand, that should not happen.

Hi @zygimantas,

To avoid query parameters from being passed on to the redirect, you’d have to do something like this:

exports.handler = async () => {
  return {
    statusCode: 200,
    headers: {
      'content-Type': 'text/html; charset=utf-8',
      'cache-control': 'public, max-age=0, must-revalidate'
    },
    body: '<html><head><meta http-equiv="refresh" content="0;https://www.netlify.com/"/></head></html>'
  }
}

You can add any URL in the meta tag.

Here’s a repo: https://github.com/Hrishikesh-K/FunctionTest and a website: https://gallant-brattain-f39828.netlify.app.