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/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Mitigator 🛡️
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/mitigator)
|
|
4
|
+
[](https://www.npmjs.com/package/mitigator)
|
|
5
|
+
[](https://opensource.org/licenses/ISC)
|
|
6
|
+
|
|
3
7
|
**Mitigator** is a production-grade, security-first TypeScript library designed to eliminate common vulnerabilities and implement advanced defense-in-depth patterns in Node.js applications.
|
|
4
8
|
|
|
5
9
|
Unlike generic utility libraries, Mitigator is built with a "Zero-Trust" philosophy, providing tools specifically hardened against XSS, Prototype Pollution, Path Traversal, SQL Injection, and more.
|
|
File without changes
|
|
File without changes
|
package/dist/index.cjs
CHANGED
|
@@ -393,7 +393,11 @@ var isJwtValid = (token, secretOrPublicKey, algorithm = "HS256") => {
|
|
|
393
393
|
if (!header.alg || header.alg.toLowerCase() === "none" || header.alg !== algorithm)
|
|
394
394
|
return false;
|
|
395
395
|
const payload = JSON.parse(import_node_buffer.Buffer.from(payloadB64, "base64url").toString("utf8"));
|
|
396
|
-
|
|
396
|
+
const nowSec = Math.floor(Date.now() / 1e3);
|
|
397
|
+
const clockToleranceSec = 60;
|
|
398
|
+
if (payload.exp && nowSec >= payload.exp) return false;
|
|
399
|
+
if (payload.nbf && nowSec + clockToleranceSec < payload.nbf) return false;
|
|
400
|
+
if (payload.iat && nowSec + clockToleranceSec < payload.iat) return false;
|
|
397
401
|
const dataToSign = `${headerB64}.${payloadB64}`;
|
|
398
402
|
const signatureBuffer = import_node_buffer.Buffer.from(signatureB64, "base64url");
|
|
399
403
|
if (algorithm.startsWith("HS")) {
|
|
@@ -1099,28 +1103,20 @@ var TokenBucket = class {
|
|
|
1099
1103
|
buckets = /* @__PURE__ */ new Map();
|
|
1100
1104
|
async consume(id, tokens = 1) {
|
|
1101
1105
|
const now = Date.now();
|
|
1102
|
-
|
|
1106
|
+
let bucket = this.buckets.get(id);
|
|
1103
1107
|
if (bucket) {
|
|
1104
1108
|
const delta = (now - bucket.lastRefill) / 1e3;
|
|
1105
1109
|
const refill = delta * this.refillRatePerSecond;
|
|
1106
1110
|
bucket.tokens = Math.min(this.capacity, bucket.tokens + refill);
|
|
1107
1111
|
bucket.lastRefill = now;
|
|
1108
1112
|
} else {
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
newBucket.tokens -= tokens;
|
|
1112
|
-
this.buckets.set(id, newBucket);
|
|
1113
|
-
return true;
|
|
1114
|
-
}
|
|
1115
|
-
this.buckets.set(id, newBucket);
|
|
1116
|
-
return false;
|
|
1113
|
+
bucket = { tokens: this.capacity, lastRefill: now };
|
|
1114
|
+
this.buckets.set(id, bucket);
|
|
1117
1115
|
}
|
|
1118
1116
|
if (bucket.tokens >= tokens) {
|
|
1119
1117
|
bucket.tokens -= tokens;
|
|
1120
|
-
this.buckets.set(id, bucket);
|
|
1121
1118
|
return true;
|
|
1122
1119
|
}
|
|
1123
|
-
this.buckets.set(id, bucket);
|
|
1124
1120
|
return false;
|
|
1125
1121
|
}
|
|
1126
1122
|
};
|