Content security policy and security headers in Strapi

Strapi's security middleware sets headers that control what browsers may load, embed and connect to. This page explains how to tune CSP for upload providers and preview, set HSTS and frame options, and verify the result after deployment.

On this page

Why Strapi security headers need tuning before go-live

Strapi's security middleware sets response headers, including a Content Security Policy, HSTS and frame options, and the defaults usually need changes for upload providers, preview and the admin panel. The defaults cannot know where your media files, preview pages and admin hostname live, so a self-hosted deployment that loads assets from other origins or serves the admin panel from its own host needs an explicit policy. A security team reviewing the admin panel and public front end before launch should treat the headers as a configured control to test, not as a finished setting.

Teams usually need this work in three situations: regulated deployments where the security review asks for named header values, separate admin and front-end hosts, and external media storage with its own domains. The review should confirm which origins each CSP directive allows and why, whether the admin panel and public API responses carry the intended headers, whether HSTS is sent only over HTTPS with a max-age that operations has agreed, and whether frame options match any legitimate need to embed Strapi preview in another site. Record the expected header values for each host so the post-deployment check has something to compare against.

The Community Edition is released under the MIT Expat license, so the middleware configuration sits in your project and can be read and adjusted there. Strapi 5 is the current major line, with v5.58.0 published on October 14, 2026, and Strapi 5 minor releases have shipped roughly weekly. Confirm the header behavior of the exact version you deploy against the Strapi GitHub releases page, and retest headers after each upgrade, because a minor release can change middleware defaults your policy depends on.

Which CSP directives each Strapi feature needs

When editors only use the admin panel on the Strapi host, the browser mostly loads scripts, styles, images and API calls from that same origin. The policy can stay close to self-only, and the main job is to avoid widening it for things the admin panel does not need. The admin panel still makes requests back to the Strapi server, so connect-src must allow that origin, and the panel renders uploaded media, so img-src needs to cover where that media is served.

  • script-src: Keep it to the admin origin. Inline script allowances should be avoided unless the installed version requires a specific hash or nonce, and that should be confirmed for your build.
  • connect-src: Allow the admin origin and any API hostname the panel calls directly. This is what lets the panel save content and fetch relations.
  • img-src: Allow self plus the media origin used for thumbnails and previews, which may differ from the admin host.
  • frame-ancestors: Set to 'none' or 'self' so no third-party site can embed the admin panel in a frame.
  • frame-src: Usually unnecessary here. Add nothing unless a plugin you have installed embeds a frame.

Confirm every origin against the Strapi version you have installed and the admin URL your proxy exposes, rather than copying values from an example.

Header options and when each fits

This table compares five browser-enforced headers that Strapi responses and the admin panel can carry, with the situations where each one fits and the failure it causes when set wrong. Read each row against your own front ends, upload provider and preview hostnames, because the right value depends on where content and the admin panel are actually served. Browser behavior differs across clients, so confirm each header against the browsers and embedded clients your users run before enforcing it.

HeaderWhat it controlsWhen to set itMain risk if misconfigured
Content-Security-PolicyWhich sources the browser may load scripts, styles, images, frames and connections fromWhen the admin panel or a served page loads assets from a CDN, an upload provider or a preview hostBlocked admin assets or media, leaving the panel partly broken without an obvious server error
Strict-Transport-SecurityWhether browsers must use HTTPS for the host and, if set, its subdomains for a periodOnce every hostname serving Strapi is confirmed to work over HTTPS end to endLockout of subdomains that are not yet on HTTPS, and hard-to-undo caching if the max-age is set high too early
X-Frame-Options or frame-ancestorsWhether other sites may embed Strapi pages in a frameWhen the admin panel or preview should never be embedded, or only by named sites such as your own preview originBreaking a preview or embedded editor view, or leaving the panel open to clickjacking if neither control is set
Referrer-PolicyHow much of the page URL the browser sends to other sites in the Referer headerWhen admin or preview URLs contain tokens, IDs or paths that should not reach third partiesLeaking sensitive path or query data to external services, or breaking analytics and referrer checks that depend on it
X-Content-Type-OptionsWhether browsers must honor the declared content type rather than guessing itFor any response that serves uploaded files or user-supplied content typesUploaded files served with a type that lets browsers run them as scripts or styles

Setting and testing headers in a Strapi project

This sequence turns a list of the origins Strapi must load from into a tested header policy, applied in report-only mode first so editors keep working before the policy is enforced. Each step ends with a check you can record, so the final enforced configuration is one your team has already exercised.

  1. Inventory every origin the admin panel needs

    Before changing any setting, list every origin the Strapi admin panel, the preview URL and the media upload provider load resources from or send requests to. Include scripts, styles, fonts, images, frames, form targets and API calls, and note which origin serves each one. The owner of the front end and the owner of the upload provider should both review the list. The step is done when the team has a written table of directive, origin and reason, and every entry has a named owner. Confirm the list against your own environment, since the provider and preview hosts vary by project.

  2. Set the security middleware in config

    Open the project's middleware configuration and set the security middleware options that match the inventory, keeping the directives in the project's config files rather than in a reverse proxy alone so they stay under version control. Add the upload provider and preview origins to the relevant directive lists, and set the HSTS and frame options to the values your policy requires. Commit the change on a branch and run the application locally. The step is done when the configuration builds and the server starts without validation errors.

  3. Start in report-only mode

    Where your Strapi version and deployment allow it, deliver the policy in report-only mode so browsers log violations without blocking anything. Point the reports at an endpoint your team can read, and confirm the policy is sent on the admin panel and API responses you expect. Test this on a staging instance that mirrors production hostnames. The step is done when the report endpoint receives reports from a page load and the team can read them. If report-only delivery cannot be configured for your setup, say so in the change record and rely on the browser console checks in the next step.

  4. Test the admin panel in the browser

    Sign in to the admin panel in a current browser and open the main sections, the content manager, the media library and the settings pages. Open the developer console and record every violation or blocked resource, then match each one to an entry in the inventory. Add any missing origin to the config, restart, and repeat until the console shows no unexpected blocks. The step is done when a full pass through the admin panel produces no blocked resources that are not explained by a documented exception.

  5. Test content editing, media upload and preview

    Use an editor account, not an administrator, to create and edit an entry, upload an image and a document, and open the preview for a draft and a published entry. Confirm that the upload completes, the file displays in the media library and the preview loads inside its frame with the expected scripts and styles. Repeat the test with the upload provider and preview origins in use by your real editors. The step is done when an editor can complete each action without an error in the console, and the test results are recorded with the browser version and date.

  6. Confirm the public API headers

    Request the content API and any public asset endpoints with a basic HTTP client and inspect the response headers. Check that HSTS, frame options and the content security policy are present with the values in the config, and that the public front end still renders its pages without blocked resources. Ask your front-end team to run their own console check. The step is done when the headers in the responses match the written policy and the front end loads cleanly.

  7. Enforce the policy and retest

    Switch the policy from report-only to enforcing mode once the report log has been clean through a full round of admin, editing, upload and preview testing. Deploy to staging first, then to production during a planned change window with the rollback steps documented. Repeat the editor test and the header check after deployment, and watch the reports for new violations for as long as your team's change process requires. The step is done when the enforced policy passes the same checks on production and the rollback procedure has been written down.

HSTS, TLS and the reverse proxy in front of Strapi

Strapi's security headers only take effect as the browser receives them, and that depends on where TLS ends and which layer adds each header. The cards below cover the HSTS decisions, the subdomain risk, the proxy layout and the forwarded headers Strapi relies on, so the team can settle them before the header tuning starts.

Choosing HSTS max-age

HSTS tells browsers to use HTTPS only for the Strapi hostname for a set period. Start with a short max-age while you confirm that every route, redirect and admin URL is served over TLS, then raise it once the setting has held in production. A long max-age is hard to undo, because browsers that cached the header will keep refusing plain HTTP until it expires. Confirm the intended value with your security team before the first deployment.

includeSubDomains and lockout risk

