Menu

How we sandbox HTML5 game builds on a browser game platform with two CSP headers
📰

How we sandbox HTML5 game builds on a browser game platform with two CSP headers

DEV Community: html·WEBQ3 Gaming·7 days ago
#SHFhClvM
#devto2#devto#dev#games#build
Long article (513 words) — no AI summary yet.
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.