๐ก๏ธ CSP Active: Basic Content Security Policy is protecting this page!
โ
Same-origin scripts only | โ
Inline styles allowed | โ External scripts blocked | โ Inline scripts blocked
๐ Current CSP Configuration
Content-Security-Policy:
default-src 'self'; // Only same-origin resources by default
script-src 'self'; // Only same-origin scripts
style-src 'self' 'unsafe-inline'; // Same-origin + inline styles
img-src 'self' data: https:; // Same-origin + data URLs + HTTPS images
font-src 'self' https:; // Same-origin + HTTPS fonts
connect-src 'self'; // Same-origin connections only
๐ฏ What This Policy Does:
- โ
Allows: Scripts from same origin (/js/script.js)
- โ
Allows: Inline CSS styles (style="...")
- โ
Allows: HTTPS images from any domain
- โ Blocks: Inline JavaScript (<script>...</script>)
- โ Blocks: External scripts (https://evil.com/script.js)
- โ Blocks: eval() function execution
- โ Blocks: Inline event handlers (onclick="...")
โ
What CSP Still Allows
1. Same-Origin Scripts
Scripts loaded from the same domain work fine:
<!-- This works -->
<script src="/js/app.js"></script>
<script src="script.js"></script>
2. Inline CSS Styles
This blue text uses inline styles (allowed by our CSP)
<!-- This works -->
<p style="color: blue;">Styled text</p>
3. External Images (HTTPS)
<!-- This works -->
<img src="https://trusted-cdn.com/image.jpg">
4. Form Submissions to Same Origin
๐ CSP Violation Monitoring
CSP violations are logged in the browser console. Check DevTools to see blocked attempts!
CSP violation log will appear here...
๐ ๏ธ How to Implement Basic CSP
Method 1: HTTP Header (Recommended)
# Apache (.htaccess)
Header always set Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'"
# Nginx
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'";
# Express.js
app.use((req, res, next) => {
res.setHeader('Content-Security-Policy', "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'");
next();
});
Method 2: Meta Tag (Limited)
<meta http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'">
๐ฏ Gradual Implementation Strategy:
- Start with Report-Only mode to test without breaking
- Use basic policy like this example
- Monitor violations and adjust as needed
- Gradually tighten by removing 'unsafe-inline'
- Use nonces/hashes for maximum security