The includeSubDomains directive extends the HSTS rule to every subdomain of the Strapi host. If a sibling service on a subdomain, such as a legacy site, a static file host or a test environment, still serves plain HTTP or has an invalid certificate, browsers will fail to reach it. Inventory every hostname under the same parent domain before enabling the directive, and treat preload listing as a separate, later decision.

Where the header is set

The HSTS header can come from Strapi's security middleware or from the reverse proxy, load balancer or ingress in front of it. Pick one owner. Setting it in both places produces duplicate headers, and browsers may reject or merge them unpredictably. Many teams set it at the edge, where every response is covered, including error pages that never reach the Strapi process. Record the choice in the deployment runbook.

TLS termination and what Strapi sees

When TLS ends at the proxy, Strapi receives plain HTTP from the proxy and sees the scheme and client address only through forwarded headers such as X-Forwarded-Proto and X-Forwarded-For. If those headers are wrong, Strapi may build http links, mis-log client addresses, or apply IP-based rules to the proxy address. Confirm which headers the proxy sets, which trusted proxy addresses Strapi accepts, and that clients cannot inject their own forwarded values.

Verifying proxy header behavior

After deployment, request the admin panel and a public API route from outside the network and inspect the response headers. Check that each security header appears exactly once, that the HTTP to HTTPS redirect uses the correct host, and that the values match the configured CSP and HSTS settings. Repeat the check through each proxy layer, since a CDN or ingress controller can add or strip headers. Keep the captured output as evidence for the go-live review.

How the middleware fits into the request path

Security headers are added in three places, and knowing which one owns each header is the first decision in this section. A request for the admin panel, the Content API or a front end reaches your reverse proxy first, which terminates TLS and can add headers of its own. It then passes to the Strapi middleware stack, where the security middleware configured in config/middlewares.js sets headers on responses Strapi generates, such as admin HTML and JSON from the Content API. The browser is the last enforcer: it applies Content-Security-Policy, frame restrictions and Strict-Transport-Security to the page it loaded and blocks anything the policy forbids. If the proxy and the application both set the same header, responses can carry duplicates or conflicting values, so assign one owner per header and confirm the final response with a request from outside your network.

The headers draw trust boundaries that match the origins in your architecture. The admin origin serves scripts and styles that only the admin panel needs, so its policy can be strict about script sources and framing, and it should never be embedded in another site. The public API origin returns JSON to front ends and renders no pages, so its headers focus on content type handling and framing, while CORS decides which browser origins may read its responses. Third-party storage hosts sit outside both boundaries: a media provider or CDN appears in img-src or media-src for the front end that displays files, and in connect-src only if the admin uploads directly to that host. Every host you add widens what a compromised page can load, so list each one with a stated reason.

Before writing any directive, draw the request paths for each origin: the admin panel, the public API, the front end preview and each storage host, and record which headers the proxy and Strapi each send. Then open the admin panel and the front end in a browser with developer tools open and watch the console for policy violations, since a blocked image or upload preview usually appears there first. Confirm the exact middleware option names and defaults for your Strapi version in the official documentation, because the security middleware settings can change between releases. Keep a written list of origins with the owner who approved each one, so a later change to the storage provider or preview host starts from the same map.

Where security headers apply in a request

The request starts in the browser, passes the reverse proxy where HSTS is usually set, then reaches the Strapi middleware stack, where the CSP and frame options are configured. Requests to the admin panel and the Content API follow different branches, and the admin panel must allow the upload provider's domains in its CSP. Check each response at the browser edge, since headers added by the proxy and by Strapi can overlap or conflict.

Where HSTS, CSP and frame options are set and checked on a request path.

Common mistakes that weaken or break headers

Most header problems in a Strapi deployment come from a few repeated patterns: policies loosened to make a feature work, headers set in two places, and settings applied before the site is stable. Each card below names one pattern and the check a reviewer should run against the live responses.

Wildcards in script-src and connect-src

A wildcard source in script-src or connect-src lets the page load scripts or call APIs from any host, which removes most of the protection the policy is meant to give. Wildcards often appear when an upload provider or preview tool fails to load and someone widens the policy until it works. Check the header on the admin panel and on the public site, and list each host that is allowed. Every entry should map to a named provider or front end.

