Elysia Helmet

3.1.0 · active · verified Wed Apr 22

Elysia Helmet is a security plugin for the Elysia web framework, designed to protect applications by setting various HTTP response headers. It functions as a direct port of the well-known `helmet` middleware from the Express ecosystem, adapting its battle-tested security configurations to the modern Elysia runtime. The current stable version is 3.1.0. Given its nature as a framework-specific plugin, its release cadence is closely aligned with updates to the Elysia framework itself and the upstream `helmet` project, ensuring continuous compatibility and incorporating the latest web security best practices. Its primary differentiator is providing a familiar and comprehensive suite of HTTP security headers specifically integrated for Elysia, enabling developers to easily apply crucial security measures without manual header management.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to install and integrate elysia-helmet into an Elysia application with basic security header configurations, including Content Security Policy, X-Content-Type-Options, and X-Frame-Options.

import { Elysia } from 'elysia';
import { helmet } from 'elysia-helmet';

const app = new Elysia()
  .use(helmet({
    contentSecurityPolicy: {
      directives: {
        defaultSrc: ["'self'"],
        scriptSrc: ["'self'", "'unsafe-inline'"],
        imgSrc: ["'self'", 'data:'],
      },
    },
    xContentTypeOptions: true,
    xFrameOptions: { action: 'deny' },
  }))
  .get('/', () => 'Hello Elysia with Helmet!')
  .listen(3000);

console.log(`Server is running at ${app.server?.hostname}:${app.server?.port}`);

view raw JSON →