npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

next-security

v1.1.1

Published

Security plugin for Next.js based on OWASP and Helmet

Downloads

177

Readme

next-security

npm version npm downloads Github Actions CI License

Security plugin for Next.js based on OWASP Top 10 and helmet that adds security response headers.

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 { headers } = require('next-security');
const nextConfig = {
  ...headers(), // with this approach you will also hide the `X-Powered-By` header that is a good pattern
};

module.exports = nextConfig;

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

/** @type {import('next').NextConfig} */
const { createHeaders } = require('next-security');
const nextConfig = {
  async headers() {
    return [
      {
        source: '/(.*)',
        headers: createHeaders(),
      },
    ];
  },
  // poweredByHeader: false // you can add this manually
};

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 { headers } = require('next-security');
const nextConfig = {
  ...headers({
    xXSSProtection: '1',
    crossOriginResourcePolicy: 'cross-origin',
    contentSecurityPolicy: false,
  }),
};

module.exports = nextConfig;