Strapi SSO docs

Admin panel framed by other sites

If the admin panel can be embedded in a frame on another origin, an attacker can overlay it and trick an editor into clicking actions they did not intend. The admin panel should not be framed by any site, and frame-ancestors should be set to 'none' or to a short list of your own origins. Test by loading the admin URL from a page on a different host and confirming that the browser refuses to render it.

Duplicate headers from proxy and application

When both the reverse proxy and Strapi's security middleware set the same header, browsers may receive two values and apply the stricter or the looser one, depending on the browser. A proxy that strips or overwrites headers can also remove the policy the application set. Inspect the response at the edge and at the application port, and confirm each header appears once with the intended value. Record which layer owns each header.

HSTS before HTTPS is stable

Strict-Transport-Security tells browsers to use HTTPS for the host for a set period, so a certificate or redirect problem can lock users out until the period expires. Enable it only after every hostname serves valid HTTPS and the redirect chain is confirmed. Start with a short max-age and lengthen it once monitoring shows no certificate or redirect errors. Confirm the value with the team that owns DNS and certificates before you raise it.

Preview origins left out of the policy

Preview features load the front end in a frame or call it from the admin panel, so a policy written only for the production site will block them. The result is often a blank preview that teams report as a Strapi fault. List the preview origins explicitly in the frame and connect directives, and keep them separate from production origins. Test preview from each editor role and in each environment before go-live.

Verifying headers after deployment

How do I check security headers on the Strapi admin panel after deployment?

Open the admin panel in a browser, open the developer tools, and inspect the response headers for the main document and for the scripts and stylesheets it loads. Confirm that the Content-Security-Policy, Strict-Transport-Security, X-Frame-Options and X-Content-Type-Options headers are present and match what you configured. Repeat the check from a private window and from each hostname or path that serves the admin, because a reverse proxy or CDN can add, drop or override headers set by Strapi. Record what you see so the next change can be compared against it.

Which command-line tools can confirm headers returned by a Strapi API?

Use curl with the -I flag to request headers only, and send an Origin header or request with -H to see how the response changes for a specific caller. Run the same request against the front end, the admin panel and a representative API route, and compare the output side by side. Save the output as evidence for the release record. Test over HTTPS only, because a redirect from HTTP can hide a missing header on the first response. Check that headers are not duplicated, since two conflicting values can appear when both the application and the proxy set them.

Can an external scanner verify Strapi headers and TLS settings?

Yes, an external scanner gives an outside view of the same headers and TLS settings that a visitor sees, which is useful because it tests the full path through load balancers and proxies. Choose a scanner your security team already trusts, run it against each public hostname, and keep the report with the date and configuration version. Scanners flag missing headers and weak directives but cannot judge whether your Content Security Policy fits your upload provider or preview setup, so review every flagged item against the intended behavior. Confirm the scanner's findings against a browser check before you change anything.

How do I confirm that the Content Security Policy is actually enforced?

Load each main page in a browser and watch the console for policy violation messages, which name the blocked resource and the directive that blocked it. A header that is present does not prove enforcement, so also check that the policy is delivered as Content-Security-Policy and not only as a report-only header. Exercise the features that depend on the policy, including media upload, asset preview and the admin editor, because a blocked script or image often appears only when a user performs that action. Treat each violation as either a needed allowance or a real problem, and document which one it is.

How should I read CSP violation reports from Strapi?

If you configured a reporting endpoint, review the reports for patterns rather than single events, since one blocked extension or browser plugin can create noise. Group reports by directive, blocked URI and document, then decide whether each group points to a missing allowance for an upload provider, a preview host or an analytics tag, or to unexpected content that should be blocked. Look for reports that mention unfamiliar domains, which can indicate injected content and need investigation. Keep the reporting endpoint's own access controls and retention in mind, since the reports can contain URLs with personal data. Confirm the process with your security team before relying on it.

What should I check after a Strapi header change goes live?

