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 🙏

© 2025 – Pkg Stats / Ryan Hefner

express-tailscale-auth

v0.0.1

Published

Express middleware for Tailscale authentication

Downloads

4

Readme

express-tailscale-auth

Express middleware for Tailscale authentication and authorization. Automatically authenticate users based on their Tailscale connection and optionally enforce fine-grained permissions using Tailscale Access control capabilities.

Why use this?

If you're already using Tailscale to secure your infrastructure, this middleware lets you leverage that same identity system for your web applications. No need for separate login systems, password management, or external authentication providers.

Perfect for:

  • Internal tools and dashboards - Automatically authenticated for your team
  • Services behind Tailscale Funnel/Serve - Secure public endpoints with zero-config auth
  • Hybrid applications - Keep marketing pages public while protecting /admin or /api routes

Your users get seamless access to applications just by being connected to your Tailscale network, while you get enterprise-grade identity and access management without the complexity. No separate login or auth keys needed.

Or thats the idea anyway.

Features

  • 🔐 Zero-config authentication - Users are automatically authenticated if they're connected via Tailscale
  • 🎯 Capability-based authorization - Fine-grained permissions using Tailscale Access control grants
  • 🔍 User information - Access to Tailscale user profile in your route handlers

Installation

npm install express-tailscale-auth

Basic Usage

import express from 'express'
import { createTailscaleAuthMw } from 'express-tailscale-auth'

const app = express()
app.set("trust proxy", ["loopback", "uniquelocal", "linklocal"]);

// Create the authentication middleware
const tailscaleAuth = createTailscaleAuthMw()

// Apply to all routes
app.use(tailscaleAuth)

// Or apply to specific routes
app.get('/protected', tailscaleAuth, (req, res) => {
  // User information is available in req.tailscaleUser
  res.json({
    message: `Hello ${req.tailscaleUser?.displayName}!`,
    user: req.tailscaleUser
  })
})

app.listen(3000, () => {
  console.log('Server running on port 3000')
})

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | socketPath | string | undefined | Path to tailscaled unix socket. Auto-detected if not specified. | | useSocketOnly | boolean | false | Whether to only use unix socket for communication. | | debug | boolean | false | Enable debug logging to console. | | capabilitiesNamespace | string | undefined | Namespace for capability-based authorization. |

Reverse Proxy Configuration

If you need this middleware your app most likely runs behind a reverse proxy (e.g. tailscale funnel / serve).

You need to configure trust proxy settings:

// For most reverse proxy setups
app.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal'])

see more https://expressjs.com/en/guide/behind-proxies.html

Capability-Based Authorization

For fine-grained access control, you can use Tailscale Access control capabilities. First, configure your Tailscale Access control with grants:

1. Configure Tailscale Access control

Add grants to your Tailscale Access control policy:

{
  "grants": [
    {
      "src": ["[email protected]"],
      "dst": ["*"],
      "app": {
        "myapp.com/capabilities": [
          {
            "routes": [
              {"route": "/api/admin/**", "methods": ["GET", "POST"]},
              {"route": "/api/users", "methods": ["GET"]},
              {"route": "/public/**", "methods": ["*"]}
            ]
          }
        ]
      }
    }
  ]
}

2. Configure Middleware

Set the capabilities namespace in your middleware:

const tailscaleAuth = createTailscaleAuthMw({
  capabilitiesNamespace: 'myapp.com/capabilities'
})

3. Route Matching

The middleware uses glob patterns for route matching:

  • ** matches any number of path segments
  • * matches a single path segment
  • Exact paths like /api/users match exactly