Support custom Content Security Policy
Johnny Povolny
Expo hosting sets a default Content Security Policy of "frame-ancestors 'self'". This means you cannot load any expo web app in an iframe, which can sometimes be a valid/valuable use case.
Being able to control the level of strictness of the CSP is a standard feature of other hosting services (netlify, vercel, etc). Would it be possible to add this to the hosting config in eas.json or something like that?
Thanks!
Rune Philosof
My bad. I am deploy a static web app. It cannot support
nonce
.And
staticwebapp.config.json
is specific to the hosting provider I am using.But for other non-static web app uses, being able to set a
nonce
is essential.Rune Philosof
You are able to set a custom CSP in
staticwebapp.config.json
"globalHeaders": {
"Content-Security-Policy": "default-src 'self'; script-src 'self' 'unsafe-inline' ...
The headline of this feature request should be
> Support setting
nonce
attribute on script tagsHere is a list of problematic code
- https://github.com/expo/expo/blob/17e0a7d4f623d359dfbc6485d041a3a073cd738c/packages/%40expo/cli/src/start/server/metro/serializeHtml.ts#L105
- https://github.com/expo/expo/blob/17e0a7d4f623d359dfbc6485d041a3a073cd738c/packages/%40expo/router-server/src/utils/html.ts#L54
- https://github.com/expo/expo/blob/17e0a7d4f623d359dfbc6485d041a3a073cd738c/packages/%40expo/router-server/src/utils/html.ts#L75 (this one is easy to handle with hash)
- https://github.com/expo/expo/blob/17e0a7d4f623d359dfbc6485d041a3a073cd738c/packages/%40expo/router-server/src/utils/html.ts#L97
- https://github.com/search?q=repo%3Aexpo%2Fexpo%20%2F%3Cscript%2F&type=code
Rémy Oudemans
This would be handy for us in some form too!
We're looking to self-host an expo web app.
Adding a CSP when we control the server is easy enough because we can set it in the response headers, but for the CSP to be strict at all we need to be able to use 'strict-dynamic' with a nonce in the script-src.
We would need expo to support a way for a nonce to be added to all the script tags in the html at runtime.
As an example of how this can be done, Next.js have handled this well https://nextjs.org/docs/app/guides/content-security-policy.
Without that we'll have to resort to setting 'unsafe-inline' in the script-src directive to load a 3rd-party script, which is pretty bad in terms of security.