Express Server-Side Fingerprinting Middleware

1.2.2 · active · verified Wed Apr 22

express-fingerprint is an Express middleware designed for passive, server-side client fingerprinting. It allows developers to identify incoming requests based on characteristics observable in HTTP request contents without executing any client-side code. The current stable version is `1.2.2`. The library processes information such as the User-Agent string, HTTP Accept headers, and GeoIP data (if available) to generate a unique hash and a detailed component breakdown for each request, accessible via `req.fingerprint`. Releases are infrequent but have recently addressed critical import issues and added TypeScript support. A key differentiator is its strict adherence to server-side data collection, prioritizing privacy by avoiding client-side scripts, and offering extensibility through custom parameter functions to gather additional request-specific data.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `express-fingerprint` as middleware, including default and custom parameters, and how to access the generated fingerprint object on the `req` object for every incoming request.

import express from 'express';
import Fingerprint from 'express-fingerprint';

const app = express();

app.use(Fingerprint({
    parameters: [
        // Default parameters
        Fingerprint.useragent,
        Fingerprint.acceptHeaders,
        Fingerprint.geoip,

        // Custom additional parameters
        function(next) {
            // Example: Add a custom header value
            const customHeader = this.req.headers['x-custom-id'] || 'N/A';
            next(null, {
                'customHeaderId': customHeader
            });
        },
        function(next) {
            // Example: Asynchronously fetch and add data
            setTimeout(() => {
                next(null, {
                    'customAsyncParam': 'asyncValue'
                });
            }, 50);
        }
    ]
}));

app.get('/', (req, res) => {
    // The fingerprint object is available on req.fingerprint
    console.log('Request Fingerprint:', req.fingerprint);
    res.json({
        message: 'Fingerprint collected!',
        fingerprint: req.fingerprint
    });
});

app.listen(3000, () => {
    console.log('Server listening on http://localhost:3000');
});

view raw JSON →