Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

next-security

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-security

Security plugin for Next.js based on OWASP and Helmet

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

next-security

npm version npm downloads Github Actions CI License

Security plugin for Next.js based on OWASP and Helmet.

Features

  • No configuration security headers similar to Helmet.js
  • Customization of all header values
  • [Coming soon] Content Security Policy (CSP) for SSG apps
  • [Coming soon]Request Size limiter
  • [Coming soon]Cross Site Scripting (XSS) Validation
  • [Coming soon]Cross-Origin Resource Sharing (CORS) support
  • [Coming soon] [Optional] Allowed HTTP Methods, Basic Auth, CSRF, Rate Limiter

Usage

Install the plugin:

npm i next-security
yarn add next-security
pnpm add next-security

Add the plugin to the next.config.js like following:

/** @type {import('next').NextConfig} */
const { nextSecurity } = require('next-security');
const nextConfig = {
  ...nextSecurity(),
};

module.exports = nextConfig;

Or, if you want to have more control over the source for the headers:

/** @type {import('next').NextConfig} */
const { generateSecurityHeaders } = require('next-security');
const nextConfig = {
  async headers() {
    return [
      {
        source: '/(.*)',
        headers: generateSecurityHeaders(),
      },
    ];
  },
};

module.exports = nextConfig;

And that's it! The plugin will now register security response headers so that your application will be more secure.

If you inspect the headers that are being returned by the Next application in the browser, you should see the following result:

cross-origin-resource-policy: same-origin
cross-origin-opener-policy: same-origin
cross-origin-embedder-policy: require-corp
content-security-policy: base-uri 'self'; font-src 'self' https: data:; form-action 'self'; frame-ancestors 'self'; img-src 'self' data:; object-src 'none'; script-src-attr 'none'; style-src 'self' https: 'unsafe-inline'; upgrade-insecure-requests
origin-agent-cluster: ?1
referrer-policy: no-referrer
strict-transport-security: max-age=15552000; includeSubDomains
x-content-type-options: nosniff
x-dns-prefetch-control: off
x-download-options: noopen
x-frame-options: SAMEORIGIN
x-permitted-cross-domain-policies: none
x-xss-protection: 0
permissions-policy: camera=(), display-capture=(), fullscreen=(), geolocation=(), microphone=()

Configuration

You can pass configuration to the plugin like following:

/** @type {import('next').NextConfig} */
const { nextSecurity } = require('next-security');
const nextConfig = {
  ...nextSecurity({
    headers: {
      xXSSProtection: '1',
      crossOriginResourcePolicy: 'cross-origin',
      contentSecurityPolicy: false,
    },
  }),
};

module.exports = nextConfig;

FAQs

Package last updated on 27 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc