Frameguard is an Express.js middleware designed to enhance web application security by setting the `X-Frame-Options` HTTP header. This header primarily helps mitigate clickjacking attacks by restricting whether a browser can render a page in an `<frame>`, `<iframe>`, `<embed>`, or `<object>` tag. The current stable version is 4.0.0, and its release cadence is generally tied to the broader Helmet.js project, of which it is a part, receiving updates alongside Helmet's release cycle. While the `X-Frame-Options` header is largely superseded by the more robust `frame-ancestors` Content Security Policy (CSP) directive in modern browsers, Frameguard remains valuable for providing a layer of protection against clickjacking in older browser environments that may not fully support CSP. It differentiates itself by offering a simple, focused implementation for the most common and secure directives: `DENY` (preventing any framing) and `SAMEORIGIN` (allowing framing only from the same origin).
npm install frameguardVerified import paths — ran on the pinned version, not inferred.
Demonstrates applying `frameguard` middleware to an Express.js application with different `X-Frame-Options` actions: `deny` and `sameorigin`, and the default behavior.
Consider implementing a Content Security Policy with the `frame-ancestors` directive for modern browser protection. Example: `app.use(helmet.contentSecurityPolicy({ directives: { frameAncestors: ["'self'", 'https://trusted.com'] } }));`If `ALLOW-FROM` functionality is required, you must manually set the `X-Frame-Options` header or use a `Content-Security-Policy` with `frame-ancestors` for more granular control over framing sources.
Ensure `frameguard` is installed (`npm install frameguard`) and then explicitly import and apply it: `import frameguard from 'frameguard'; app.use(frameguard());`
If your application should never be framed, explicitly set `action: 'deny'` (e.g., `app.use(frameguard({ action: 'deny' }));`) for maximum protection against clickjacking.For CommonJS, use `const frameguard = require('frameguard'); app.use(frameguard());`. For ESM, use `import frameguard from 'frameguard'; app.use(frameguard());`.If you need to allow framing from the same origin, change the action to `sameorigin`: `app.use(frameguard({ action: 'sameorigin' }));`. If framing from other origins is required, consider using `Content-Security-Policy: frame-ancestors` instead.Ensure `app.use(frameguard(...))` is called before any routes that require the header. Check for other security middleware that might be removing or conflicting with the `X-Frame-Options` header.
No dependency data recorded yet.