-
Notifications
You must be signed in to change notification settings - Fork 0
Fix CSP violations by removing Caddy CSP override and configuring app middleware #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Co-authored-by: tsmarvin <[email protected]>
Co-authored-by: tsmarvin <[email protected]>
|
This did not fix anything as far as I can tell @copilot this on the apple music page: and this message pretty much everywhere: |
Co-authored-by: tsmarvin <[email protected]>
... Found the issue! The Caddyfile was setting a hardcoded CSP header that overrode the application's dynamic CSP middleware. The browser was seeing Caddy's CSP ( Fixed in commit 39281c3:
The CSP violations should now be resolved. After deploying, you should see the nonce in the CSP header instead of 'unsafe-inline'. |
|
Sadly that didn’t change anything either @copilot |
The changes look correct in the code. Since you're still seeing To apply the fix:
To verify it's working after deployment:
Have you redeployed/restarted Caddy with the updated Caddyfile?
Found it! The docker-compose.yml was pulling a pre-built image from Docker Hub ( Fixed in commit 12d871f: To deploy the fix: docker-compose up -d --buildThis will rebuild the container with the updated CSP middleware code that:
|
…mage Co-authored-by: tsmarvin <[email protected]>
|
Please revert the last change - I updated my caddy configuration myself to remove the CSP and X-Origin settings, which did pass the CSP settings into the app, but now I'm getting the following error from the playlist page: and this error from the embeds: |
|
@copilot forgot to tag you - that last message is for you. |
…HTTPS frame-ancestors Co-authored-by: tsmarvin <[email protected]>
Fixed both issues in commit 382640b:
The CSP now uses:
After deploying these changes, both errors should be resolved. |
…inline' Co-authored-by: tsmarvin <[email protected]>
Co-authored-by: tsmarvin <[email protected]>
Co-authored-by: tsmarvin <[email protected]>
Co-authored-by: tsmarvin <[email protected]>
Fix Content Security Policy Settings
Problem: Apple Music playlist sync fails due to CSP violations blocking required external scripts and frame-ancestors restrictions.
Root Cause:
Changes Made:
script-srcto allow Apple MusicKit CDN and Cloudflare analyticsconnect-srcto allow Cloudflare Insights APIframe-ancestorsto usehttps: 'self'for embeds (allows HTTPS + same-origin)Implementation Details:
Application CSP (
src/Configuration/StartupExtensions.cs):script-src: Whitelists Apple MusicKit and Cloudflare CDNs + nonce supportstyle-src: Uses nonce-based security (no 'unsafe-inline', no exposed nonces)frame-ancestors: Useshttps: 'self'to allow HTTPS framing AND same-origin for embeds/Apple Music pagesconnect-src: Whitelists music provider APIs and Cloudflare InsightsSecure Style Implementation:
playlist-manager.css- Moved all playlist styles from JavaScript to a proper CSS file_Layout.cshtml- Added CSS file reference (line 15)style-src 'self' 'nonce-{nonce}'Files Modified:
src/Configuration/StartupExtensions.cs- CSP middleware configurationCaddyfile- Removed hardcoded CSP and X-Frame-Optionssrc/Web/Views/Shared/_Layout.cshtml- Added CSS referencesrc/Web/wwwroot/public/playlist-manager.css- NEW: Playlist stylessrc/Web/wwwroot/public/playlist-manager.js- Removed dynamic style creationSecurity Improvements:
'unsafe-inline'directives - eliminates XSS attack vectorframe-ancestors https: 'self'allows HTTPS framing + same-origin while blocking HTTPFrame-Ancestors Fix:
Changed from
https:tohttps: 'self'to properly support:External HTTPS sites embedding the content (e.g., social media, other sites)
Same-origin framing (e.g., when dev.tunebridge.media frames its own embed endpoints)
Fixes Fix Content Security Policy Settings #142
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.