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

@faranglao/sveltekit-security-headers

v0.2.2

Published

A security library for SvelteKit, improving safety using HTTP Response Headers

Downloads

23

Readme

SvelteKit Security Headers

Enhance visitor security in SvelteKit based web applications.

Add those missing HTTP response headers with sveltekit-security-headers.

Node.js CI Lint Playwright Tests

Installation

npm install @faranglao/sveltekit-security-headers

Getting Started

To add HTTP response headers to your application install the package and export the SvelteKitSecurityHeaders().handle function.

The SvelteKitSecurityHeaders().handle function is a SvelteKit Server Hook that is exported in src/hooks.server.ts.

// samples/securityheaders/hooks.server.ts
// copy to src/hooks.server.ts
import { SvelteKitSecurityHeaders } from '@faranglao/sveltekit-security-headers';

export const handle = SvelteKitSecurityHeaders().handle;

Then run the web application using npm run dev.

The handle function will add the following headers to your sites HTTP traffic.

# Headers added to HTTP Response
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: geolocation=(), camera=(), microphone=()

Security Headers

Having already delivered over 250 million scans the Security Headers site is a useful tool for analyzing HTTP headers.

The scan returns a score from an A+ grade down to an F grade. You can find more information on scoring on Scott Helme's Security Headers blog.

With minimal configuration SvelteKitSecurityHeaders().handle will add those missing HTTP headers required to achieve an A grade score on securityheaders.com

Customizing Response Headers

The SvelteKitSecurityHeaders().handle function makes it possible to fully customize the HTTP response headers returned from your application.

The code below shows how to apply both pre-configured headers and add customer values to your HTTP responses.

// samples/custom/hooks.server.ts
// copy to src/hooks.server.ts
import { SvelteKitSecurityHeaders, RuleSet } from '@faranglao/sveltekit-security-headers';

export const handle = SvelteKitSecurityHeaders({
  headers: [
    // remove any duplicates with a Set
    ...new Set([
      ...RuleSet.SecurityHeaders,
      ...RuleSet.SvelteKitSpecific,
      ...RuleSet.OwaspRecommendedMinimal,

      // Access-Control-Allow-Origin header to allow requests
      // from your domain .. override value
      {
        name: 'Access-Control-Allow-Origin',
        value: 'https://sveltekit-security-headers.vercel.app'
      }

      // .. add custom headers
    ])
  ],
  verbose: true
}).handle;

Multiple Server Hooks

The following code sample shows how to use the sequence helper function to wrap existing server hook code and invoke the SvelteKitSecurityHeaders().handle function.

// samples/sequence/hooks.server.ts
// copy to src/hooks.server.ts
import type { Handle } from '@sveltejs/kit';
import { sequence } from '@sveltejs/kit/hooks';
import { SvelteKitSecurityHeaders } from '@faranglao/sveltekit-security-headers';

export const handle: Handle = sequence(
  /* existing Hook code , */
  SvelteKitSecurityHeaders().handle
);

Source Code

Source code for the sveltekit-security-headers package is maintained on GitHub.