![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
cybertoken
Advanced tools
A token format inspired by GitHub's new API token format. Think of it as a standardized password format with some handy properties. Intended for API token and password generation.
GitHub changed their token format a while back and explained the reasons in an insightful blog post1.
tl;dr:
_
instead of -
is better for double-click text selection: abc_def
vs abc-def
.These properties make this token format suitable for things like API tokens, which is what cybertoken is.
Install:
npm install cybertoken
Also available on JSR:
npx jsr add @cybertoken/cybertoken
import { createTokenGenerator } from "cybertoken";
const apiTokenGenerator = createTokenGenerator({
prefixWithoutUnderscore: "contoso",
});
const token = apiTokenGenerator.generateToken();
// Securely hash `token` and save it in your database. Return `token` to the user once.
console.log(token);
// contoso_IvN2xEuHUDjQ3PNQgZkILWc7GUxpmThDD410NQxJalD5GjY
You can also use cybertokens as passwords. If you use GitHub, you can set up a custom secret scanning pattern that will prevent anyone from pushing anything that looks like a cybertoken that your org uses.
For example, use this pattern for Cybertokens with the prefix contosopass
:
contosopass_[0-9A-Za-z]{10,}
The npm package also offers a command-line utility to generate tokens.
npm install -g cybertoken
Usage:
cybertoken <prefix>
# example:
cybertoken test
test_KOK5QxQr4GBGk97X8Ij5ZnyZO24kMIEiW1LdUYIqEj7A5Nv
You can also provide the token prefix via an env variable:
CYBERTOKEN_PREFIX=foo cybertoken
To make thing easier, you can put this in your .bashrc
:
echo "export CYBERTOKEN_PREFIX=foo" >> ~/.bashrc
...and now you can just use cybertoken
!
This is what a cybertoken consists of:
prefix base62(n-bytes + v + crc32(n-bytes + v))
┌────────┐ ┌──────────────────────────────────────────────┐
myapitoken_161YNJQOaoFoWLaoXeMVHYyrSLhGPOjSBYBtxY6V3GqFFZKV
Explanation:
n-bytes
are n
random bytes, but at least 21 (default: 22), generated by a cryptographically secure random sourcev
is a single byte containing the version of the cybertoken format used (currently, only 0x00
)0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
GitHub's blog post covering this: https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats ↩
More info in Base62: https://en.wikipedia.org/wiki/Base62 ↩
FAQs
A token format for APIs inspired by the GitHub's API token format.
We found that cybertoken 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.