Skip to content

Improve your security headers

Your website emits headers in each response which are responsible for how clients and browsers interact with your site.

These headers are important as they provide controls which can protect your website from cross site scripting (XSS) and other malicious activity.

New projects start with Strict-Transport-Security: max-age=31536000, X-Content-Type-Options: nosniff and Referrer-Policy: strict-origin-when-cross-origin. These values are safe for any site.

The dashboard grades the security headers of your site and can add the recommended values. Then you add a Content Security Policy (CSP), which is specific to each site.

To save headers in Traffic > Headers, the project must belong to an organisation-level subscription. Otherwise the save fails with “Custom headers requires an organisation level subscription.”

  1. In the dashboard, open your project and go to Traffic > Security headers.

  2. Read the grade and the header badges. A badge with a warning sign marks a missing header.

    The Security headers page with grade C, “Could be better.”, and the header badges. The Content-Security-Policy and Permissions-Policy badges have a warning sign because the site does not send them.

The scan reads the headers of a domain of the project that has DNS engaged. If no domain has DNS engaged, the dashboard opens Domains instead and says “No domains currently have DNS engaged.” A scan needs the edit projects permission: without it, a project that has no scan result yet shows “No scan result yet” and asks you to ask a project editor. Select Refresh to scan again at any time.

The grade is a weighted score of six headers:

Header Weight
Strict-Transport-Security 3
Content-Security-Policy 3
X-Frame-Options 2
X-Content-Type-Options 2
Referrer-Policy 1
Permissions-Policy 1

A score of 95% or more is A+, 85% is A, 70% is B and 50% is C. Without an enforced Content-Security-Policy, the other five headers reach 75% at most, so the grade is B. A Content-Security-Policy-Report-Only header does not count.

The button adds each recommended header that the project does not set yet. Headers that the project already sets keep their values, and the button does not add a CSP. Before you select the button, know that:

  • It adds X-Frame-Options: SAMEORIGIN when the project does not set that header. If another site embeds your pages in an iframe, those embeds stop working.
  • Header names match in any letter case. If the project already has x-frame-options, the button keeps it and does not add a second X-Frame-Options.
  1. Go to Traffic > Security headers.

  2. In the card Add the missing headers, read “Grade after this”. It is the grade that the scan gives after the button adds its headers. Without a Content-Security-Policy it is B at most: the card says that a Content-Security-Policy is worth 3 of the 12 grade points, and that the button does not add one.

  3. Read the headers under “Headers that the scan found missing and that this adds”.

    The card Add the missing headers: the five headers and values it adds, the line “Grade after this: B.” with the note that a Content-Security-Policy is worth 3 of the 12 grade points and that this button does not add one, the missing header Permissions-Policy, and the Add missing headers button.

  4. Select Add missing headers. The dialog Add the missing security headers? lists each header and its value, and says “Existing header values are not changed.”

    The list and the dialog name only the headers that the scan found missing. The button writes every default that is not in Traffic > Headers, also a header that your origin already sends (for example X-Frame-Options from a CMS). After you use the button, check Traffic > Headers, and remove a row that you do not want the edge to send.

  5. Select Add headers. The message “Security headers updated. Please wait 30 seconds before refreshing the status.” shows.

  6. Wait 30 seconds, then select Refresh. The grade is now the one that the card showed.

To reach A or A+, add an enforced Content-Security-Policy (below). A Content-Security-Policy-Report-Only header does not count toward the grade.

The card Add the missing headers shows only when the grade is below A, and only on a project that Quant serves. The Add missing headers button shows only for a user with the edit projects permission. For other project types, the page shows the same values as Varnish VCL to add to your vcl_deliver block.

The button adds these values for each header that the project does not set:

