Safeguard
Security Guides•

Which small CSP directives matter: base-uri, object-src, form-action?

Three short CSP directives close gaps that script-src leaves open: base-uri, object-src and form-action. See what each blocks and which skip default-src.

Safeguard Security Team
4 min read

Add base-uri 'none', object-src 'none' and form-action 'self' to a CSP unless you have a reason not to. They block injected base tags, legacy plugin embeds and form posts to attacker hosts. Two of them do not fall back to default-src, so leaving them out means no restriction at all.

Why a script-src alone is not enough

A policy that only sets script-src controls where scripts load from. An attacker who can inject markup but not run script still has other tools: redirect relative URLs, embed an object, or submit a form somewhere else. These three directives address those.

MDN's example of a nonce based strict CSP includes object-src 'none' and base-uri 'none' for this reason.

What each directive does

DirectiveControlsFalls back to default-src?
base-uriURLs allowed in the document's base elementNo. Not setting it allows any URL.
object-srcSources for object and embed elementsYes
form-actionURLs that forms may submit toNo. Not setting it allows anything.

base-uri

The base element changes how relative URLs resolve. If an attacker can inject one, relative script paths such as /app.js can be pointed at the attacker's host. MDN says that without this directive any base URI is allowed, and it is not covered by default-src. Set it to 'none' if you never use a base element, or 'self' if you do.

object-src

This covers object and embed elements. MDN notes those are legacy HTML elements that are no longer receiving new standardised security features, so it recommends restricting the directive, explicitly setting object-src 'none' when possible.

form-action

This limits where forms can submit. If injected markup adds a form that posts credentials to another host, a strict form-action stops the submission. MDN warns that whether the directive should block redirects after a submission is debated, and browser implementations were inconsistent, with Chrome blocking and Firefox not blocking in the versions it cites. Do not treat it as a complete fix for open redirects.

A starting policy

Content-Security-Policy: default-src 'self'; object-src 'none'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'

The frame-ancestors directive in that line controls who may embed your page, which is the clickjacking control. See frame-ancestors vs X-Frame-Options for details.

Steps to roll out

  1. Search your templates for base elements, object and embed tags, and every form action value.
  2. Add the directives in a Content-Security-Policy-Report-Only header first.
  3. Watch for legitimate form posts to payment or login hosts, and add those origins to form-action.
  4. Enforce, and keep reporting on.

Try it yourself

Open the web app scan and see how missing header controls are listed as findings, with a fix attached.

Click through it at your own pace, or open it full screen.

Quick check

If I set default-src, am I covered for base-uri?

No. MDN says base-uri does not fall back to default-src. Set it directly.

Does form-action stop CSRF?

No. It limits where forms on your page can submit. CSRF defences such as SameSite cookies and tokens address forged requests from other sites.

Can I set these in a meta tag?

The MDN snippets for these directives include meta examples, but a meta tag does not support every CSP feature. Prefer response headers.

Safeguard's dependency scanning and policy gates cover the packages in your build. Run a free scan at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.