Join our Newsletter — 33% off our NHI Course

Content Security Policy Directive

A Content Security Policy directive is a rule in the policy that tells the browser what kind of content may load and from where. Directives such as script-src or img-src narrow execution and retrieval paths, helping teams define a trusted set of sources and reduce exposure to injected content.

How content security policy directives work

Directives are the operational core of a Content Security Policy. They let a browser enforce source restrictions by content type, so a site can allow scripts, images, styles, frames, fonts, or connections only from approved origins and schemes.

That separation matters because not all content carries the same execution risk. A tight script-src rule can prevent many injection paths, while a narrower img-src or connect-src policy limits data exfiltration and unwanted retrieval paths without blocking every asset on the page.

Well-designed directives also make policy intent easier to reason about. Instead of one broad allowlist, teams can express trust boundaries per resource category, which is especially useful when a page mixes static content, third-party widgets, analytics, and API calls.

Common directive types and what they control

Some directives govern execution, while others govern retrieval or embedding. script-src is the most sensitive because it controls where executable JavaScript may come from, and browsers treat it as a key boundary for reducing injected script risk.

Other directives shape adjacent exposure. style-src limits styling sources, img-src constrains image fetches, font-src restricts font delivery, and frame-src controls what can be embedded. connect-src is important for API and telemetry traffic because it governs fetch, XHR, WebSocket, and similar outbound connections.

Because these rules are independent, a strong policy usually mixes several directives rather than relying on a single catch-all rule. That lets defenders reduce attack surface without over-allowing unrelated content classes.

Why directives strengthen browser-side security

Content Security Policy directives are most valuable when the application must tolerate some degree of untrusted input, third-party code, or rich client-side behaviour. They help the browser enforce a last line of defence when server-side validation or framework protections are bypassed or incomplete.

They also support clearer trust decisions during development and change control. If a new CDN, widget, or analytics endpoint is added, the directive set becomes the place where that dependency is either deliberately authorised or blocked.

For teams comparing browser controls, CSP directives work best as a policy layer, not as a substitute for secure coding, output encoding, or dependency hygiene. They reduce blast radius, but they do not make unsafe markup or unsafe script handling inherently safe.

Directive design trade-offs and implementation limits

Directive design is often a balance between security and breakage. Overly broad sources weaken protection, but overly strict rules can disrupt legitimate scripts, image CDNs, reporting endpoints, or embedded services.

The most common weakness is policy drift. Teams add exceptions over time, and a directive that once constrained a small trusted set can gradually expand until it no longer meaningfully limits injection or outbound communication.

A separate challenge is inconsistent support for newer policy features across browsers and application stacks. That means teams need to validate how a directive behaves in the real client population, not just in a staging browser or a framework demo.

Risk and Threat Considerations

Directives matter because the browser will only enforce the boundaries they actually express. A loose source list, missing directive, or broad fallback can leave injected content, malicious third-party code, or unexpected outbound requests with far more room to operate than intended.

Failure mechanism: Attackers benefit when a policy allows wildcard sources, legacy allowances, or overbroad trust in a CDN, widget, or script host, because that weakens the browser’s ability to stop execution or data flow abuse.

Impact: The result can be script execution, content injection persistence, token theft, data exfiltration, or increased exposure from compromised dependencies and supply-chain style abuse.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Non-Human Identity Top 10 address the attack and risk surface, while CIS Controls v8 and NIST CSF 2.0 set the governance and control requirements practitioners need to meet.

Framework Control / Reference Relevance
CIS Controls v8 CIS 16 — Application Software Security CSP directives constrain browser-executed content and reduce injection exposure.
CIS 8 — Audit Log Management CSP reporting directives generate browser violation telemetry for detection and tuning.
Recommendation — Deploy CSP to restrict executable and remote content sources for web applications. Collect and review CSP violation reports to detect unsafe content loading attempts.
NIST CSF 2.0 PR.DS — Data Security CSP directives help limit data exposure paths through controlled fetch and embed sources.
PR.PT — Protective Technology CSP is a browser-enforced protective control that narrows content execution and retrieval.
Recommendation — Use CSP directives to reduce unauthorized content retrieval and data leakage paths. Apply CSP as a protective browser control to constrain untrusted content.
OWASP Non-Human Identity Top 10 NHI-07 — Secret Sprawl and Exposure Directive gaps can amplify script injection paths that expose embedded secrets.
NHI-09 — Third-Party and Supply Chain Risk Broad directives can trust compromised third-party sources and CDN-delivered content.
Recommendation — Limit exposed client-side paths that could reveal or misuse secrets. Constrain third-party content sources to reduce supply-chain exposure.

Practitioner Guidance

What to watch for: Review directives as a living control, not a one-time header. The most useful signal is policy growth, especially when exceptions accumulate faster than the application’s actual dependency set changes.

When teams need a practical baseline for browser-side restriction design, OWASP’s Cheat Sheet Series is useful for framing how CSP fits alongside output encoding and other application protections. For a browser-control perspective aligned to modern security governance, NIST Cybersecurity Framework 2.0 helps place policy enforcement inside broader protect and detect outcomes.