0xDocs 0x.limo

Docs / REST API

CSP reports and policy

The Content-Security-Policy and Permissions-Policy each hosted site version is served with — declaring outside origins and permissions, enforce vs report-only, previewing, and reading violation reports.

Every hosted page on <site>-play.0x.limo is served with a Content-Security-Policy and a Permissions-Policy built for that exact site version. By default a game can load only from its own origin and from the 0x platform. Anything else it needs from outside, it declares when it publishes. The front never takes a policy from the client: the backend answers it per version.

#Declare what your game needs

Send csp with the version, from 0x.config.json with 0x publish, or in POST /v1/hosting/sites/{site}/versions:

json
{
  "csp": {
    "connect": ["wss://rt.example.com", "https://api.example.com"],
    "img": ["https://*.cdn.example.com"],
    "media": [], "font": [], "script": [], "frame": [],
    "permissions": ["microphone"],
    "eval": false,
    "inline_styles": false
  }
}
KeyExtendsValues
connectconnect-srchttps:// or wss:// origins
img / media / font / script / frameimg-src / media-src / font-src / script-src / frame-srchttps:// origins
permissionsPermissions-Policyany of camera, microphone, geolocation, usb, serial, hid, payment
evalscript-src 'unsafe-eval'true to allow eval / new Function
inline_stylesstyle-src 'unsafe-inline'true to allow <style> elements made at runtime

The rules for origins:

  • An origin is https://host[:port] (or wss:// for connect) with no path, query or user.
  • The host is a name with a domain (example.com), not an IP address.
  • One wildcard is allowed, as the whole first label: https://*.cdn.example.com.
  • At most 20 origins per kind and 64 in all; the whole declaration at most 8 KiB.

A bad declaration refuses the version with 422 upload refused and the problems listed, for example csp.img: "http://example.com": https:// origins only.

0x reviewers may reject a declared origin. The policy route shows the declaration as declared and as in effect (declared and effective_declared).

#What every version gets

Always allowed, without declaring anything:

  • scripts, styles, images, media, fonts, workers and frames from the site's own origin;
  • WebAssembly ('wasm-unsafe-eval'); data: and blob: images, media and fonts; blob: workers;
  • the 0x platform: https://api.0x.limo, https://play.0x.limo and their wss:// origins;
  • Cloudflare's page analytics;
  • inline <script> and <style> that shipped with the game. At finalize the backend hashes every inline script and style in the version's HTML files and allows exactly those hashes, without 'unsafe-inline';
  • style="..." attributes, plus the fullscreen, gamepad and autoplay permissions.

Always refused: plugins (object-src 'none') and <base> (base-uri 'none'). Forms may submit only to the site itself.

#Enforce and report-only

ModeHeaders
enforceContent-Security-Policy (enforced), a stricter copy as Content-Security-Policy-Report-Only (style attributes by hash only; only the 0x store and X as frame ancestors), and Permissions-Policy turning off every permission not declared
report-onlythe same policy as Content-Security-Policy-Report-Only only; no Permissions-Policy. Its reports are exactly what enforcing would break
  • Versions published since the enforced policy shipped are enforce. Older versions stay report-only.
  • 0x can switch a whole site (or all sites) to another mode. The answer gives the mode and mode_source (version, site or global).
  • A version with more than 64 inline script and style hashes stays report-only. Move inline code into files to get it enforced.
  • If the backend can't answer, the page is served with the report-only baseline and keeps working.

#Preview enforcement

Add ?x1-csp=enforce to a page URL to load that page with the version's policy enforced, whatever its mode. Do this before you rely on a version being enforced.

text
https://mygame-play.0x.limo/sites/mygame/4/?x1-csp=enforce

#Read the policy

RouteAuthReturns
GET /v1/hosting/sites/{site}/policytoken, your sitethe last 20 versions, each with mode, mode_source, declared, effective_declared, review, the inline-hash counts, warnings and the exact headers
GET /v1/hosting/policy/{site}/{n}publicthat version's headers as the front applies them: X-X1-Csp, X-X1-Csp-Ro, X-X1-Pp and X-X1-Csp-Mode (empty body)
bashtested
curl -s -D - -o /dev/null https://api.0x.limo/v1/hosting/policy/planetsmithx/1
text
x-x1-csp-mode: enforce
x-x1-csp: default-src 'self'; script-src 'self' 'wasm-unsafe-eval' ...
x-x1-pp: camera=(), microphone=(), geolocation=(), usb=(), serial=(), hid=(), payment=(), fullscreen=(self), gamepad=(self), autoplay=(self)

0x publish prints the version's policy after finalize, and the finalize answer carries it as csp (Hosting).

#Violation reports

Browsers post what the policy blocked (or would block) to /x1/csp on the site's own origin. The Reporting-Endpoints header and report-uri point there. Both report formats are accepted: application/csp-report and the Reporting API's application/reports+json. Reports are anonymous. The reporter's address is used only for rate limiting (1/s, burst 120) and isn't stored.

Reports are added up per site, version, directive, blocked origin and source file. URLs lose their query and fragment, and blocked URLs keep only their origin. Read your rows:

RouteReturns
GET /v1/hosting/csp-reports?version=&days=30rows across all your sites
GET /v1/hosting/sites/{site}/csp-reports?version=&days=30rows of one site
bashtested
curl -s "https://api.0x.limo/v1/hosting/csp-reports?days=7" -H "Authorization: Bearer $ZEROX_TOKEN"
json
{"items": [{"site": "mygame", "version": 4, "directive": "connect-src", "blocked": "https://api.example.com",
            "source_file": "https://mygame-play.0x.limo/sites/mygame/4/game.js", "line": 120, "col": 9,
            "disposition": "enforce", "count": 37, "first_seen": 1792250000, "last_seen": 1792259000}],
 "totals": [{"site": "mygame", "version": 4, "reports": 37, "rows": 1, "first_seen": 1792250000, "last_seen": 1792259000}],
 "days": 7, "policy": "report-only"}

A row with blocked: "https://api.example.com" under connect-src means: declare that origin in csp.connect and publish again. Each version keeps at most 300 distinct rows. Rows not seen for 90 days are deleted. The /dev/submit page shows the same rows.

Note

The top-level "policy": "report-only" in this answer is a fixed label from the report-only phase. Read each row's disposition (enforce or report) and the version's mode from the policy route.