@blamejs/pki 0.4.8 → 0.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/lib/constants.js +13 -0
- package/lib/webauthn.js +94 -7
- package/package.json +1 -1
- package/sbom.cdx.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,19 @@ All notable changes to `@blamejs/pki` are documented here. The format
|
|
|
4
4
|
follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); this
|
|
5
5
|
project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## v0.4.9 — 2026-08-09
|
|
8
|
+
|
|
9
|
+
A WebAuthn compound attestation now verifies -- every nested statement must pass, so a wrapper cannot launder a failed attestation behind one that succeeds -- and the certificate chains an attestation carries are bounded by count, not only by size.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- pki.webauthn.verify verifies the compound attestation format, which it previously refused as unsupported. Every nested statement must verify for the attestation to verify -- the specification leaves the threshold to relying-party policy, and this is the fail-closed reading of it. The result reports attestation type Compound and carries each element's own verdict, attestation type and certificate chain in order, so a caller applies its own policy to the parts rather than to a merged verdict that could overstate or understate any of them. The combined trust path is empty by construction: several elements produce several independent chains, and presenting them as one ordered path would misrepresent what was validated.
|
|
14
|
+
- The nested statements are held to the format's own syntax: at least two of them, each exactly a format identifier and a statement, each identifier matched case-sensitively against the supported set, and none of them compound -- the specification spells that exclusion out, so nesting is impossible by construction rather than by a depth counter. Which CBOR shape a statement takes is now a property of the format rather than a fixed rule, so accommodating the array-shaped compound statement leaves every other format's contract unchanged, and a compound presented in the older map shape is refused.
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- The number of certificates an attestation may carry is now bounded. Both the attestation statement's certificate array and a JSON Web Signature certificate header capped the size of each certificate but not how many there were, so a statement could present thousands of small certificates and each one cost a parse and, downstream, a full path validation -- work far out of proportion to the bytes on the wire. A single bound now covers every place a chain arrives, set well above any real attestation chain.
|
|
19
|
+
|
|
7
20
|
## v0.4.8 — 2026-08-08
|
|
8
21
|
|
|
9
22
|
A stored android-safetynet WebAuthn attestation can be re-verified in full -- the signature, the registration binding, and the certificate chain -- behind an opt-in and against a root the caller supplies.
|
package/lib/constants.js
CHANGED
|
@@ -297,6 +297,19 @@ var LIMITS = {
|
|
|
297
297
|
// terminates but exhausts memory. This matches PATH_MAX_CERTS: a chain longer than the path
|
|
298
298
|
// validator will ever accept has nothing to offer, so refusing it at the decoder is free.
|
|
299
299
|
TLS_CERT_MAX_ENTRIES: 100,
|
|
300
|
+
// The most nested statements a WebAuthn compound attestation (sec. 8.9) may carry. The syntax
|
|
301
|
+
// says "2*" -- unbounded -- so this is a resource bound this toolkit chooses, NOT a spec MUST.
|
|
302
|
+
// The CBOR parse caps bound the decode; they do not bound the crypto, and each element costs a
|
|
303
|
+
// signature verification plus, for some formats, a full certificate-path validation. Seven
|
|
304
|
+
// non-compound formats are registered, so a conforming statement carrying one of each is 7.
|
|
305
|
+
WEBAUTHN_COMPOUND_MAX_STATEMENTS: 16,
|
|
306
|
+
// The most certificates a WebAuthn attestation chain may carry, in an attStmt x5c array or a JWS
|
|
307
|
+
// x5c header. A real attestation chain is one to four; the byte ceiling on a single entry does
|
|
308
|
+
// not bound the COUNT, so an array of thousands of small certificates is an unbounded parse and
|
|
309
|
+
// signature-check fanout (CWE-770) that terminates but costs far more CPU than wire. This is a
|
|
310
|
+
// resource bound this toolkit chooses -- no specification states it -- and it is far tighter than
|
|
311
|
+
// PATH_MAX_CERTS because an attestation chain is not a general PKI path.
|
|
312
|
+
WEBAUTHN_X5C_MAX_CERTS: 10,
|
|
300
313
|
// A WebAuthn android-safetynet attestation statement carries the SafetyNet response as a JWS
|
|
301
314
|
// compact serialization: two small JSON objects plus a signature, with the certificate chain
|
|
302
315
|
// inline in the header. Real ones run a few kilobytes. The cap bounds the text decode before the
|
package/lib/webauthn.js
CHANGED
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
* @intro Trust evaluation of a W3C WebAuthn (Level 3) / passkey attestation: parse
|
|
9
9
|
* the attestation object + authenticatorData, decode the COSE credential public
|
|
10
10
|
* key, and verify each defined attestation-statement format (packed, tpm,
|
|
11
|
-
* android-key, apple, fido-u2f, none, and android-safetynet behind an
|
|
12
|
-
* the attestation-statement signature and each format's structural
|
|
11
|
+
* android-key, apple, fido-u2f, none, compound, and android-safetynet behind an
|
|
12
|
+
* opt-in) -- the attestation-statement signature and each format's structural
|
|
13
|
+
* bindings. The attestation CBOR is decoded by the strict,
|
|
13
14
|
* fail-closed `pki.cbor` codec (WebAuthn keys are CTAP2-canonical), the signature by
|
|
14
15
|
* `pki.webcrypto`. Chaining the returned x5c trust path to a caller-pinned root via
|
|
15
16
|
* `pki.path.validate` is the caller's step: this module verifies the statement, not
|
|
@@ -327,11 +328,16 @@ function parseAttestationObject(bytes) {
|
|
|
327
328
|
// (WebAuthn 6.5.4); an extra top-level key is a non-canonical envelope, rejected.
|
|
328
329
|
if (root.children.length !== 3 || !fmtN || !attStmtN || !authDataN) throw _err("webauthn/bad-attestation-object", "the attestation object must be exactly { fmt, attStmt, authData }");
|
|
329
330
|
if (fmtN.majorType !== 3) throw _err("webauthn/bad-attestation-object", "attestation object 'fmt' must be a text string");
|
|
330
|
-
// attStmt is the attestation statement, a CBOR map keyed by field name (WebAuthn 6.5.4)
|
|
331
|
-
//
|
|
332
|
-
//
|
|
333
|
-
// nodes, not { key, value } pairs)
|
|
334
|
-
|
|
331
|
+
// attStmt is the attestation statement, a CBOR map keyed by field name (WebAuthn 6.5.4) for every
|
|
332
|
+
// format but one: sec. 8.9 gives compound an ARRAY of nested statements. Which shape a format
|
|
333
|
+
// takes is a registry row, not a branch, so adding a format cannot silently widen the envelope
|
|
334
|
+
// for the others -- a non-map value (whose children are single nodes, not { key, value } pairs)
|
|
335
|
+
// must never reach the per-field statement walk of a format that expects a map.
|
|
336
|
+
var wantMajor = ATT_STMT_MAJOR[cbor.read.textString(fmtN)];
|
|
337
|
+
if (wantMajor === undefined) wantMajor = 5;
|
|
338
|
+
if (attStmtN.majorType !== wantMajor) {
|
|
339
|
+
throw _err("webauthn/bad-attestation-object", "attestation object 'attStmt' must be a CBOR " + (wantMajor === 4 ? "array" : "map") + " for format " + JSON.stringify(cbor.read.textString(fmtN)));
|
|
340
|
+
}
|
|
335
341
|
if (authDataN.majorType !== 2) throw _err("webauthn/bad-attestation-object", "attestation object 'authData' must be a byte string");
|
|
336
342
|
var authDataBytes = cbor.read.byteString(authDataN);
|
|
337
343
|
return {
|
|
@@ -377,9 +383,24 @@ function _requireAttShape(attStmt, allowed, required) {
|
|
|
377
383
|
Object.keys(have).forEach(function (k) { if (allowed.indexOf(k) === -1) throw _err("webauthn/bad-att-stmt", "the attestation statement carries an unexpected field '" + k + "'"); });
|
|
378
384
|
required.forEach(function (k) { if (!have[k]) throw _err("webauthn/bad-att-stmt", "the attestation statement is missing the '" + k + "' field"); });
|
|
379
385
|
}
|
|
386
|
+
// The CBOR major type each format's attStmt takes. Every format uses a map (5) except compound,
|
|
387
|
+
// whose sec. 8.9 syntax is an array of nested statements. A data row rather than a branch, so a
|
|
388
|
+
// future format declares its shape here instead of loosening the shared envelope check.
|
|
389
|
+
var ATT_STMT_MAJOR = { compound: 4 };
|
|
390
|
+
|
|
391
|
+
// One bound for every attestation certificate chain, wherever it arrives from -- an attStmt x5c
|
|
392
|
+
// array or a JWS x5c header. Capping the bytes of a single entry does not bound the COUNT, and the
|
|
393
|
+
// cost of an entry is a DER parse plus, downstream, a signature check or a path validation. Kept in
|
|
394
|
+
// one place so a new chain-bearing format cannot reintroduce the unbounded fanout.
|
|
395
|
+
function _requireX5cCount(n) {
|
|
396
|
+
if (n > constants.LIMITS.WEBAUTHN_X5C_MAX_CERTS) {
|
|
397
|
+
throw _err("webauthn/bad-att-stmt", "an attestation certificate chain carries " + n + " certificates, above the " + constants.LIMITS.WEBAUTHN_X5C_MAX_CERTS + " this toolkit will parse");
|
|
398
|
+
}
|
|
399
|
+
}
|
|
380
400
|
function _readX5c(attStmt) {
|
|
381
401
|
var x5cN = cbor.read.mapGet(attStmt, "x5c");
|
|
382
402
|
if (!x5cN || x5cN.majorType !== 4 || !x5cN.children || !x5cN.children.length) throw _err("webauthn/bad-att-stmt", "x5c must be a non-empty array of certificates");
|
|
403
|
+
_requireX5cCount(x5cN.children.length);
|
|
383
404
|
return x5cN.children.map(function (c) {
|
|
384
405
|
var der;
|
|
385
406
|
try { der = cbor.read.byteString(c); } catch (e) { throw _err("webauthn/bad-att-stmt", "an x5c entry must be a byte string", e); }
|
|
@@ -572,6 +593,7 @@ var VERIFIERS = {
|
|
|
572
593
|
if (!Array.isArray(header.x5c) || header.x5c.length === 0) {
|
|
573
594
|
throw _err("webauthn/bad-att-stmt", "the android-safetynet JWS header carries no x5c certificate chain (RFC 7515 sec. 4.1.6)");
|
|
574
595
|
}
|
|
596
|
+
_requireX5cCount(header.x5c.length);
|
|
575
597
|
// x5c entries are STANDARD base64 (RFC 7515 sec. 4.1.6), not base64url like the segments.
|
|
576
598
|
var chain = header.x5c.map(function (entry, i) {
|
|
577
599
|
if (typeof entry !== "string") throw _err("webauthn/bad-att-stmt", "the android-safetynet x5c entry " + i + " is not a string");
|
|
@@ -636,6 +658,71 @@ var VERIFIERS = {
|
|
|
636
658
|
});
|
|
637
659
|
},
|
|
638
660
|
|
|
661
|
+
// compound (WebAuthn 8.9): the attStmt is an ARRAY of nested attestation statements, each
|
|
662
|
+
// verified over the SAME authenticatorData and clientDataHash as the outer object. sec. 8.9
|
|
663
|
+
// leaves the acceptance threshold to relying-party policy ("if validation fails for one or more
|
|
664
|
+
// subStmt, decide the appropriate result based on RP policy"); this toolkit's policy is
|
|
665
|
+
// fail-closed -- EVERY element must verify, because accepting a compound whose strong element
|
|
666
|
+
// failed and whose `none` element passed would let a wrapper launder a failed attestation.
|
|
667
|
+
compound: function (att, clientDataHash, opts) {
|
|
668
|
+
var kids = att.attStmt.children || [];
|
|
669
|
+
// sec. 8.9 syntax `2*`: at least two nested statements, or it is not a compound.
|
|
670
|
+
if (kids.length < 2) throw _err("webauthn/bad-att-stmt", "a compound attestation statement must carry at least two nested statements (WebAuthn 8.9)");
|
|
671
|
+
// Not a spec rule: a resource bound this toolkit chooses. The CBOR caps bound the PARSE; they
|
|
672
|
+
// do not bound the crypto, and each element costs a signature verify plus, for some formats, a
|
|
673
|
+
// certificate-chain path validation.
|
|
674
|
+
if (kids.length > constants.LIMITS.WEBAUTHN_COMPOUND_MAX_STATEMENTS) {
|
|
675
|
+
throw _err("webauthn/bad-att-stmt", "a compound attestation statement carries " + kids.length + " nested statements, above the " + constants.LIMITS.WEBAUTHN_COMPOUND_MAX_STATEMENTS + " this toolkit will verify");
|
|
676
|
+
}
|
|
677
|
+
var elements = kids.map(function (el, i) {
|
|
678
|
+
// sec. 8.9: nonCompoundAttStmt = { $$attStmtType } -- each element is exactly { fmt, attStmt }.
|
|
679
|
+
if (!el || el.majorType !== 5) throw _err("webauthn/bad-att-stmt", "compound element " + i + " must be a CBOR map { fmt, attStmt } (WebAuthn 8.9)");
|
|
680
|
+
var fN = cbor.read.mapGet(el, "fmt"), sN = cbor.read.mapGet(el, "attStmt");
|
|
681
|
+
if (el.children.length !== 2 || !fN || !sN) throw _err("webauthn/bad-att-stmt", "compound element " + i + " must be exactly { fmt, attStmt } (WebAuthn 8.9)");
|
|
682
|
+
if (fN.majorType !== 3) throw _err("webauthn/bad-att-stmt", "compound element " + i + " 'fmt' must be a text string");
|
|
683
|
+
var f = cbor.read.textString(fN);
|
|
684
|
+
// sec. 8.9 spells the element type `.ne "compound"`: nesting is forbidden by the syntax
|
|
685
|
+
// itself, which is what fixes the evaluation depth at one. No depth parameter is needed --
|
|
686
|
+
// and adding one would imply a nesting this format does not have.
|
|
687
|
+
if (f === "compound") throw _err("webauthn/bad-att-stmt", "a compound attestation statement must not nest another compound (WebAuthn 8.9)");
|
|
688
|
+
// sec. 8.1: identifiers match case-sensitively, which the registry lookup already is.
|
|
689
|
+
var v = VERIFIERS[f];
|
|
690
|
+
if (!v) throw _err("webauthn/unsupported-format", "compound element " + i + " uses unsupported attestation statement format '" + f + "'");
|
|
691
|
+
var wantMajor = ATT_STMT_MAJOR[f] === undefined ? 5 : ATT_STMT_MAJOR[f];
|
|
692
|
+
if (sN.majorType !== wantMajor) throw _err("webauthn/bad-att-stmt", "compound element " + i + " 'attStmt' has the wrong CBOR shape for format '" + f + "'");
|
|
693
|
+
// Each element verifies against the OUTER authenticatorData: sec. 8.9 passes the same
|
|
694
|
+
// verification-procedure inputs down, so an element cannot bind a different credential.
|
|
695
|
+
return { fmt: f, index: i, att: { fmt: f, attStmt: sN, authData: att.authData, authDataBytes: att.authDataBytes } };
|
|
696
|
+
});
|
|
697
|
+
// Sequential, not Promise.all: a compound may hold many elements, and each can cost a
|
|
698
|
+
// signature verify plus a full path validation. Fanning them out concurrently would turn one
|
|
699
|
+
// attestation into a burst of crypto work.
|
|
700
|
+
var out = [];
|
|
701
|
+
return elements.reduce(function (p, e) {
|
|
702
|
+
return p.then(function () {
|
|
703
|
+
// The verifier is CALLED inside the promise chain, not evaluated as an argument to
|
|
704
|
+
// Promise.resolve: most arms do their structural checks synchronously, so an argument-
|
|
705
|
+
// position call would let those throws escape the handler below and reach the caller
|
|
706
|
+
// bare -- the same failure reported with the element's context or without it, depending
|
|
707
|
+
// only on whether it happened before or after the first await.
|
|
708
|
+
return Promise.resolve().then(function () { return VERIFIERS[e.fmt](e.att, clientDataHash, opts); })
|
|
709
|
+
.then(function (r) { out.push(r); }, function (err) {
|
|
710
|
+
throw _err("webauthn/compound-element-failed", "compound element " + e.index + " (format '" + e.fmt + "') did not verify", err);
|
|
711
|
+
});
|
|
712
|
+
});
|
|
713
|
+
}, Promise.resolve()).then(function () {
|
|
714
|
+
// sec. 8.9 lists the supported attestation type as "Any" and authorises returning
|
|
715
|
+
// "implementation-specific values representing any combination of outputs". A distinct type
|
|
716
|
+
// rather than a merge: collapsing to the strongest element would let a wrapper upgrade a
|
|
717
|
+
// caller's attestationType check, and collapsing to the weakest would spuriously fail one.
|
|
718
|
+
// The trust path is empty because two elements yield two independent chains and there is no
|
|
719
|
+
// single ordered path -- each element's own path is on its entry in `compound`.
|
|
720
|
+
var res = _result("compound", "Compound", [], att);
|
|
721
|
+
res.compound = out;
|
|
722
|
+
return res;
|
|
723
|
+
});
|
|
724
|
+
},
|
|
725
|
+
|
|
639
726
|
// none (WebAuthn 8.7): the authenticator provides no attestation. attStmt MUST be
|
|
640
727
|
// an empty map; there is no statement to verify, so the result carries no trust
|
|
641
728
|
// path. The credential public key still binds via authenticatorData (AT flag).
|
package/package.json
CHANGED
package/sbom.cdx.json
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
|
|
3
3
|
"bomFormat": "CycloneDX",
|
|
4
4
|
"specVersion": "1.5",
|
|
5
|
-
"serialNumber": "urn:uuid:
|
|
5
|
+
"serialNumber": "urn:uuid:1f0429a5-9e2b-4cc8-a67f-6357968a0774",
|
|
6
6
|
"version": 1,
|
|
7
7
|
"metadata": {
|
|
8
|
-
"timestamp": "2026-08-
|
|
8
|
+
"timestamp": "2026-08-09T01:33:39.618Z",
|
|
9
9
|
"lifecycles": [
|
|
10
10
|
{
|
|
11
11
|
"phase": "build"
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
}
|
|
20
20
|
],
|
|
21
21
|
"component": {
|
|
22
|
-
"bom-ref": "@blamejs/pki@0.4.
|
|
22
|
+
"bom-ref": "@blamejs/pki@0.4.9",
|
|
23
23
|
"type": "application",
|
|
24
24
|
"name": "pki",
|
|
25
|
-
"version": "0.4.
|
|
25
|
+
"version": "0.4.9",
|
|
26
26
|
"scope": "required",
|
|
27
27
|
"author": "blamejs contributors",
|
|
28
28
|
"description": "Pure-JavaScript PKI toolkit that owns its stack — X.509, ASN.1/DER, CMS, PQC-first.",
|
|
29
|
-
"purl": "pkg:npm/%40blamejs/pki@0.4.
|
|
29
|
+
"purl": "pkg:npm/%40blamejs/pki@0.4.9",
|
|
30
30
|
"properties": [],
|
|
31
31
|
"externalReferences": [
|
|
32
32
|
{
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"components": [],
|
|
55
55
|
"dependencies": [
|
|
56
56
|
{
|
|
57
|
-
"ref": "@blamejs/pki@0.4.
|
|
57
|
+
"ref": "@blamejs/pki@0.4.9",
|
|
58
58
|
"dependsOn": []
|
|
59
59
|
}
|
|
60
60
|
]
|