Run a short, repeatable checklist that covers the admin panel, the front end and at least one API route, and compare the results with the last approved baseline. The checklist should include header presence and values, HSTS on HTTPS responses only, frame restrictions for the admin, the CSP behavior on upload and preview flows, and CORS responses for each allowed origin. Ask your team to run the same checklist after each platform upgrade, proxy change or CDN rule change, since those changes often override application settings without warning. Store the checklist results with the change record.

Can my own team verify Strapi headers, or do we need a partner?

Most teams can run the checks described here with access to the browser, a terminal and the reverse proxy configuration, so the main question is whether someone owns the baseline and repeats the checks after each change. A partner adds value when the policy needs design work for several upload providers, previews and embedded tools, or when you need written evidence for an assessment. DeployOpen's security testing covers application and API testing, which can include header and policy review, and the scope and deliverables are agreed in writing before work starts. Ask any provider to state which headers, hostnames and flows they will test.

Limits to confirm in your environment

The header and CSP settings in a Strapi project depend on the exact Strapi version, the browser population you serve and the hosting layer in front of the application. The cards below list the facts to confirm before you write a policy, so the values you ship match what your stack actually does.

Exact middleware options in your version

Strapi's security middleware options can differ between minor releases, so the option names and their shapes must be read from the installed version rather than from memory or an older tutorial. Check the config/middlewares.ts entry that your project actually loads, and confirm how the contentSecurityPolicy directives are merged with the defaults. Record the Strapi version next to every header value you approve, because a later upgrade can change how those values are interpreted.

Installation requirements

Browser support for each directive

Not every browser enforces every CSP directive or header in the same way, and some older clients ignore directives that newer ones honor. Before you rely on a directive such as frame-ancestors or a strict script-src for the admin panel, test the set of browsers your editors and visitors actually use. Note which directives you cannot rely on, and decide whether a fallback or a server-side control covers that gap.

Provider-specific origins

Upload providers, media CDNs, preview hosts and analytics tools each need their own origins in img-src, media-src, connect-src or frame-src. Build the list from the providers you have configured, not from a template, and confirm the exact hostnames and any regional endpoints with each vendor. An origin added for a provider you later remove is an unneeded allowance, so review the list whenever a provider changes.

Custom headers on the hosting platform

Some managed hosts, load balancers and CDNs set, strip or override response headers at their own layer. Confirm whether your platform lets you add custom headers, and whether it already injects a default Strict-Transport-Security or frame policy that could conflict with Strapi's own settings. Where the platform cannot set a header, decide whether the reverse proxy you control can, and document which layer owns each header.

Admin and preview frame behavior

The admin panel and any preview feature may need to load your front end in an iframe, while the public site may need to block framing entirely. These two needs pull frame-ancestors and X-Frame-Options in different directions. Confirm the exact hostnames that embed Strapi and that embed your front end, and test each path after deployment so a legitimate preview does not fail silently.

HSTS scope and rollout

Strict-Transport-Security applies to every subdomain when includeSubDomains is set, and a long max-age is hard to reverse once browsers cache it. Confirm that every hostname under the domain serves HTTPS, and agree the rollout sequence with your team before you set a long duration. Ask your security team which preload or subdomain policy they already enforce, so the Strapi value does not contradict it.

Cost, effort and what the work needs from you

What drives the effort of a Strapi CSP and security headers project?

The main drivers are how many origins the front end, admin panel, preview and upload providers use, how many reverse proxies or CDNs sit in front of Strapi, and whether headers are set in Strapi's middleware, at the proxy, or both. Each extra origin adds a directive to test. Each proxy layer adds a place where a header can be duplicated, stripped or overwritten. Preview setups and third-party media or email widgets add further cases, because each one needs its own allowance and its own browser test. A project with one front end, one bucket and one proxy is far smaller than one with several sites and a preview environment.

Can our internal team tune Strapi security headers without a partner?

Often yes, if your engineers know Strapi's middleware configuration, your reverse proxy and browser developer tools. The work is configuration and testing rather than new code, but mistakes are easy to make, such as a CSP that blocks the admin panel or an HSTS policy that locks out a hostname you still need on plain HTTP. A partner is most useful when you need an independent review before go-live, when several teams share the same domains, or when the team lacks time to test every page type. Decide based on who will own the policy after launch and who will check it after each Strapi upgrade.

