-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Safari doesn't like multiple CSP headers #2251
Conversation
I don't think this works. I just tested it on my local version of ordinals . com and I am still getting CSP errors. I posted what I thought was a fix a few days ago, but it ended up not working either. I'm still working on trying to get it working on Safari. Safari CSP implementation is a bit tricky to figure out. |
Hey that's weird. I'm sure I had it working but when I run it again now it's giving errors again. Let's see if I missed something |
Just letting @veryordinally and @raph know that I have verified that this PR works. The test inscriptions originally mentioned in #2236 all work with this latest PR. I tested on Safari and I tested on iPhone. |
Another consideration for this PR regarding using sandbox + allow-scripts + allow-same-origin. "When the embedded document has the same origin as the embedding page, it is strongly discouraged to use both allow-scripts and allow-same-origin, as that lets the embedded document remove the sandbox attribute — making it no more secure than not using the sandbox attribute at all." - from https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe) |
Okay, when I remove allow-scripts and only set allow-same-origin it won't work because then script execution is not allowed. But it does show why Safari is refusing to execute the scripts because it treats the urls in the iframe as coming from a different origin. |
I have read a bit more about sandbox + allow-same-origin flag and I think it's probably not the way you want to go because it is not secure enough. I also saw some posts from other people related to Safari ignoring the allow-scripts flag on sandboxed iframes and some of them are a few years old. So even if it is a Safari bug, I don't think it will be fixed soon. :-( |
I've reverted last change and removed 'allow-same-origin' because it is a security risk and allows the code from within the iframe to access cookies, localStorage, etc. |
@bodily11 So only the fix moving all CSP values into a single header should do the job |
Hmmm not sure this is right. I pulled your CSP change into my instance of Ord and deployed it to a production server, but it still wasn't working. It needed the iframe fix before it started working for me, and this was on the latest version of Ord deployed to a production server. |
Bummer, maybe there are still some missing values in the CSP header, like :/inscription/ and/or :/preview/ because the page being loaded is /inscription/... and this page creates an iframe which loads /preview/... |
Yeah, if you allow scripts and allow same origin you are essentially removing sandbox (because it can be removed via script). So in that case, as long as you are disabling access to those APIs yourself on your frontend (maybe Xverse is doing this) then you should be ok. But if you aren't disabling access to those APIs, then you are essentially allowing Ordinals to access local storage and cookies. |
Maybe it should be configurable with an argument |
Why does the ord server serve paths that aren't a part of the public APIs? It seems best to use a separate host name for pages that aren't exposed via the API. With that, this CSP for whitelisting paths will no longer be needed:
|
I just tested this and still not working on Safari. I'm using a M1 MacBook Pro running Safari Version 16.5.1 (18615.2.9.11.7). The consolidation of the CSP headers into one does work (on Chrome and Firefox) so definitely an improvement! A note on contributing. I wrote a small guide to how our tests work here. When you make a change run the |
I'm not quite sure what you mean by this. All of those endpoints are served by the server and are public. |
The reason it's not working is because I removed the last change which added 'allow-same-origin' to the sandbox attribute on the iframe, because it's considered insecure. I thought it would also work without that change because on my side all the other pages with iframes gave the same error but they don't give an error in production. So unfortunately the only solution I know can think of is to add the "allow-same-origin" again. I think it's a bug in how Safari handles iframes with sandbox 'allow-scripts', but that's not something we can change. :-( Thanks for the guide on how to test work, I didn't know this. |
@raphjaph I believe the whitelisting of paths via CSP header is needed because ordinals.com serve paths that shouldn't be available to inscriptions, such as https://ordinals.com/sat/a, https://ordinals.com/block/00000000000000000000ad2683dabaee3b02e12f6a14af9a8cd4ab9cd719d0c3 etc. If inscriptions are served from its own subdomain, where only paths exposed are the ones available through the official API (i.e /content/, /blockheight etc.), there's no need to whitelist any specific paths via a CSP header. Because that subdomain should only serve /content/ and other paths that should be available to all inscriptions. |
I'll reply back in another day or two, but the crux of the issue here is the following:
|
Merging CSP headers as is done in this PR does not work. When a single CSP header is used, requests to any of the sources are allowed, so, for example, |
Recursive Ordinals aren't working on Safari because Safari only uses the first CSP header from the response.
By moving all values to the insert en removing the append Recursive Ordinals will also work on Safari.
You can use this recursive ordinal to test
https://ordinals.com/inscription/370706072e6a03c3eb1349bf4531fe20e60d28063fac1f1c3a0774b094efb931i0