Header Value Description
Strict-Transport-Security max-age=31536000 A Strict-Transport-Security (STS) header with max-age=31536000 enforces HTTPS for a minimum of 1 year. Quant redirects HTTP requests to HTTPS, and provides certificates for custom domains automatically (see SSL certificates). Add includeSubDomains only when every subdomain serves HTTPS.
Content-Security-Policy Not added We cannot provide default CSP values as they are site specific. See Add a Content Security Policy.
X-Frame-Options SAMEORIGIN The X-Frame-Options header with a value of SAMEORIGIN tells browsers that this page should only be framed (i.e., loaded within an iframe) if the request originated from the same domain as the current page.
X-Content-Type-Options nosniff The X-Content-Type-Options header with a value of nosniff tells browsers not to MIME-sniff the content type, and instead rely on the Content-Type HTTP header for determining the actual type of the response.
Referrer-Policy strict-origin-when-cross-origin The Referrer-Policy header with a value of strict-origin-when-cross-origin sends the full URL as the referrer only to your own site. Other sites receive only your origin (for example https://www.example.com), and nothing is sent when an HTTPS page links to an HTTP page. This is also the default in current browsers (MDN: Referrer-Policy).
Permissions-Policy microphone=(), camera=() The Permissions-Policy header with a value of microphone=(), camera=() indicates that the website has explicitly denied access to the user’s microphone and camera, even if the site would normally request permission for these features. This is an example of a “deny” policy for specific permissions. If your website requires microphone or camera access you may reconsider these values.

For more detail on each of these headers refer to the section below.

Header Description
Strict-Transport-Security The Strict-Transport-Security (STS) HTTP header is used to enforce secure connections, preventing downgrade attacks and ensuring all communications between a client and server are encrypted. It ensures that a connection cannot be downgraded to an insecure protocol, such as HTTP instead of HTTPS.
Content-Security-Policy The Content-Security-Policy (CSP) HTTP header is used to define which sources of content are allowed to be executed within a web page, helping protect against XSS attacks by specifying which scripts or resources can be loaded. It allows developers to set rules on where resources like scripts, stylesheets, and fonts can be loaded from.
X-Frame-Options The X-Frame-Options HTTP header is used to prevent clickjacking attacks by controlling whether a page can be loaded within an iframe on another domain, or if it should not be framed at all. It allows developers to specify which domains are allowed to frame their content. (Note: The X-Frame-Options has been deprecated and replaced with the Content-Security-Policy (CSP) header’s “frame-ancestors” directive in modern browsers.)
X-Content-Type-Options The X-Content-Type-Options HTTP header is used to prevent MIME-sniffing attacks by indicating that the server will always provide a specific Content-Type, preventing the browser from attempting to sniff and change it. This helps prevent attacks where an attacker might try to manipulate the browser’s interpretation of content based on its type.
Referrer-Policy The Referrer-Policy HTTP header is used to control whether or how the Referer (sic) HTTP header is sent with requests from a client to a server, protecting user privacy and preventing leaks of sensitive information such as referrers. It allows developers to set policies on what data about the previous page can be shared with the current page’s server.
Permissions-Policy The Permissions-Policy HTTP header is used to declare which permissions (such as camera, microphone, or geolocation) a website requires, allowing users to make informed decisions about which permissions are necessary and granting them control over their data. It helps protect user privacy by providing transparency into what permissions a site needs to function.

A CSP lists the sources from which the browser may load scripts, styles, images, fonts and connections. It is specific to each site: it must list every source your pages use, and it must change when your tags and vendors change.

There are two methods. Use one method for each site:

  • By hand, in Headers. Suits a site with few pages and few third-party scripts, which you can test yourself in a browser. In report-only mode, you see the reports only in the console of the browser you test with.
  • With Security > CSP. Suits a site with many pages, tags or vendors. Quant collects the reports from real visitors, and helps you keep the policy current. Available on selected plans.

Both methods start in report-only mode, read what the policy would block, and enforce the policy only when no reports are left.

  1. Go to Traffic > Headers. Response headers lists the headers of the project. Select Add header.

    The Custom headers page. Response headers lists Strict-Transport-Security, Referrer-Policy, X-Frame-Options, X-Content-Type-Options and Permissions-Policy, each with its value, and the Add header button below the list.

  2. In Header name, enter Content-Security-Policy-Report-Only. In Value, enter a strict start:

    default-src 'self'

    A new row with Header name Content-Security-Policy-Report-Only and Value default-src ‘self’ below the other headers, and the Save headers button with the note “A saved change takes up to 30 seconds to apply.”

  3. Select Save headers. The message “Custom headers updated. Please allow 30s for changes to apply.” shows. Wait about 30 seconds. Report-only mode reports problems and blocks nothing.

  4. Open your site in Chrome. Open the developer tools (F12, or Cmd+Option+J on a Mac), choose Console, and reload the page. The console lists each source that the policy would block, and says that the policy is report-only.

  5. For each source that you trust, add it to the policy value, then select Save headers. Repeat steps 4 and 5 on each type of page: the home page, a content page, search, forms and any page with embedded media.

  6. When no reports are left, change Header name to Content-Security-Policy and select Save headers. The browser now enforces the policy.

  7. Wait about 30 seconds and test the site again, with the console open. Then select Refresh on Traffic > Security headers. A policy with a default-src or script-src directive gets all 3 of its grade points. A policy without either directive gets only part of them; when the grade is below A, the card Add the missing headers says so.

For example, a small site that applies inline styles and loads data: images could end with:

default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:

Use this example only as a guide. 'unsafe-inline' for styles is a trade-off: it lets any inline style run. Tune the policy for each site.

The headers in Traffic > Headers apply to every response of the project. For a policy on one path only, use a custom response headers rule.

Content Security Policy with Security > CSP

Section titled “Content Security Policy with Security > CSP”

Security > CSP in the dashboard builds and maintains the policy and writes it to your Quant project. It is available on selected plans; contact Quant for access. It replaces ScriptAttest, which is now part of the Quant dashboard.

  1. Open the project and select Security > CSP.
  2. Scan: select the Base URL, add the pages, and start the scan. A headless browser loads each page and lists its sources. If the site already serves a CSP, you can import it as version 1.
  3. Review sources: approve or deny each domain and each inline hash.
  4. Generate the policy, then Validate it against the live pages until no violations remain.
  5. Deploy in report-only mode. Quant writes Content-Security-Policy-Report-Only and Reporting-Endpoints to the project and keeps your other headers. Browsers send violation reports to Quant.
  6. Review the Violations tab for 24 to 48 hours of normal traffic. Approve the sources that the site needs, and ignore the reports that browser tools cause.
  7. Select Switch to enforcing mode on the Policy tab, then deploy. Quant replaces the report-only header with Content-Security-Policy.

Security > CSP also compares each script with its baseline, and gives Subresource Integrity (SRI) values for external scripts. See Content Security Policy (CSP) for each step in detail.