Guide: Setting Up a Content Security Policy (CSP) for Immich in NGINX Proxy Manager (NPM) #13043
Replies: 2 comments 4 replies
-
Note: if you are setting immich up for the first time, don't forget to put the following headers in there too (from the immich documentation):
|
Beta Was this translation helpful? Give feedback.
-
Getting the following error in the console with mentioned CSP header: Content-Security-Policy: The page’s settings blocked an inline script (script-src-elem) from being executed because it violates the following directive: “script-src 'self' https://immich.domain.com https://static.immich.cloud https://tiles.immich.cloud 'sha256-h5wSYKWbmHcoYTdkHNNguMswVNCphpvwW+uxooXhF/Y=' 'sha256-MK9u9tTzYnMIn9JSYcvLuwDDlo6Oevw1wdQBWB8TGys='” |
Beta Was this translation helpful? Give feedback.
-
Introduction
Setting up a Content Security Policy (CSP) is crucial for securing your Immich instance. CSP protects against various types of attacks such as Cross-Site Scripting (XSS) by controlling which resources can be loaded or executed by your site. However, Immich requires some inline scripts to function properly, and blocking these might prevent the app from loading.
This guide will walk you through configuring a secure CSP while ensuring that Immich loads without errors.
Note: This assumes you already have your site setup and accessible via NPM with SSL certs etc functioning.
Step-by-Step Guide
1. Access NGINX Proxy Manager
https://immich.yourdomain.com
).2. Add Custom NGINX Configuration
3. Define the Security Headers
Copy and paste the following configuration to include all the necessary security headers for Immich (replacing "immich.yourdomain.com" with your immich server domain:
Explanation of Headers:
'self'
) and inline scripts by their SHA-256 hashes.4. Identify Additional Script Hashes (If Needed)
After applying the CSP, load your Immich instance.
Open your browser’s Developer Tools (
F12
or right-click > Inspect) and go to the Console tab.If there are CSP violations, they will show up in the console with a message like this:
Copy the hash provided (e.g.,
'sha256-<hash>'
).Add the new hash to the
script-src
directive in your CSP. For example:Repeat this process for all required hashes.
5. Test Your Site
6. Save Your Configuration
Troubleshooting
Blocked Inline Scripts: If you encounter blocked inline scripts, the error messages in the Console will provide the SHA-256 hash you need to add to the
script-src
directive.Blocked External Resources: If external resources like fonts, images, or APIs are blocked, adjust your CSP to explicitly allow those domains. For example, to allow loading fonts from a CDN:
Conclusion
By configuring these security headers, you protect your Immich instance from various web vulnerabilities such as XSS, clickjacking, and more. Keep refining your CSP by reviewing the Console for violations and adding new hashes as necessary.
Remember to test your CSP regularly and maintain a balance between security and functionality.
This should now give you a working immich server, with an A+ report card on https://securityheaders.com/
Beta Was this translation helpful? Give feedback.
All reactions