Skip to main content
短.be

CSP

Content Security Policy - an HTTP header that controls which resources a browser is allowed to load for a given page.

Aug 24, 2025 · About 1 min read

Security

Content Security Policy (CSP) is a security mechanism implemented through an HTTP response header that allows website owners to control which resources (scripts, styles, images, fonts, etc.) the browser is permitted to load. CSP is a powerful defense against cross-site scripting (XSS) and data injection attacks.

A CSP header contains directives that specify allowed sources for different resource types. For example, script-src defines where JavaScript can be loaded from, style-src controls CSS sources, and img-src governs image sources. The default-src directive provides a fallback for any resource type not explicitly configured. Web application security books on Amazon provide implementation guides.

For URL shortening services, CSP helps protect splash pages, preview pages, and the management dashboard from XSS attacks. A well-configured CSP prevents attackers from injecting malicious scripts even if they find an input validation vulnerability.

Implementing CSP can be challenging because overly restrictive policies may break legitimate functionality. The recommended approach is to start with a report-only mode (Content-Security-Policy-Report-Only) that logs violations without blocking resources, then gradually tighten the policy based on the reports. Security engineering books on Amazon discuss deployment strategies.

Share on XHatena

Was this article helpful?

Related Terms

Related Articles

FAQ

What types of attacks does CSP prevent?
CSP prevents XSS (Cross-Site Scripting), data injection, and clickjacking attacks by restricting resource loading to only permitted sources.
How do I configure CSP?
Set it via the Content-Security-Policy HTTP response header or an HTML <meta> tag. It's recommended to test with Content-Security-Policy-Report-Only first before applying in production.

Ready to create a short URL?

Shorten a URL for Free