What does our team need to provide before a headers review starts?

Plan to provide the architecture, the list of domains and subdomains, and the reverse proxy or CDN configuration in use. For upload providers, confirm the exact hostnames and whether files load through the browser directly or through Strapi. For preview, name the front-end hostnames and any framework that injects scripts. Test accounts for each role, including an editor and an anonymous visitor, are needed to exercise the admin panel and public pages. Also share the current Strapi version and the hosting model, because headers can be set in different places depending on how Strapi is deployed.

How is the cost of a Strapi security headers engagement quoted?

DeployOpen does not publish a price list. A quote follows from a written scope that lists the origins, environments, proxies, browser and page types to test, the deliverables, and the timeline agreed before work starts. Ask for the cost split between configuration, testing, documentation and any retest, and whether it is one-time or includes ongoing review. Ask what is excluded, such as changes to the front-end application or proxy platform that your team owns. Most engagements are fixed-scope, so changes to scope should be written down before they are priced.

What recurring work follows a Strapi CSP rollout?

Headers need review whenever Strapi is upgraded, a new upload provider or analytics script is added, a front end gains a new third-party service, or the preview domain changes. Strapi 5 releases ship often, so check the release notes for middleware or admin changes before each upgrade. Recurring work is usually small per cycle but never zero, so decide who owns the policy file and who approves a change. Retainers for upgrades and continuous testing are available if you prefer ongoing support over one-off reviews.

Which header problems cause the most delay in a Strapi project?

Delays usually come from a CSP that blocks images, fonts or scripts loaded from an upload provider, a preview iframe that is refused by a frame options setting, or an HSTS policy applied before every subdomain supports HTTPS. Headers set twice, once by Strapi and once by a proxy, can conflict silently. Expect time for browser-by-browser checks and for finding which directive a blocked request needs. Confirm each allowance with the provider's documentation and with your own network team rather than copying a policy from another project.

Does a headers review make our Strapi deployment compliant?

No. A headers review produces configuration, evidence and a findings report that your compliance or audit team can use, but it does not issue an audit report, attestation or certification. Independent auditors and certification bodies make those determinations. Ask which controls your assessor expects to see for transport security and browser protections, and confirm with them how they want the evidence presented.

How DeployOpen scopes and tests Strapi header changes

DeployOpen plans, implements, hardens and documents self-hosted open-source platforms inside your own infrastructure, and Strapi header work fits that model. The Strapi instance, its reverse proxy, the CDN in front of it and the upload provider all sit in the cloud accounts, data centers or air-gapped networks you control, so the header and CSP changes are made and verified there. DeployOpen also runs security testing, so the same engagement can check the headers from an attacker's point of view after they are deployed, not only confirm that a config file was edited. Work is delivered as a fixed-scope engagement with scope, deliverables and timelines agreed in writing before anything changes. For header work, that scope should name the environments covered (for example, staging and production), which origins and hostnames are in play, which upload provider and preview hosts must be allowed, and who signs off on each change. Ask for the written scope to list the exact header checks that will be run and the retest that follows any fix.

DeployOpen prepares systems, controls and evidence for compliance assessments, such as the captured header configuration, the test results, and the change records that show who approved a CSP or HSTS change and when. It does not issue audit reports, attestations or certifications. Those come from independent auditors or certification bodies, and you should confirm early which evidence your assessor expects and in what format. If your assessor asks for a control mapping, ask for it to be drafted from your own framework and reviewed by your compliance team. Keep in mind that header settings change over time as upload providers, analytics tools and preview integrations are added, so the evidence should be refreshed, not captured once.

Ongoing support is available as a retainer for teams that want header and CSP checks repeated after each Strapi upgrade, plugin change or new third-party script. A retainer covers the work that the fixed-scope engagement does not, such as re-running the header checks against each release and reviewing new directives before they reach production. Ask any provider, including DeployOpen, to state in the quote which items recur, how often they are run, and what counts as an out-of-scope request that would need a new written agreement.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.