We have an S3 websites to that sits behind cloudflare and we utilize workers in order to inject security response headers for our content security policies, however we have noticed some strange behaviour.
If we take a resource that exists in S3 (highlighted):
So all in all it only works if the resource does NOT exist in S3 and ONLY if it has a .html extension. Can anyone please assist as to why this is the case and what we are doing wrong?
Thanks for the swift response. Here is a sample of our cloudflare worker code below. What we are really interested in is the x-frame options more so than the content security policy. Could cloudflare be stripping away the x-frame options as well?
It looks like the case where the resource does exist is expected, from reading the code (specifically, the script only returns the new headers if (res.status === 404)).
As far as the case where the resource does not exist and does not end with .html, I’m not sure. Is that the full script content that you pasted? Also, what are the routes the script is deployed on? Something like example.com/*, I assume? Lastly, your screenshots suggest that you have a browser-side service worker installed. Could you share what that script does?
I’m not aware of Cloudflare stripping any of these headers. Adding many of these headers programmatically is, I think a classic use case of Workers.
I’ve only noticed few that are stripped, like “server” and some headers that CF apply automatically.
I’m thinking, maybe it’s removed because X-Frame-Options only accepts two values SAMEORIGIN and DENY. While he’s written same-origin, which would be wrong.