Exemple
bun 1.3.14: Distinguish Bun.password.verify throwing PASSWORD_UNSUPPORTED_ALGORITHM for arbitrary non-empty strings and PASSWORD_INVALID_ENCODING for malformed payloads rather than returning false
Échantillon vérifié pour npm bun 1.3.14: Distinguish Bun.password.verify throwing PASSWORD_UNSUPPORTED_ALGORITHM for arbitrary non-empty strings and…
sha256:ea508eabfe658d9521fb07e9136a8dca4f4b4c634174c383130d61ce7394be4b
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 3
- Clés de signature qui l’ont compilé
- 3
Environnement déclaré
node linux x64 node node npm
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-17 |
| node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-18 |
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-09-07 |
Cas
HOW- Objectif
- Distinguish Bun.password.verify throwing PASSWORD_UNSUPPORTED_ALGORITHM for arbitrary non-empty strings and PASSWORD_INVALID_ENCODING for malformed payloads rather than returning false
- Paquets
- Symboles
-
- Bun.password.verify
- Bun.password.hash
- Environnement
- node
- Créé
- 2026-08-17T03:15:51Z
Contrat
- Bun.password.verify throws an Error with code PASSWORD_UNSUPPORTED_ALGORITHM for arbitrary non-empty hash strings and PASSWORD_INVALID_ENCODING for malformed prefixes rather than returning false, while an empty string hash returns false.
- Bun.password.verify returns true for matching credentials and false for mismatched passwords when provided valid argon2id or bcrypt hashes.
- Bun.password.hash with an unsupported algorithm name throws a TypeError with code ERR_INVALID_ARG_TYPE listing supported algorithms.
- Bun.password.hash with out-of-range bcrypt cost rounds throws a TypeError with code ERR_INVALID_ARG_TYPE.
Fichiers
- NOTES.md
- csx.json
- package-lock.json
- package.json
- test/contract.mjs
- test/password_contract.mjs
Code source
# Notes
A search for existing solutions returned three samples for `bun`:
- `sha256:40a4371c6d2dc2464ed3ae6583e5ff73d0c28d56ad8ae4692a8d336a2c8fb9cb` (Isolate runtime and test preload scopes in bunfig.toml and configure custom config paths via CLI flags rather than environment variables in Bun)
- `sha256:dd9bb7f87f4695d185f0b94b6a56e486798d752f360c2aca719604f3bf51837f` (Distinguish bun build sourcemap defaulting to linked external map files rather than inline data URLs across minor versions)
- `sha256:62e943e4ef56e467cea25ec706d25278ef193cf39bc0c7597ce46891c359411e` (Differentiate TypedArray instances from plain index-keyed objects in Bun.deepEquals following the v1.2.2 structural comparison fix)
None of these cover `Bun.password.verify` or password hashing error semantics.
When authentication routines pass corrupted, legacy plain-text, or unparseable hash tokens to `Bun.password.verify`, execution fails loudly with an uncaught `PASSWORD_UNSUPPORTED_ALGORITHM` exception instead of evaluating to `false`.
{"case":{"believed":"Bun.password.verify returns false whenever a candidate password fails to verify against an unparseable, legacy, or corrupted hash string.","caseId":"case:sha256:2582eb9cd9b92c9b1dd56423e790d89d9504a31dcc5d34e0ce6f211a97a910c2","contract":["Bun.password.verify throws an Error with code PASSWORD_UNSUPPORTED_ALGORITHM for arbitrary non-empty hash strings and PASSWORD_INVALID_ENCODING for malformed prefixes rather than returning false, while an empty string hash returns false.","Bun.password.verify returns true for matching credentials and false for mismatched passwords when provided valid argon2id or bcrypt hashes.","Bun.password.hash with an unsupported algorithm name throws a TypeError with code ERR_INVALID_ARG_TYPE listing supported algorithms.","Bun.password.hash with out-of-range bcrypt cost rounds throws a TypeError with code ERR_INVALID_ARG_TYPE."],"goal":"Distinguish Bun.password.verify throwing PASSWORD_UNSUPPORTED_ALGORITHM for arbitrary non-empty strings and PASSWORD_INVALID_ENCODING for malformed payloads rather than returning false","kind":"HOW","packages":["pkg:npm/bun@1.3.14"],"schemaVersion":1,"symbols":["Bun.password.verify","Bun.password.hash"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"node","os":"linux","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/bun@1.3.14"],"schemaVersion":1,"symbols":["Bun.password.verify","Bun.password.hash"],"verifierAdapter":"node-typescript@1"}
{
"name": "npm-bun-d2",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "npm-bun-d2",
"version": "1.0.0",
"dependencies": {
"bun": "1.3.14"
}
},
"node_modules/@oven/bun-darwin-aarch64": {
"version": "1.3.14",
"resolved": "https://registry.npmjs.org/@oven/bun-darwin-aarch64/-/bun-darwin-aarch64-1.3.14.tgz",
"integrity": "sha512-Omj20SuiHBOUjUBIyqtkNjSUIjOtEOJwmbix/ZyFH4BaQ6OZTaaRWIR4TjHVz0yadHgli6lLTiAh1uarnvD49A==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"darwin"
]
},
"node_modules/@oven/bun-darwin-x64": {
"version": "1.3.14",
"resolved": "https://registry.npmjs.org/@oven/bun-darwin-x64/-/bun-darwin-x64-1.3.14.tgz",
"integrity": "sha512-FFj3QdU/OhlDyZOJ8CWfN5eWLpRlT4qjZg7lMQi7jA6GuoY5ajlO1zWLP/MuHYRSbXQUvV52RejNi8DVnAp13w==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"darwin"
]
},
"node_modules/@oven/bun-darwin-x64-baseline": {
"version": "1.3.14",
"resolved": "https://registry.npmjs.org/@oven/bun-darwin-x64-baseline/-/bun-darwin-x64-baseline-1.3.14.tgz",
"integrity": "sha512-OSfsTZstc898HHElhU4NccaBGOSSDn5VfahiVTnidZ9B/+wb7WTyfZJaBeJcfjwJ9H2W9uTh2TGtl3UfcXgV9g==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"darwin"
]
},
"node_modules/@oven/bun-freebsd-aarch64": {
"version": "1.3.14",
"resolved": "https://registry.npmjs.org/@oven/bun-freebsd-aarch64/-/bun-freebsd-aarch64-1.3.14.tgz",
"integrity": "sha512-LIKrXaFxAHybVO5Pf+9XP2FHUj/5APvXTUKk9dqHm5iFz4oH+W24cmhjkJirNujh9hKeTyrpWSe3no9JZKowIw==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"freebsd"
]
},
"node_modules/@oven/bun-freebsd-x64": {
"version": "1.3.14",
"resolved": "https://registry.npmjs.org/@oven/bun-freebsd-x64/-/bun-freebsd-x64-1.3.14.tgz",
"integrity": "sha512-uwD+fGUH1ADpIF3B1U2jWzzb20QwRLZfj5QZ28GUCGrAJ/nTmWrD6YYGsblCY1wuhldRez3lU40AyuvSCyLYmw==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"freebsd"
]
},
"node_modules/@oven/bun-linux-aarch64": {
"version": "1.3.14",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64/-/bun-linux-aarch64-1.3.14.tgz",
"integrity": "sha512-X5SsPZHs+iYO8R/efIcRtc7gT2Q2DgPfliCxEkx4cXBumwkw0c/EsHMNwH3EgGpCDaZ7IYVPhpCG/xBOQHEwZw==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@oven/bun-linux-aarch64-android": {
"version": "1.3.14",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64-android/-/bun-linux-aarch64-android-1.3.14.tgz",
"integrity": "sha512-y4kq5b85lsrmFb9Xvi4w9mA5IEFJkLMrSmYn06q24KjL9rUWDWO3VFZEtteZxUN5+ec3Zm5S8OnJw1umaCbVjA==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"android"
]
},
"node_modules/@oven/bun-linux-aarch64-musl": {
"version": "1.3.14",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64-musl/-/bun-linux-aarch64-musl-1.3.14.tgz",
"integrity": "sha512-jmqOA92Cd1NL/1XBd4bFkJLxQ86K0RW7ohxS2qzzAvuitO4JiIxjjTeCspoU44zCozH72HpfZfUE2On31OjnWA==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@oven/bun-linux-x64": {
"version": "1.3.14",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-x64/-/bun-linux-x64-1.3.14.tgz",
"integrity": "sha512-7OVTAKvwfPmSbIV1HpdOoVVx5VRc427GuPPne93N6vk4eQBPId9nXmZDh9/zGaKPdbVjVtQSZafWQoUjx38Utw==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@oven/bun-linux-x64-android": {
"version": "1.3.14",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-android/-/bun-linux-x64-android-1.3.14.tgz",
"integrity": "sha512-qe9e1d+3VAEU7nAA2ol9Jvmy/o99PVMSgZhHn7Q/9O3YcDrfEqyQ8zm4zoe5qTEo8HZH0dN03Le0Ys2eQPs7eg==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"android"
]
},
"node_modules/@oven/bun-linux-x64-baseline": {
"version": "1.3.14",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-baseline/-/bun-linux-x64-baseline-1.3.14.tgz",
"integrity": "sha512-q/8EdOC0yUE8FPeoOVq8/Pw5I9/tJaYmUfO/uDUAREx8IUnOJH1RJ5A3BjFqre8pvJoiZA9AovPJq5FnNNjSxA==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@oven/bun-linux-x64-musl": {
"version": "1.3.14",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-musl/-/bun-linux-x64-musl-1.3.14.tgz",
"integrity": "sha512-GBCB/k/sIqcr06eTNgg7g46qiUv35Jasx4XiccJ/n7RGqrE4RWUD/XJBbWFprVPjvqd59+QtSnS99XGqvftHfg==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@oven/bun-linux-x64-musl-baseline": {
"version": "1.3.14",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-musl-baseline/-/bun-linux-x64-musl-baseline-1.3.14.tgz",
"integrity": "sha512-n6iE71G4lQE4XkrZhQQcL5YUlxDbnq6nqV7zeQi33PMsLT/0kYE+RvHOtBWZ3w0wMdXZfINmp63hIb9ijUBGtw==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@oven/bun-windows-aarch64": {
"version": "1.3.14",
"resolved": "https://registry.npmjs.org/@oven/bun-windows-aarch64/-/bun-windows-aarch64-1.3.14.tgz",
"integrity": "sha512-T7s3x/BsVKQObGU6QDkZeI6wKynzqGbBH1yI77jrrj5siElclxr3DQrDIk8CV4G5/SJq2HHq4kpLyYY2DKCSmA==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"win32"
]
},
"node_modules/@oven/bun-windows-x64": {
"version": "1.3.14",
"resolved": "https://registry.npmjs.org/@oven/bun-windows-x64/-/bun-windows-x64-1.3.14.tgz",
"integrity": "sha512-mUFWL3BoYkNpjd8e9PqROiFF/1Xeotq20mABJsiQH62jM1g5zqWh4khw1RZ6bX8Q8fWvlPaxG1PjofkmjUi3vg==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"win32"
]
},
"node_modules/@oven/bun-windows-x64-baseline": {
"version": "1.3.14",
"resolved": "https://registry.npmjs.org/@oven/bun-windows-x64-baseline/-/bun-windows-x64-baseline-1.3.14.tgz",
"integrity": "sha512-uIjLUC1S9DWgICzuoMba7vurBJnBruE4S5CxnvmZkdqWVXRzx1Rgu636HoH+k0qeaQCFh3jeG3JQ1y6fRHv0sw==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"win32"
]
},
"node_modules/bun": {
"version": "1.3.14",
"resolved": "https://registry.npmjs.org/bun/-/bun-1.3.14.tgz",
"integrity": "sha512-aB6GVd42x1Y5ie1K16SF+oLGtgSkwX9hgoDdIW88pjvfTccU8F1vfpoOt34QLv0dZ1v3XimtaxPlZUG81Gx9Zg==",
"cpu": [
"arm64",
"x64"
],
"hasInstallScript": true,
"license": "MIT",
"os": [
"darwin",
"linux",
"android",
"freebsd",
"win32"
],
"bin": {
"bun": "bin/bun.exe",
"bunx": "bin/bunx.exe"
},
"optionalDependencies": {
"@oven/bun-darwin-aarch64": "1.3.14",
"@oven/bun-darwin-x64": "1.3.14",
"@oven/bun-darwin-x64-baseline": "1.3.14",
"@oven/bun-freebsd-aarch64": "1.3.14",
"@oven/bun-freebsd-x64": "1.3.14",
"@oven/bun-linux-aarch64": "1.3.14",
"@oven/bun-linux-aarch64-android": "1.3.14",
"@oven/bun-linux-aarch64-musl": "1.3.14",
"@oven/bun-linux-x64": "1.3.14",
"@oven/bun-linux-x64-android": "1.3.14",
"@oven/bun-linux-x64-baseline": "1.3.14",
"@oven/bun-linux-x64-musl": "1.3.14",
"@oven/bun-linux-x64-musl-baseline": "1.3.14",
"@oven/bun-windows-aarch64": "1.3.14",
"@oven/bun-windows-x64": "1.3.14",
"@oven/bun-windows-x64-baseline": "1.3.14"
}
}
}
}
{
"name": "npm-bun-d2",
"version": "1.0.0",
"type": "module",
"dependencies": {
"bun": "1.3.14"
}
}
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { createRequire } from "node:module";
import { spawnSync } from "node:child_process";
const require = createRequire(import.meta.url);
function isMuslLinux() {
if (process.platform !== "linux") return false;
if (fs.existsSync("/etc/alpine-release")) return true;
try {
return !process.report?.getReport?.().header?.glibcVersionRuntime;
} catch {
return false;
}
}
function platformBinaryPackages(platform, architecture, musl) {
const packageArchitecture = architecture === "arm64" ? "aarch64" : architecture;
if (platform === "linux" && musl) {
return packageArchitecture === "x64"
? ["@oven/bun-linux-x64-musl-baseline", "@oven/bun-linux-x64-musl"]
: [`@oven/bun-linux-${packageArchitecture}-musl`];
}
const packagePlatform = platform === "win32" ? "windows" : platform;
return [`@oven/bun-${packagePlatform}-${packageArchitecture}`];
}
function findBunBinary() {
const packagePath = require.resolve("bun/package.json");
const packageDirectory = path.dirname(packagePath);
const metadata = JSON.parse(fs.readFileSync(packagePath, "utf8"));
const musl = isMuslLinux();
const executable = process.platform === "win32" ? "bun.exe" : "bun";
const candidates = platformBinaryPackages(process.platform, process.arch, musl).map(
(packageName) =>
path.join(packageDirectory, "..", ...packageName.split("/"), "bin", executable),
);
// postinstall is disabled during verification. On Alpine, never fall back
// to the package-local wrapper or a glibc binary.
if (!musl) {
candidates.push(
path.join(packageDirectory, "bin", executable),
path.join(packageDirectory, "bin", "bun.exe"),
path.join(packageDirectory, metadata.bin?.bun ?? ""),
);
}
const binary = candidates.find((candidate) => candidate && fs.existsSync(candidate));
assert.ok(binary, "resolved bun package must contain a platform executable");
return binary;
}
assert.deepStrictEqual(platformBinaryPackages("linux", "x64", true), [
"@oven/bun-linux-x64-musl-baseline",
"@oven/bun-linux-x64-musl",
]);
const bunExecutablePath = findBunBinary();
// 2. Execute password verify and hash error contracts inside the Bun runtime
const passwordContractPath = path.join("test", "password_contract.mjs");
const passwordRunResult = spawnSync(bunExecutablePath, ["run", passwordContractPath], {
encoding: "utf-8",
});
assert.strictEqual(
passwordRunResult.status,
0,
`password_contract.mjs failed with exit code ${passwordRunResult.status}:\n${passwordRunResult.stderr}\n${passwordRunResult.stdout}`
);
assert.ok(
passwordRunResult.stdout.includes("PASSWORD_CONTRACT_OK"),
"password_contract.mjs must complete successfully with PASSWORD_CONTRACT_OK"
);
console.log("ALL_CONTRACTS_PASS");
import assert from "node:assert/strict";
// 1. Valid password verification returns true for matches and false for mismatches
const argonHash = await Bun.password.hash("secret_password", { algorithm: "argon2id" });
const bcryptHash = await Bun.password.hash("secret_password", { algorithm: "bcrypt" });
assert.strictEqual(await Bun.password.verify("secret_password", argonHash), true);
assert.strictEqual(await Bun.password.verify("wrong_password", argonHash), false);
assert.strictEqual(await Bun.password.verify("secret_password", bcryptHash), true);
assert.strictEqual(await Bun.password.verify("wrong_password", bcryptHash), false);
// 2. Empty string hash returns false rather than throwing
assert.strictEqual(await Bun.password.verify("secret_password", ""), false);
// 3. Unrecognized or non-modular string formats throw PASSWORD_UNSUPPORTED_ALGORITHM Error instead of returning false
for (const invalidHash of [
"plain_password_text",
"c4ca4238a0b923820dcc509a6f75849b",
"sha256$bad_hash_format",
"token_xyz_98765"
]) {
let threw = false;
try {
await Bun.password.verify("secret_password", invalidHash);
} catch (err) {
threw = true;
assert.strictEqual(err.name, "Error");
assert.strictEqual(err.code, "PASSWORD_UNSUPPORTED_ALGORITHM");
assert.strictEqual(err.message, 'Password verification failed with error "UnsupportedAlgorithm"');
}
assert.strictEqual(threw, true, `Expected PASSWORD_UNSUPPORTED_ALGORITHM for ${invalidHash}`);
}
// 4. Recognized algorithm prefix with invalid payload encoding throws PASSWORD_INVALID_ENCODING
for (const malformedHash of [
"$argon2id$invalid_argon2_payload",
"$2b$10$invalid_bcrypt_payload_char!"
]) {
let threw = false;
try {
await Bun.password.verify("secret_password", malformedHash);
} catch (err) {
threw = true;
assert.strictEqual(err.name, "Error");
assert.strictEqual(err.code, "PASSWORD_INVALID_ENCODING");
assert.strictEqual(err.message, 'Password verification failed with error "InvalidEncoding"');
}
assert.strictEqual(threw, true, `Expected PASSWORD_INVALID_ENCODING for ${malformedHash}`);
}
// 5. Bun.password.hash with unsupported algorithm throws TypeError ERR_INVALID_ARG_TYPE listing supported algorithms
let algoError = null;
try {
await Bun.password.hash("secret_password", { algorithm: "sha512" });
} catch (err) {
algoError = err;
}
assert.ok(algoError instanceof TypeError);
assert.strictEqual(algoError.code, "ERR_INVALID_ARG_TYPE");
assert.ok(algoError.message.includes('expected one of: "bcrypt", "argon2id", "argon2d", "argon2i"'));
// 6. Bun.password.hash with out-of-range bcrypt cost throws TypeError ERR_INVALID_ARG_TYPE
let costError = null;
try {
await Bun.password.hash("secret_password", { algorithm: "bcrypt", cost: 3 });
} catch (err) {
costError = err;
}
assert.ok(costError instanceof TypeError);
assert.strictEqual(costError.code, "ERR_INVALID_ARG_TYPE");
assert.strictEqual(costError.message, "Rounds must be between 4 and 31");
console.log("PASSWORD_CONTRACT_OK");