Registry / auth-security / referrer-policy

referrer-policy

JSON →
library1.2.0jsnpmunverified

Express/Connect middleware to set the Referrer-Policy HTTP header, part of the Helmet.js security suite. Version 1.2.0 is stable and works with Node >=4. Ships TypeScript definitions. Allows specifying one of the standard policy values (e.g., no-referrer, same-origin, strict-origin-when-cross-origin) or an array of policies for fallback. Lightweight and focused, with no external dependencies.

npm install referrer-policy
INSTALL
IMPORT
SIG · REFERRER-POLICY
R
referrer-policy
auth-securityjavascriptv1.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

referrerPolicy
import referrerPolicy from 'referrer-policy'
const referrerPolicy = require('referrer-policy')
Package is ESM-compatible via bundler; CommonJS require is still supported in Node <14 or without 'type':'module'.
referrerPolicy
const referrerPolicy = require('referrer-policy')
import { referrerPolicy } from 'referrer-policy'
Default export only; named import will fail.
Default import (TypeScript)
import referrerPolicy from 'referrer-policy'
import * as referrerPolicy from 'referrer-policy'
TypeScript types use default export; namespace import works but not idiomatic.

Shows how to import and use the middleware with Express, setting the policy to 'same-origin'.

import express from 'express'; import referrerPolicy from 'referrer-policy'; const app = express(); app.use(referrerPolicy({ policy: 'same-origin' })); // Sets Referrer-Policy: same-origin app.listen(3000);
Debug
Known issues
gotchaThe 'policy' option must be a string or an array of strings. If an array, only the first valid policy is used by some browsers.
fix
Pass a single policy string unless you intend fallback behavior (array).
affects: >=1.0.0
gotchaSetting policy to an empty string or invalid value will default to 'no-referrer' silently.
fix
Always validate policy against the allowed values listed in the spec.
affects: >=1.0.0
deprecatedThe 'policy' option default changed from 'no-referrer' to 'strict-origin-when-cross-origin'? Not applicable for this package; defaults to 'no-referrer'.
fix
Explicitly set policy to avoid ambiguity.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'referrer-policy'
Package not installed or import path wrong.
fix
Run 'npm install referrer-policy' and ensure import path matches package name.
TypeError: referrerPolicy is not a function
Using named import { referrerPolicy } instead of default import.
fix
Use 'import referrerPolicy from 'referrer-policy''.
Invalid policy value: 'something-else'
Passed an unsupported policy string.
fix
Use one of the valid policies: 'no-referrer', 'no-referrer-when-downgrade', 'same-origin', 'origin', 'strict-origin', 'origin-when-cross-origin', 'strict-origin-when-cross-origin', 'unsafe-url'.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources
referrer-policy — npm install referrer-policy · libregistry