
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600Γ Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600Γ faster than humans.
hashed-device-fingerprint-js
Advanced tools
A lightweight library for generating hashed fingerprints based on selected device data.
+-------------------+------------------------+
| https://yoursite.com |
+-------------------+------------------------+
| | |
+-----------------+-----------------+-----------------+
| (DEVICE A) | (DEVICE B) | (DEVICE C) |
| device-specific | device-specific | device-specific |
| fingerprint | fingerprint | fingerprint |
+-----------------+-----------------+-----------------+
A lightweight JavaScript/TypeScript package that generates device-specific hashed fingerprints for devices in both browser and server environments. The library allows customization of what data is included in the fingerprint, with options for saving the hash in cookies, passing headers for server-side use, and providing the user's IP directly.
hashed-device-fingerprint-js
generates fingerprints using device data like [screenResolution, platform, concurrency, userIP]
by default, with userAgent
and language
disabled. You can add customData (e.g., userID)
to make the array [screenResolution, platform, concurrency, userIP, customData]
(e.g. [1920x1080, Windows, 4 cores, 203.0.113.45, user-12345]
), ensures a consistent generated same hash across browsers on the same device.
Win32
or Linux
)navigator
and screen
properties.require
(CommonJS) and import
(ES Modules).Install the package using npm:
npm install hashed-device-fingerprint-js
Install the package using yarn:
yarn add hashed-device-fingerprint-js
By default, all options are enabled (userAgent
and language
disabled). The library generates a fingerprint hash using all available device data and automatically fetches the user's IP address.
import { generateHashedFingerprint } from 'hashed-device-fingerprint-js';
generateHashedFingerprint()
.then(hash => console.log('Fingerprint Hash:', hash))
.catch(error => console.error('Error:', error));
In a Server environment, pass HTTP headers to generate a fingerprint. Use the environment option to specify the server-side environment.
const { generateHashedFingerprint } = require('hashed-device-fingerprint-js');
// import { generateHashedFingerprint } from 'hashed-device-fingerprint-js';
// Example HTTP headers
const headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
'accept-language': 'en-US,en;q=0.9',
'x-forwarded-for': '203.0.113.45',
};
generateHashedFingerprint({
environment: 'server',
headers,
})
.then(hash => console.log('Fingerprint Hash:', hash))
.catch(error => console.error('Error:', error));
Customize the behavior by passing an options object:
generateHashedFingerprint({
useUserAgent: false, // Exclude the user agent (default: true)
useLanguage: false, // Exclude the browser language
useScreenResolution: true, // Include screen resolution (default: true)
usePlatform: true, // Include platform information (default: true)
useConcurrency: true, // Include logical processors (default: true)
useIP: true, // Fetch and include the user's IP (default: true)
userIP: '203.0.113.45', // Provide IP manually (overrides API fetch)
saveToCookie: false, // Do not save the hash in a cookie (default: true)
cookieExpiryDays: 10 // Cookie expiry in days (default: 7)
})
.then(hash => console.log('Custom Fingerprint Hash:', hash))
.catch(error => console.error('Error:', error));
The IP address is included in the fingerprint based on these rules:
userIP
is provided, it is used directly.userIP
is null and useIP is true, the IP is fetched using an external API (https://api64.ipify.org).generateHashedFingerprint({ saveToCookie: true })
.then(hash => console.log('Fingerprint saved in cookie:', hash))
.catch(error => console.error('Error:', error));
generateHashedFingerprint({ useIP: false })
.then(hash => console.log('Fingerprint without IP:', hash))
.catch(error => console.error('Error:', error));
generateHashedFingerprint({ userIP: '203.0.113.45' })
.then(hash => console.log('Fingerprint with manual IP:', hash))
.catch(error => console.error('Error:', error));
const { generateHashedFingerprint } = require('hashed-device-fingerprint-js');
// Basic route
app.get('/hash', async (req, res) => {
// Define headers for fingerprint generation
const headers = {
'user-agent': req.headers['user-agent'] || 'Unknown',
'accept-language': req.headers['accept-language'] || 'Unknown',
'x-forwarded-for': req.headers['x-forwarded-for'] || req.connection.remoteAddress || 'Unknown',
};
try {
// Generate the fingerprint hash
const hash = await generateHashedFingerprint({
environment: 'server',
headers,
});
// Log the hash
console.log('Generated Hash:', hash);
// Send the hash as the response
res.send({ hash });
} catch (error) {
// Handle errors
console.error('Error generating fingerprint:', error);
res.status(500).send({ error: 'Failed to generate fingerprint' });
}
});
The package includes TypeScript type definitions for all options and methods. Hereβs a quick example:
import { generateHashedFingerprint, FingerprintOptions } from 'hashed-device-fingerprint-js';
const options: Partial<FingerprintOptions> = {
saveToCookie: false,
useUserAgent: true,
useIP: true
};
generateHashedFingerprint(options)
.then(hash => console.log('Typed Fingerprint Hash:', hash))
.catch(error => console.error('Error:', error));
Errors are thrown as JavaScript Error objects. Use a try-catch block or .catch() to handle them safely:
generateHashedFingerprint()
.then(hash => console.log('Fingerprint Hash:', hash))
.catch(error => {
if (error instanceof Error) {
console.error('Error:', error.message);
} else {
console.error('Unknown Error:', error);
}
});
saveToCookie
boolean
true
cookieExpiryDays
number
7
useUserAgent
boolean
false
useLanguage
boolean
false
useScreenResolution
boolean
true
usePlatform
boolean
true
useConcurrency
boolean
true
useIP
boolean
true
userIP
string
null
headers
Record<string, string[]>
{}
environment
'browser' | 'server'
Auto-detected
'browser'
or 'server'
).customData
string
null
UUID
or user ID
).This package is licensed under the MIT License.
git checkout -b feature-name
.git commit -m 'Add feature'
.git push origin feature-name
.If you encounter any issues or have questions, feel free to open an issue on Repo Issues.
Happy coding! π
FAQs
A lightweight library for generating hashed fingerprints based on selected device data.
The npm package hashed-device-fingerprint-js receives a total of 2 weekly downloads. As such, hashed-device-fingerprint-js popularity was classified as not popular.
We found that hashed-device-fingerprint-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600Γ faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.