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 🙏

© 2026 – Pkg Stats / Ryan Hefner

anti-session-hijack

v3.0.1

Published

Client SDK for session hijacking prevention

Readme

anti-session-hijack


Overview

anti-session-hijack detects session hijacking by binding an authentication token to a browser and device fingerprint, then validating that binding on every request. If the fingerprint changes — indicating a stolen token being used from a different device — the session is flagged immediately.


Installation

npm install anti-session-hijack

Features

  • Stolen and reused authentication token detection
  • Fingerprint-based session binding
  • Redis-backed storage (compatible with Upstash, ioredis, and node-redis)
  • Minimal, dependency-free core
  • Full TypeScript support

API Reference

generateFingerprint()

Collects browser signals — hardware, OS, canvas, and more — and produces a SHA-256 hash of those components as a stable, unique device identifier.

Parameters: None

Returns: Promise<FingerprintResult> — An object containing id (a 64-character hexadecimal SHA-256 hash), the raw components used in hashing, the algorithm version, and a generation time timestamp.

"use client";

import { generateFingerprint } from "anti-session-hijack";
import { useEffect, useState } from "react";

const [fingerprint, setFingerprint] = useState<string>("");

useEffect(() => {
  const load = async () => {
    const result = await generateFingerprint();
    setFingerprint(result.id);
  };

  load();
}, []);

addSession(authTokenHash, fingerprint, redis)

Associates a hashed authentication token with a browser fingerprint in Redis. Call this upon successful user login.

Parameters:

| Parameter | Type | Description | |---|---|---| | authTokenHash | string | The hashed version of the authentication token | | fingerprint | string | The unique browser fingerprint from the client | | redis | object | A Redis client instance (@upstash/redis, ioredis, etc.) |

Returns: Promise<void>

await addSession(hashedToken, userFingerprint, redisClient);

verifySession(authTokenHash, fingerprint, redis)

Checks whether the provided fingerprint matches the one stored for the given authentication token. Call this on every protected request or route.

Parameters:

| Parameter | Type | Description | |---|---|---| | authTokenHash | string | The hashed authentication token to verify | | fingerprint | string | The current browser fingerprint from the client | | redis | object | A Redis client instance |

Returns: Promise<object>

| Field | Type | Description | |---|---|---| | valid | boolean | true if fingerprints match | | hijacked | boolean | true if fingerprints do not match | | receivedFingerprint | string \| undefined | Fingerprint currently stored in Redis (for debugging) |

const result = await verifySession(hashedToken, currentFingerprint, redisClient);

if (result.hijacked) {
  // Revoke session, notify user, or trigger an alert
}

email(service, senderEmail, senderAppPassword, receiverEmail)

Sends a standardized security alert email to the user indicating a potential session compromise.

Parameters:

| Parameter | Type | Description | |---|---|---| | service | string | Email service provider (e.g., "gmail") | | senderEmail | string | Address used to send the alert | | senderAppPassword | string | Application-specific password for the sender account | | receiverEmail | string | Recipient's email address |

Returns: Promise<void>

await email(
  "gmail",
  process.env.EMAIL_USER,
  process.env.EMAIL_PASSWORD,
  userEmail
);

generateAuthToken(jwtSecret, options)

Generates a signed JWT authentication token with a unique nonce to prevent replay attacks.

Parameters:

| Parameter | Type | Description | |---|---|---| | jwtSecret | string | Secret key used to sign the JWT | | options.payload | Record<string, any> | Data to include in the token payload | | options.expiresIn | string (optional) | Token expiration time (default: "7d") | | options.algorithm | string (optional) | Signing algorithm (default: "HS256") |

Returns: Promise<string> — The signed JWT token.

const token = await generateAuthToken("your-secret-key", {
  payload: { userId: 123, role: "admin" },
  expiresIn: "1h",
});

Redis Compatibility

This package works with any Redis client that exposes standard get and set methods.

| Client | Support | |---|---| | @upstash/redis | Recommended for serverless and edge environments | | ioredis | Fully supported | | redis (node-redis) | Fully supported |


Repository

github.com/Shield-Ltd/Anti-Session-Hijack-NPM


Authors


License

MIT