[GH-ISSUE #3122] [Issue]: Game audio blocked by CSP — media-src is missing data: (data:audio/wav clip rejected) #1671

Closed
opened 2026-10-21 05:41:34 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @kolacheee on GitHub (Jun 30, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3122

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

In Game mode, the browser blocks a small data:audio/wav clip the app tries to play, and logs a Content-Security-Policy error:

Loading media from 'data:audio/wav;base64,UklGR…' violates the following Content Security Policy directive: "media-src 'self' blob: https:". The action has been blocked.

The app's CSP allows data: URIs for images and fonts, but the media-src directive was never given data: — so any data: audio/video is blocked. The specific clip here is the silent "unlock audio" primer the game audio manager plays on first interaction to let subsequent SFX/music autoplay; with it blocked, that priming fails and the console fills with the CSP violation.

How to reproduce (try it yourself)

  1. Open a Game-mode chat with game audio (SFX/music) in use.
  2. Interact so the audio system primes itself (first user gesture).
  3. Open the browser console.

You'll see: Loading media from 'data:audio/wav;base64,…' violates … "media-src 'self' blob: https:". The action has been blocked.
Expected: the data: audio clip plays (or is at least allowed by the CSP), with no violation, like data: images already are.

Where it is

  • The CSP: packages/server/src/middleware/security-headers.ts:32 — "media-src 'self' blob: https:". It's missing data:. Note the sibling directives that do allow it: img-src 'self' data: blob: https: (line 31) and font-src 'self' data: (line 33).
  • The blocked source: packages/client/src/lib/game-audio.ts:13 defines SILENT_AUDIO_DATA_URI as exactly this data:audio/wav;base64,UklGRkQD… clip, and primeMediaElement() (lines 217-220) plays it via new Audio(SILENT_AUDIO_DATA_URI) (muted, volume 0) to unlock autoplay. That new Audio(...) is what trips media-src.

What's happening

data: was added to img-src and font-src but not media-src, so the game audio manager's silent-WAV primer (and any other data: audio the app might play) is blocked by CSP. data: media is self-contained (no network request), so allowing it carries no real risk — it's just an omission relative to the image/font directives.

Suggested fix

Add data: to the media-src directive in security-headers.ts:32:

"media-src 'self' data: blob: https:",

(That matches img-src/font-src, which already allow data:.) Alternatively, convert the silent primer to a blob: URL instead of a data: URI — blob: is already in media-src — but the CSP one-liner is the minimal, consistent fix.


AI-investigated against the current tree (v2.0.9); the CSP directive and the SILENT_AUDIO_DATA_URI / primeMediaElement source read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 30, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3122 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** In Game mode, the browser blocks a small `data:audio/wav` clip the app tries to play, and logs a Content-Security-Policy error: > Loading media from 'data:audio/wav;base64,UklGR…' violates the following Content Security Policy directive: "media-src 'self' blob: https:". The action has been blocked. The app's CSP allows `data:` URIs for **images** and **fonts**, but the `media-src` directive was never given `data:` — so any `data:` audio/video is blocked. The specific clip here is the silent "unlock audio" primer the game audio manager plays on first interaction to let subsequent SFX/music autoplay; with it blocked, that priming fails and the console fills with the CSP violation. **How to reproduce (try it yourself)** 1. Open a Game-mode chat with game audio (SFX/music) in use. 2. Interact so the audio system primes itself (first user gesture). 3. Open the browser console. **You'll see:** `Loading media from 'data:audio/wav;base64,…' violates … "media-src 'self' blob: https:". The action has been blocked.` **Expected:** the `data:` audio clip plays (or is at least allowed by the CSP), with no violation, like `data:` images already are. **Where it is** - The CSP: `packages/server/src/middleware/security-headers.ts:32` — `"media-src 'self' blob: https:"`. It's missing `data:`. Note the sibling directives that **do** allow it: `img-src 'self' data: blob: https:` (line 31) and `font-src 'self' data:` (line 33). - The blocked source: `packages/client/src/lib/game-audio.ts:13` defines `SILENT_AUDIO_DATA_URI` as exactly this `data:audio/wav;base64,UklGRkQD…` clip, and `primeMediaElement()` (lines 217-220) plays it via `new Audio(SILENT_AUDIO_DATA_URI)` (muted, volume 0) to unlock autoplay. That `new Audio(...)` is what trips `media-src`. **What's happening** `data:` was added to `img-src` and `font-src` but not `media-src`, so the game audio manager's silent-WAV primer (and any other `data:` audio the app might play) is blocked by CSP. `data:` media is self-contained (no network request), so allowing it carries no real risk — it's just an omission relative to the image/font directives. **Suggested fix** Add `data:` to the `media-src` directive in `security-headers.ts:32`: ``` "media-src 'self' data: blob: https:", ``` (That matches `img-src`/`font-src`, which already allow `data:`.) Alternatively, convert the silent primer to a `blob:` URL instead of a `data:` URI — `blob:` is already in `media-src` — but the CSP one-liner is the minimal, consistent fix. --- *AI-investigated against the current tree (v2.0.9); the CSP directive and the `SILENT_AUDIO_DATA_URI` / `primeMediaElement` source read and confirmed. Please verify before fixing.*
bsakaguchi 2026-10-21 05:41:34 +07:00
  • closed this issue
  • added the
    in-pr
    label
Author
Owner

@SpicyMarinara commented on GitHub (Jul 2, 2026):

Codex is taking this in branch codex/issue-sweep-3119-3135 for a staging-targeted fix sweep.

<!-- gh-comment-id:4864509736 --> @SpicyMarinara commented on GitHub (Jul 2, 2026): Codex is taking this in branch codex/issue-sweep-3119-3135 for a staging-targeted fix sweep.
Author
Owner

@SpicyMarinara commented on GitHub (Jul 2, 2026):

Fix is ready in PR #3138 with CI passing. This issue will close automatically when the PR merges into staging.

<!-- gh-comment-id:4864746373 --> @SpicyMarinara commented on GitHub (Jul 2, 2026): Fix is ready in PR #3138 with CI passing. This issue will close automatically when the PR merges into staging.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1671
No description provided.