gitmyhub

keyguard_express

TypeScript ★ 0 updated 14d ago

KeyGuard Express is Express.js middleware that adds API key authentication, rate limiting, and abuse blocking to a Node.js backend.

TypeScriptExpress.jsNode.jsSQLiteRedissetup: easycomplexity 3/5

KeyGuard Express is a TypeScript library that adds API key based security to an Express.js web server, the most widely used framework for building web APIs in Node.js. It is a port of an earlier Python project of the same idea, rebuilt for JavaScript and TypeScript developers.

Once installed, it acts as middleware, meaning it sits in front of your existing routes and checks every incoming request before your own code runs. It requires a valid API key sent in a request header, and it rejects requests with a missing, invalid, or expired key. Beyond basic authentication, it enforces monthly usage caps per key, applies rate limiting so a single key or IP address cannot flood your server with requests, and can automatically block IP addresses that repeatedly send bad or missing keys. Keys are stored hashed rather than in plain text, using a well established password hashing method, and older, unsalted keys keep working during the transition.

The library also supports scopes, letting you restrict which routes a given key is allowed to call, such as read only versus write access, and organizations, so you can manage keys and limits separately for different customers or teams. It comes with an admin API and a command line tool for creating organizations, generating and revoking keys, rotating a key to a new one without downtime, and viewing an audit log of admin actions. Extra middleware pieces cover request body validation using the Zod library, verifying webhook signatures with HMAC, adding common security response headers, and configuring cross origin request rules.

Data is stored in SQLite by default with no extra setup required, though PostgreSQL is also supported for larger deployments, and rate limiting can run purely in memory or be backed by Redis for use across multiple servers.

This is a young, unstarred project written in TypeScript, aimed at developers who want to add production style API key protection to a Node.js and Express backend without writing all of this security logic themselves from scratch.

Where it fits