WEBQ3 Gaming hosts free browser games, including our own arena fighter Power Surge: Planet Breakers and builds from independent creators. Every game runs in the page with no download and no account. That raises a practical question for any site that runs game code it didn't fully write: how do you let a build run at full speed without giving it access to the rest of the site?
Our answer is two Content-Security-Policy headers, one on the game page and one on the separate origin that serves the build.
The page and the build live on different origins
The game page is served from webq3.games. The build itself is served from a separate host, webq3-games.netlify.app, and is loaded into the page in an iframe. Because the build sits on its own origin, the browser's same-origin policy already keeps it away from cookies, storage and scripts on the main site.
Header one: the game page
The page's policy starts from default-src 'self' and only opens what it needs.…