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

@fastify/helmet

Package Overview
Dependencies
Maintainers
20
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/helmet

Important security headers for Fastify

  • 13.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
20
Created

What is @fastify/helmet?

@fastify/helmet is a Fastify plugin that helps secure your Fastify applications by setting various HTTP headers. It is a wrapper around the Helmet.js library, which is widely used in the Express.js ecosystem for enhancing security.

What are @fastify/helmet's main functionalities?

Basic Usage

This code demonstrates how to register the @fastify/helmet plugin with a Fastify application to set various HTTP headers for security.

const fastify = require('fastify')();
const helmet = require('@fastify/helmet');

fastify.register(helmet);

fastify.get('/', async (request, reply) => {
  return { hello: 'world' };
});

fastify.listen(3000, err => {
  if (err) throw err;
  console.log('Server listening on http://localhost:3000');
});

Custom Configuration

This code shows how to customize the configuration of @fastify/helmet, such as disabling the Content Security Policy and setting the frameguard to deny.

const fastify = require('fastify')();
const helmet = require('@fastify/helmet');

fastify.register(helmet, {
  contentSecurityPolicy: false,
  frameguard: { action: 'deny' }
});

fastify.get('/', async (request, reply) => {
  return { hello: 'world' };
});

fastify.listen(3000, err => {
  if (err) throw err;
  console.log('Server listening on http://localhost:3000');
});

Using Specific Helmet Middleware

This code demonstrates how to use specific middleware options provided by Helmet, such as dnsPrefetchControl and referrerPolicy.

const fastify = require('fastify')();
const helmet = require('@fastify/helmet');

fastify.register(helmet, {
  dnsPrefetchControl: { allow: true },
  referrerPolicy: { policy: 'no-referrer' }
});

fastify.get('/', async (request, reply) => {
  return { hello: 'world' };
});

fastify.listen(3000, err => {
  if (err) throw err;
  console.log('Server listening on http://localhost:3000');
});

Other packages similar to @fastify/helmet

Keywords

FAQs

Package last updated on 25 Nov 2024

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