Fix guides · Security
How to add the X-Content-Type-Options: nosniff header
One line that stops browsers guessing file types, which closes off a class of attacks using uploaded files. Steps for Shopify, WordPress, Webflow, Wix, Squarespace and Next.js.
- Time to fix
- 5–10 minutes
- Skill needed
- Copy and paste
- Who notices
- Visitors, if anyone can upload files to your site
Why it matters
When a file's type is unclear, browsers sometimes "sniff" its contents and guess. An uploaded file labelled as plain text could then be run as a web page or a script.
The nosniff header tells browsers to trust the declared type and never guess. It's a single line with no visible effect on a correctly set-up site.
“This prevents XSS-attacks where user-uploaded content is executed as an HTML document, even if the browser has specified that it should be treated as plain text (or some other type).”
Before you start
- The header only has one valid value: nosniff.
- If a script or stylesheet stops loading afterwards, your server is sending it with the wrong file type. Fix the type rather than removing the header.
Fix it on your platform
Shopify Managed by the platform
- Shopify runs the servers for your store and doesn't let stores on its standard plans add or change response headers, so there's nothing to edit in your theme.
- If this check matters to you (for example, for a security questionnaire), ask Shopify support about X-Content-Type-Options for your store. Stores on Shopify Plus or a headless setup (Hydrogen) can set their own headers.
WordPress
- Where you add the header depends on your hosting, not WordPress itself. First check your host's dashboard: many managed WordPress hosts have a security-headers setting.
- On Apache hosting, add the line below to the .htaccess file in your site's root folder (back the file up first). On Nginx, add it to your site's server block, or ask your host to.
- If your site runs through Cloudflare with the orange-cloud proxy on, you can add the header there instead, with a Response Header Transform Rule.
Header always set X-Content-Type-Options "nosniff"add_header X-Content-Type-Options "nosniff" always;Webflow Managed by the platform
- Webflow only allows custom security headers on Enterprise plans. On other plans, this header can't be added.
- On Enterprise, add it in Site settings → Publishing → Custom Headers.
Wix Managed by the platform
- Wix doesn't offer a setting for custom response headers, so this can't be added from the Wix Editor.
- If you need it for compliance, contact Wix support and ask how they handle this header on your domain.
Squarespace Managed by the platform
- Squarespace has no setting for custom response headers, and code injection adds code to your pages, not headers.
- If you need it for compliance, contact Squarespace support and ask how they handle this header on your domain.
Next.js
- Add the header for every route in next.config.ts using headers().
- If you host on Vercel or Netlify, you can set it in vercel.json or netlify.toml instead; use one place, not both.
const nextConfig = {
async headers() {
return [
{
source: "/:path*",
headers: [{ key: "X-Content-Type-Options", value: "nosniff" }],
},
];
},
};
export default nextConfig;Any other site
- Add the header where your site is served from: your web server, hosting control panel or CDN. Pick the example that matches your setup.
- Cloudflare (proxied, orange cloud): add it with a Response Header Transform Rule.
/*
X-Content-Type-Options: nosniffHeader always set X-Content-Type-Options "nosniff"add_header X-Content-Type-Options "nosniff" always;Check that it's fixed
- Re-run your StudioLNC audit: the "Missing X-Content-Type-Options: nosniff" issue should be gone.
Find every issue like this on your site
Free audit of performance, accessibility, SEO and security, with fixes for your platform.