Traditional X-* headers for protecting against common web vulnerabilities including XSS, clickjacking, and information disclosure.
Prevents MIME type sniffing by instructing browsers to use the declared Content-Type.
/**
* Sets X-Content-Type-Options header to "nosniff"
* @returns Express middleware function
*/
function xContentTypeOptions(): MiddlewareFunction;Usage Example:
import { xContentTypeOptions } from "helmet";
app.use(xContentTypeOptions());
// Sets: X-Content-Type-Options: nosniffThis prevents browsers from interpreting files as different MIME types than declared, which can prevent XSS attacks via file upload vulnerabilities.
Controls DNS prefetching to improve privacy and reduce unnecessary DNS lookups.
/**
* Sets X-DNS-Prefetch-Control header
* @param options - DNS prefetch control options
* @returns Express middleware function
*/
function xDnsPrefetchControl(
options?: XDnsPrefetchControlOptions
): MiddlewareFunction;
interface XDnsPrefetchControlOptions {
/** Whether to allow DNS prefetching (default: false) */
allow?: boolean;
}Usage Examples:
import { xDnsPrefetchControl } from "helmet";
// Default: disable DNS prefetching
app.use(xDnsPrefetchControl());
// Sets: X-DNS-Prefetch-Control: off
// Enable DNS prefetching
app.use(xDnsPrefetchControl({ allow: true }));
// Sets: X-DNS-Prefetch-Control: onDNS prefetching can improve performance but may leak information about user browsing patterns. Disabling it improves privacy.
Prevents Internet Explorer from executing downloads in the site's context.
/**
* Sets X-Download-Options header to "noopen"
* @returns Express middleware function
*/
function xDownloadOptions(): MiddlewareFunction;Usage Example:
import { xDownloadOptions } from "helmet";
app.use(xDownloadOptions());
// Sets: X-Download-Options: noopenThis prevents IE from opening downloads directly in the browser context, reducing XSS risks from malicious downloads.
Prevents clickjacking attacks by controlling whether the page can be embedded in frames.
/**
* Sets X-Frame-Options header to prevent clickjacking
* @param options - Frame options configuration
* @returns Express middleware function
*/
function xFrameOptions(
options?: XFrameOptionsOptions
): MiddlewareFunction;
interface XFrameOptionsOptions {
/** Frame policy action (default: "sameorigin") */
action?: "deny" | "sameorigin";
}Usage Examples:
import { xFrameOptions } from "helmet";
// Default: allow same-origin framing
app.use(xFrameOptions());
// Sets: X-Frame-Options: SAMEORIGIN
// Deny all framing
app.use(xFrameOptions({ action: "deny" }));
// Sets: X-Frame-Options: DENYAction Values:
Note: Consider using CSP
frame-ancestorsControls cross-domain policy file access for Flash and PDF content.
/**
* Sets X-Permitted-Cross-Domain-Policies header
* @param options - Cross-domain policies configuration
* @returns Express middleware function
*/
function xPermittedCrossDomainPolicies(
options?: XPermittedCrossDomainPoliciesOptions
): MiddlewareFunction;
interface XPermittedCrossDomainPoliciesOptions {
/** Policy permission level (default: "none") */
permittedPolicies?: "none" | "master-only" | "by-content-type" | "all";
}Usage Examples:
import { xPermittedCrossDomainPolicies } from "helmet";
// Default: no cross-domain policies
app.use(xPermittedCrossDomainPolicies());
// Sets: X-Permitted-Cross-Domain-Policies: none
// Allow master policy file only
app.use(xPermittedCrossDomainPolicies({
permittedPolicies: "master-only"
}));
// Sets: X-Permitted-Cross-Domain-Policies: master-onlyPolicy Values:
Removes the X-Powered-By header to hide server technology information.
/**
* Removes X-Powered-By header
* @returns Express middleware function
*/
function xPoweredBy(): MiddlewareFunction;Usage Example:
import { xPoweredBy } from "helmet";
app.use(xPoweredBy());
// Removes: X-Powered-By headerThis prevents information disclosure about the server technology stack, making it slightly harder for attackers to identify potential vulnerabilities.
Disables legacy XSS filtering in browsers due to potential security issues.
/**
* Sets X-XSS-Protection header to "0" to disable legacy XSS filtering
* @returns Express middleware function
*/
function xXssProtection(): MiddlewareFunction;Usage Example:
import { xXssProtection } from "helmet";
app.use(xXssProtection());
// Sets: X-XSS-Protection: 0Legacy XSS filters in browsers can sometimes be bypassed or cause legitimate content to be blocked. Modern CSP is more effective for XSS prevention.
Helmet provides backward-compatible aliases for these headers:
// Legacy aliases (same functionality as above)
const noSniff: typeof xContentTypeOptions;
const dnsPrefetchControl: typeof xDnsPrefetchControl;
const ieNoOpen: typeof xDownloadOptions;
const frameguard: typeof xFrameOptions;
const permittedCrossDomainPolicies: typeof xPermittedCrossDomainPolicies;
const hidePoweredBy: typeof xPoweredBy;
const xssFilter: typeof xXssProtection;Usage Examples:
import {
noSniff,
frameguard,
hidePoweredBy
} from "helmet";
// These are equivalent to their X-* counterparts
app.use(noSniff());
app.use(frameguard({ action: "deny" }));
app.use(hidePoweredBy());Many of these legacy headers have modern replacements:
// Legacy
app.use(xFrameOptions({ action: "deny" }));
// Modern (preferred)
app.use(contentSecurityPolicy({
directives: {
"frame-ancestors": ["'none'"]
}
}));// Legacy (now disabled by Helmet)
app.use(xXssProtection());
// Modern (preferred)
app.use(contentSecurityPolicy({
directives: {
"script-src": ["'self'"],
"object-src": ["'none'"]
}
}));All these headers have excellent browser support, including legacy versions. However, modern CSP-based approaches are preferred for new applications as they provide more granular control and better security.