logoalt Hacker News

esttoday at 4:24 PM1 replyview on HN

I didn't quite get the CSP part. Why use and srcdoc and <meta http-equiv="Content-Security-Policy"> instead of a real server header? Static hosting?


Replies

simonwtoday at 4:29 PM

If you host iframe apps at a fixed URL like:

  /-/apps/iframe-content/timeline.html
You can protect it with CSP headers, but you can't also protect it with the sandbox="" attribute (should a user visit it directly)

If you want both sandbox= restrictions and CSP headers at the same time the only way I've found that works cross all major borders is the iframe plus srcdoc="" with injected CSP meta headers patterns.

Note that a lot of sandbox implementations serve their iframe content from a separate domain, to ensure cookies and localStorage and other same origin things are robustly protected.

I can't do that easily for Datasette because it's open source software that people can run on their own laptops, so I didn't want to block people on "now register a domain/subdomain and set this up in DNS".

show 2 replies