[PR #11082] fix(opencode): allow media-src data: URL for small audio files #13652

Closed
opened 2026-02-16 18:18:29 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11082

State: closed
Merged: Yes


Small audio files (<4KB) are inlined by Vite as base64 data URLs, but Content-Security-Policy didn't allow data: for media resources. This caused sound preview to fail for several sounds.

Added 'media-src "self" data:' to CSP to allow both regular file URLs and data URLs for audio playback.

Fixes #11081

What does this PR do?

18 out of 48 sound options don't play on hover in the sound settings page. Small audio files (<4KB) are inlined by Vite as base64 data URLs, but the Content-Security-Policy blocks data: URLs for media resources.

Root Cause

  • Vite automatically inlines assets <4KB as data URLs for performance
  • CSP didn't have a media-src directive, falling back to default-src 'self' which blocks data: URLs
  • Large audio files (>4KB) were not inlined, so they loaded normally

Solution

Added media-src 'self' data: to Content-Security-Policy to allow both:

  • Regular file URLs for large audio files
  • Base64 data URLs for small audio files

Verification

  • Tested all 48 audio options in Firefox and Chrome
  • All sounds now play correctly on hover
  • Confirmed no CSP errors in browser console

How did you verify your code works?

  1. Start OpenCode web app

  2. Navigate to Settings → Sound effects

  3. Open any sound dropdown (e.g., Agent sound)

  4. Hover over each sound option

    • Alert 01-10: All should play
    • Bip-bop 01-10: All should play
    • Staplebops 01-07: All should play
    • Nope 01-12: All should play
    • Yup 01-06: All should play
  5. Check browser console for CSP errors

    • Should see no CSP violations
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11082 **State:** closed **Merged:** Yes --- Small audio files (<4KB) are inlined by Vite as base64 data URLs, but Content-Security-Policy didn't allow data: for media resources. This caused sound preview to fail for several sounds. Added 'media-src "self" data:' to CSP to allow both regular file URLs and data URLs for audio playback. Fixes #11081 ### What does this PR do? 18 out of 48 sound options don't play on hover in the sound settings page. Small audio files (<4KB) are inlined by Vite as base64 data URLs, but the Content-Security-Policy blocks `data:` URLs for media resources. #### Root Cause - Vite automatically inlines assets <4KB as data URLs for performance - CSP didn't have a `media-src` directive, falling back to `default-src 'self'` which blocks `data:` URLs - Large audio files (>4KB) were not inlined, so they loaded normally #### Solution Added `media-src 'self' data:` to Content-Security-Policy to allow both: - Regular file URLs for large audio files - Base64 data URLs for small audio files #### Verification - Tested all 48 audio options in Firefox and Chrome - All sounds now play correctly on hover - Confirmed no CSP errors in browser console ### How did you verify your code works? 1. Start OpenCode web app 2. Navigate to Settings → Sound effects 3. Open any sound dropdown (e.g., Agent sound) 4. Hover over each sound option - Alert 01-10: All should play - Bip-bop 01-10: All should play - Staplebops 01-07: All should play - Nope 01-12: All should play - Yup 01-06: All should play 5. Check browser console for CSP errors - Should see no CSP violations ```
yindo added the pull-request label 2026-02-16 18:18:29 -05:00
yindo closed this issue 2026-02-16 18:18:29 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13652