Netlify.toml support reading query string for headers too

Reading query string params in netlify.toml is supported for redirects.
Could you please support that for headers too?

Example usage:

  for = "/"
  query = {param = ":param"}
    Content-Security-Policy = "script-src 'self' https://:param;"
    #even better, have a templating syntax, eg Content-Security-Policy = "script-src 'self' {{#if request.queryStringParameters.param}}{{request.queryStringParameters.param}} {{/if}};"

I’m curious as to where/why you would use this. Can you provide more details on why you need/want such a feature?

Also, Edge Functions already support such kind of a thing.

Hi, it’s the same use case as this one How to set dynamic header for Content-Security-Policy: frame-ancestors - #15 by fool

I know functions can be used to solve it, but if reading query params is already supported for redirects, I think it would be simpler to solve this need only from .toml file.

If it was just about reading the value, I’m sure that would be easy. But the actual implementation of the feature would come with lots of code, debugging, tests, edge cases and other problems to debug and this is simply not a priority right now.

So, unless you’re ready to wait for this to be picked up (if at all that ever happens), Edge Functions would be a much better way to go.

Got it, thanks. Will use edge functions. Have a good day :slight_smile:

1 Like