mitigator 1.0.0 → 1.0.1
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/README.md +4 -0
- package/dist/bin/mitigator-audit.cjs +0 -0
- package/dist/bin/mitigator-audit.js +0 -0
- package/dist/index.cjs +8 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -16
- package/dist/index.d.ts +11 -16
- package/dist/index.js +8 -12
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -300,25 +300,19 @@ interface PasskeyRegistrationResult {
|
|
|
300
300
|
* decoding both sides from base64url, per the WebAuthn Level 2 spec §7.1.
|
|
301
301
|
*/
|
|
302
302
|
declare const verifyPasskeyRegistration: (clientDataJSONStr: string, expectedChallenge: string, expectedOrigin?: string) => PasskeyRegistrationResult;
|
|
303
|
+
interface AuthenticatorDataResult {
|
|
304
|
+
rpIdHash: Buffer$1;
|
|
305
|
+
flags: number;
|
|
306
|
+
signCount: number;
|
|
307
|
+
aaguid?: Buffer$1;
|
|
308
|
+
credentialId?: string;
|
|
309
|
+
publicKeyBytes?: string;
|
|
310
|
+
}
|
|
303
311
|
/**
|
|
304
312
|
* Parses WebAuthn raw authenticator data (authData) buffer to extract the
|
|
305
313
|
* aaguid, credential ID, and public key bytes according to the FIDO2 spec.
|
|
306
314
|
*/
|
|
307
|
-
declare const parseAuthenticatorData: (authData: Buffer$1) =>
|
|
308
|
-
rpIdHash: Buffer$1<ArrayBufferLike>;
|
|
309
|
-
flags: number;
|
|
310
|
-
signCount: number;
|
|
311
|
-
aaguid?: undefined;
|
|
312
|
-
credentialId?: undefined;
|
|
313
|
-
publicKeyBytes?: undefined;
|
|
314
|
-
} | {
|
|
315
|
-
rpIdHash: Buffer$1<ArrayBufferLike>;
|
|
316
|
-
flags: number;
|
|
317
|
-
signCount: number;
|
|
318
|
-
aaguid: Buffer$1<ArrayBufferLike>;
|
|
319
|
-
credentialId: string;
|
|
320
|
-
publicKeyBytes: string;
|
|
321
|
-
} | null;
|
|
315
|
+
declare const parseAuthenticatorData: (authData: Buffer$1) => AuthenticatorDataResult | null;
|
|
322
316
|
/**
|
|
323
317
|
* Result returned by `verifyPasskeyAssertion`.
|
|
324
318
|
*/
|
|
@@ -373,6 +367,7 @@ interface PasskeyAssertionResult {
|
|
|
373
367
|
*/
|
|
374
368
|
declare const verifyPasskeyAssertion: (clientDataJSONStr: string, expectedChallenge: string, expectedOrigin: string, storedSignCount: number, authData: Buffer$1, signature: Buffer$1, publicKeyPem: string) => PasskeyAssertionResult;
|
|
375
369
|
|
|
370
|
+
type index$7_AuthenticatorDataResult = AuthenticatorDataResult;
|
|
376
371
|
type index$7_PasskeyAssertionResult = PasskeyAssertionResult;
|
|
377
372
|
type index$7_PasskeyRegistrationResult = PasskeyRegistrationResult;
|
|
378
373
|
declare const index$7_basicAuth: typeof basicAuth;
|
|
@@ -393,7 +388,7 @@ declare const index$7_verifyPasskeyAssertion: typeof verifyPasskeyAssertion;
|
|
|
393
388
|
declare const index$7_verifyPasskeyRegistration: typeof verifyPasskeyRegistration;
|
|
394
389
|
declare const index$7_verifyPasskeySignature: typeof verifyPasskeySignature;
|
|
395
390
|
declare namespace index$7 {
|
|
396
|
-
export { type index$7_PasskeyAssertionResult as PasskeyAssertionResult, type index$7_PasskeyRegistrationResult as PasskeyRegistrationResult, index$7_basicAuth as basicAuth, index$7_can as can, index$7_canAccess as canAccess, index$7_generateCSRF as generateCSRF, index$7_generateHmacChallenge as generateHmacChallenge, index$7_generateHoneyToken as generateHoneyToken, index$7_generatePasskeyChallenge as generatePasskeyChallenge, index$7_hasRole as hasRole, index$7_isHoneyToken as isHoneyToken, index$7_isJwtValid as isJwtValid, index$7_parseAuthenticatorData as parseAuthenticatorData, index$7_suggestMFA as suggestMFA, index$7_verifyCSRF as verifyCSRF, index$7_verifyHmacResponse as verifyHmacResponse, index$7_verifyPasskeyAssertion as verifyPasskeyAssertion, index$7_verifyPasskeyRegistration as verifyPasskeyRegistration, index$7_verifyPasskeySignature as verifyPasskeySignature };
|
|
391
|
+
export { type index$7_AuthenticatorDataResult as AuthenticatorDataResult, type index$7_PasskeyAssertionResult as PasskeyAssertionResult, type index$7_PasskeyRegistrationResult as PasskeyRegistrationResult, index$7_basicAuth as basicAuth, index$7_can as can, index$7_canAccess as canAccess, index$7_generateCSRF as generateCSRF, index$7_generateHmacChallenge as generateHmacChallenge, index$7_generateHoneyToken as generateHoneyToken, index$7_generatePasskeyChallenge as generatePasskeyChallenge, index$7_hasRole as hasRole, index$7_isHoneyToken as isHoneyToken, index$7_isJwtValid as isJwtValid, index$7_parseAuthenticatorData as parseAuthenticatorData, index$7_suggestMFA as suggestMFA, index$7_verifyCSRF as verifyCSRF, index$7_verifyHmacResponse as verifyHmacResponse, index$7_verifyPasskeyAssertion as verifyPasskeyAssertion, index$7_verifyPasskeyRegistration as verifyPasskeyRegistration, index$7_verifyPasskeySignature as verifyPasskeySignature };
|
|
397
392
|
}
|
|
398
393
|
|
|
399
394
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -300,25 +300,19 @@ interface PasskeyRegistrationResult {
|
|
|
300
300
|
* decoding both sides from base64url, per the WebAuthn Level 2 spec §7.1.
|
|
301
301
|
*/
|
|
302
302
|
declare const verifyPasskeyRegistration: (clientDataJSONStr: string, expectedChallenge: string, expectedOrigin?: string) => PasskeyRegistrationResult;
|
|
303
|
+
interface AuthenticatorDataResult {
|
|
304
|
+
rpIdHash: Buffer$1;
|
|
305
|
+
flags: number;
|
|
306
|
+
signCount: number;
|
|
307
|
+
aaguid?: Buffer$1;
|
|
308
|
+
credentialId?: string;
|
|
309
|
+
publicKeyBytes?: string;
|
|
310
|
+
}
|
|
303
311
|
/**
|
|
304
312
|
* Parses WebAuthn raw authenticator data (authData) buffer to extract the
|
|
305
313
|
* aaguid, credential ID, and public key bytes according to the FIDO2 spec.
|
|
306
314
|
*/
|
|
307
|
-
declare const parseAuthenticatorData: (authData: Buffer$1) =>
|
|
308
|
-
rpIdHash: Buffer$1<ArrayBufferLike>;
|
|
309
|
-
flags: number;
|
|
310
|
-
signCount: number;
|
|
311
|
-
aaguid?: undefined;
|
|
312
|
-
credentialId?: undefined;
|
|
313
|
-
publicKeyBytes?: undefined;
|
|
314
|
-
} | {
|
|
315
|
-
rpIdHash: Buffer$1<ArrayBufferLike>;
|
|
316
|
-
flags: number;
|
|
317
|
-
signCount: number;
|
|
318
|
-
aaguid: Buffer$1<ArrayBufferLike>;
|
|
319
|
-
credentialId: string;
|
|
320
|
-
publicKeyBytes: string;
|
|
321
|
-
} | null;
|
|
315
|
+
declare const parseAuthenticatorData: (authData: Buffer$1) => AuthenticatorDataResult | null;
|
|
322
316
|
/**
|
|
323
317
|
* Result returned by `verifyPasskeyAssertion`.
|
|
324
318
|
*/
|
|
@@ -373,6 +367,7 @@ interface PasskeyAssertionResult {
|
|
|
373
367
|
*/
|
|
374
368
|
declare const verifyPasskeyAssertion: (clientDataJSONStr: string, expectedChallenge: string, expectedOrigin: string, storedSignCount: number, authData: Buffer$1, signature: Buffer$1, publicKeyPem: string) => PasskeyAssertionResult;
|
|
375
369
|
|
|
370
|
+
type index$7_AuthenticatorDataResult = AuthenticatorDataResult;
|
|
376
371
|
type index$7_PasskeyAssertionResult = PasskeyAssertionResult;
|
|
377
372
|
type index$7_PasskeyRegistrationResult = PasskeyRegistrationResult;
|
|
378
373
|
declare const index$7_basicAuth: typeof basicAuth;
|
|
@@ -393,7 +388,7 @@ declare const index$7_verifyPasskeyAssertion: typeof verifyPasskeyAssertion;
|
|
|
393
388
|
declare const index$7_verifyPasskeyRegistration: typeof verifyPasskeyRegistration;
|
|
394
389
|
declare const index$7_verifyPasskeySignature: typeof verifyPasskeySignature;
|
|
395
390
|
declare namespace index$7 {
|
|
396
|
-
export { type index$7_PasskeyAssertionResult as PasskeyAssertionResult, type index$7_PasskeyRegistrationResult as PasskeyRegistrationResult, index$7_basicAuth as basicAuth, index$7_can as can, index$7_canAccess as canAccess, index$7_generateCSRF as generateCSRF, index$7_generateHmacChallenge as generateHmacChallenge, index$7_generateHoneyToken as generateHoneyToken, index$7_generatePasskeyChallenge as generatePasskeyChallenge, index$7_hasRole as hasRole, index$7_isHoneyToken as isHoneyToken, index$7_isJwtValid as isJwtValid, index$7_parseAuthenticatorData as parseAuthenticatorData, index$7_suggestMFA as suggestMFA, index$7_verifyCSRF as verifyCSRF, index$7_verifyHmacResponse as verifyHmacResponse, index$7_verifyPasskeyAssertion as verifyPasskeyAssertion, index$7_verifyPasskeyRegistration as verifyPasskeyRegistration, index$7_verifyPasskeySignature as verifyPasskeySignature };
|
|
391
|
+
export { type index$7_AuthenticatorDataResult as AuthenticatorDataResult, type index$7_PasskeyAssertionResult as PasskeyAssertionResult, type index$7_PasskeyRegistrationResult as PasskeyRegistrationResult, index$7_basicAuth as basicAuth, index$7_can as can, index$7_canAccess as canAccess, index$7_generateCSRF as generateCSRF, index$7_generateHmacChallenge as generateHmacChallenge, index$7_generateHoneyToken as generateHoneyToken, index$7_generatePasskeyChallenge as generatePasskeyChallenge, index$7_hasRole as hasRole, index$7_isHoneyToken as isHoneyToken, index$7_isJwtValid as isJwtValid, index$7_parseAuthenticatorData as parseAuthenticatorData, index$7_suggestMFA as suggestMFA, index$7_verifyCSRF as verifyCSRF, index$7_verifyHmacResponse as verifyHmacResponse, index$7_verifyPasskeyAssertion as verifyPasskeyAssertion, index$7_verifyPasskeyRegistration as verifyPasskeyRegistration, index$7_verifyPasskeySignature as verifyPasskeySignature };
|
|
397
392
|
}
|
|
398
393
|
|
|
399
394
|
/**
|
package/dist/index.js
CHANGED
|
@@ -243,7 +243,11 @@ var isJwtValid = (token, secretOrPublicKey, algorithm = "HS256") => {
|
|
|
243
243
|
if (!header.alg || header.alg.toLowerCase() === "none" || header.alg !== algorithm)
|
|
244
244
|
return false;
|
|
245
245
|
const payload = JSON.parse(Buffer2.from(payloadB64, "base64url").toString("utf8"));
|
|
246
|
-
|
|
246
|
+
const nowSec = Math.floor(Date.now() / 1e3);
|
|
247
|
+
const clockToleranceSec = 60;
|
|
248
|
+
if (payload.exp && nowSec >= payload.exp) return false;
|
|
249
|
+
if (payload.nbf && nowSec + clockToleranceSec < payload.nbf) return false;
|
|
250
|
+
if (payload.iat && nowSec + clockToleranceSec < payload.iat) return false;
|
|
247
251
|
const dataToSign = `${headerB64}.${payloadB64}`;
|
|
248
252
|
const signatureBuffer = Buffer2.from(signatureB64, "base64url");
|
|
249
253
|
if (algorithm.startsWith("HS")) {
|
|
@@ -958,28 +962,20 @@ var TokenBucket = class {
|
|
|
958
962
|
buckets = /* @__PURE__ */ new Map();
|
|
959
963
|
async consume(id, tokens = 1) {
|
|
960
964
|
const now = Date.now();
|
|
961
|
-
|
|
965
|
+
let bucket = this.buckets.get(id);
|
|
962
966
|
if (bucket) {
|
|
963
967
|
const delta = (now - bucket.lastRefill) / 1e3;
|
|
964
968
|
const refill = delta * this.refillRatePerSecond;
|
|
965
969
|
bucket.tokens = Math.min(this.capacity, bucket.tokens + refill);
|
|
966
970
|
bucket.lastRefill = now;
|
|
967
971
|
} else {
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
newBucket.tokens -= tokens;
|
|
971
|
-
this.buckets.set(id, newBucket);
|
|
972
|
-
return true;
|
|
973
|
-
}
|
|
974
|
-
this.buckets.set(id, newBucket);
|
|
975
|
-
return false;
|
|
972
|
+
bucket = { tokens: this.capacity, lastRefill: now };
|
|
973
|
+
this.buckets.set(id, bucket);
|
|
976
974
|
}
|
|
977
975
|
if (bucket.tokens >= tokens) {
|
|
978
976
|
bucket.tokens -= tokens;
|
|
979
|
-
this.buckets.set(id, bucket);
|
|
980
977
|
return true;
|
|
981
978
|
}
|
|
982
|
-
this.buckets.set(id, bucket);
|
|
983
979
|
return false;
|
|
984
980
|
}
|
|
985
981
|
};
|