ega-v9 1.0.3 → 1.0.4
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/dist/index.d.ts +1 -1
- package/dist/index.js +29 -14
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -155,7 +155,7 @@ type NextFunction = EGAGuardNext;
|
|
|
155
155
|
type EGARequest = EGAGuardRequest;
|
|
156
156
|
type EGAResponse = EGAGuardResponse;
|
|
157
157
|
export declare class EGA {
|
|
158
|
-
private
|
|
158
|
+
#private;
|
|
159
159
|
private readonly eventLog;
|
|
160
160
|
private eventSequence;
|
|
161
161
|
private constructor();
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _EGA_options;
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
15
|
exports.evaluateRuntimeAdmission = exports.assertRuntimeLicenseAdmission = exports.EGARuntimeAdmissionError = exports.ega = exports.EGA = void 0;
|
|
4
16
|
exports.verifyExecution = verifyExecution;
|
|
@@ -166,16 +178,17 @@ function validateGuardInvocation(req, res, next) {
|
|
|
166
178
|
}
|
|
167
179
|
class EGA {
|
|
168
180
|
constructor(options = {}) {
|
|
181
|
+
_EGA_options.set(this, void 0);
|
|
169
182
|
this.eventLog = [];
|
|
170
183
|
this.eventSequence = 0;
|
|
171
|
-
this
|
|
184
|
+
__classPrivateFieldSet(this, _EGA_options, Object.freeze({
|
|
172
185
|
appName: options.appName ?? "ega-v9-app",
|
|
173
186
|
trustLevel: options.trustLevel ?? "supported",
|
|
174
187
|
telemetry: options.telemetry ?? false,
|
|
175
188
|
failClosed: options.failClosed ?? true,
|
|
176
189
|
policyId: options.policyId ?? "default-policy",
|
|
177
190
|
approvalThreshold: options.approvalThreshold ?? 70
|
|
178
|
-
};
|
|
191
|
+
}), "f");
|
|
179
192
|
}
|
|
180
193
|
static init(options = {}) {
|
|
181
194
|
validateEGAOptions(options);
|
|
@@ -183,9 +196,10 @@ class EGA {
|
|
|
183
196
|
}
|
|
184
197
|
guard() {
|
|
185
198
|
return (req, res, next) => {
|
|
199
|
+
(0, runtime_admission_provider_1.enforceRuntimeLicenseAdmission)();
|
|
186
200
|
validateGuardInvocation(req, res, next);
|
|
187
201
|
const requestId = (0, crypto_1.randomUUID)();
|
|
188
|
-
const clientIdentity = buildAnonymousClientIdentity(req, this.
|
|
202
|
+
const clientIdentity = buildAnonymousClientIdentity(req, __classPrivateFieldGet(this, _EGA_options, "f").appName);
|
|
189
203
|
const licenseState = evaluateLicenseState(req);
|
|
190
204
|
const actualReplayRoot = this.createReplayRoot(req);
|
|
191
205
|
const expectedReplayRoot = this.getExpectedReplayRoot(req);
|
|
@@ -194,7 +208,7 @@ class EGA {
|
|
|
194
208
|
timestamp: new Date().toISOString(),
|
|
195
209
|
requestId,
|
|
196
210
|
replayRoot: actualReplayRoot,
|
|
197
|
-
trustLevel: this.
|
|
211
|
+
trustLevel: __classPrivateFieldGet(this, _EGA_options, "f").trustLevel,
|
|
198
212
|
status: "verified",
|
|
199
213
|
clientIdentity,
|
|
200
214
|
licenseState
|
|
@@ -207,9 +221,9 @@ class EGA {
|
|
|
207
221
|
const businessMetrics = collectBusinessMetrics(req.body);
|
|
208
222
|
const trust = evaluateTrust({
|
|
209
223
|
isMismatch,
|
|
210
|
-
failClosed: this.
|
|
224
|
+
failClosed: __classPrivateFieldGet(this, _EGA_options, "f").failClosed,
|
|
211
225
|
businessMetrics,
|
|
212
|
-
approvalThreshold: this.
|
|
226
|
+
approvalThreshold: __classPrivateFieldGet(this, _EGA_options, "f").approvalThreshold
|
|
213
227
|
});
|
|
214
228
|
const businessGovernanceProfile = buildBusinessGovernanceProfile(businessMetrics, trust);
|
|
215
229
|
const provenance = this.buildProvenanceGraph({
|
|
@@ -223,7 +237,7 @@ class EGA {
|
|
|
223
237
|
const context = {
|
|
224
238
|
requestId,
|
|
225
239
|
replayRoot: actualReplayRoot,
|
|
226
|
-
trustLevel: this.
|
|
240
|
+
trustLevel: __classPrivateFieldGet(this, _EGA_options, "f").trustLevel,
|
|
227
241
|
status: isMismatch ? "contained" : "verified",
|
|
228
242
|
scorpLock: true,
|
|
229
243
|
clientIdentity,
|
|
@@ -236,10 +250,10 @@ class EGA {
|
|
|
236
250
|
},
|
|
237
251
|
containment: {
|
|
238
252
|
activated: isMismatch,
|
|
239
|
-
mode: this.
|
|
253
|
+
mode: __classPrivateFieldGet(this, _EGA_options, "f").failClosed ? "fail-closed" : "observe",
|
|
240
254
|
reason: isMismatch ? "replay root mismatch" : undefined,
|
|
241
255
|
quarantineId,
|
|
242
|
-
executionAllowed: !isMismatch || !this.
|
|
256
|
+
executionAllowed: !isMismatch || !__classPrivateFieldGet(this, _EGA_options, "f").failClosed
|
|
243
257
|
},
|
|
244
258
|
trust,
|
|
245
259
|
businessGovernanceProfile,
|
|
@@ -408,7 +422,7 @@ class EGA {
|
|
|
408
422
|
executionAllowed: context.containment.executionAllowed
|
|
409
423
|
}
|
|
410
424
|
});
|
|
411
|
-
if (this.
|
|
425
|
+
if (__classPrivateFieldGet(this, _EGA_options, "f").failClosed) {
|
|
412
426
|
this.recordEvent({
|
|
413
427
|
type: "execution.blocked",
|
|
414
428
|
timestamp: new Date().toISOString(),
|
|
@@ -498,7 +512,7 @@ class EGA {
|
|
|
498
512
|
}
|
|
499
513
|
createReplayRoot(req) {
|
|
500
514
|
return this.replayRoot({
|
|
501
|
-
appName: this.
|
|
515
|
+
appName: __classPrivateFieldGet(this, _EGA_options, "f").appName,
|
|
502
516
|
method: req.method ?? "UNKNOWN",
|
|
503
517
|
path: req.originalUrl ?? req.url ?? req.path ?? "/",
|
|
504
518
|
body: req.body ?? null,
|
|
@@ -538,9 +552,9 @@ class EGA {
|
|
|
538
552
|
type: "policy",
|
|
539
553
|
label: "Policy",
|
|
540
554
|
data: {
|
|
541
|
-
policyId: this.
|
|
555
|
+
policyId: __classPrivateFieldGet(this, _EGA_options, "f").policyId,
|
|
542
556
|
scorpLock: true,
|
|
543
|
-
failClosed: this.
|
|
557
|
+
failClosed: __classPrivateFieldGet(this, _EGA_options, "f").failClosed
|
|
544
558
|
}
|
|
545
559
|
},
|
|
546
560
|
{
|
|
@@ -549,7 +563,7 @@ class EGA {
|
|
|
549
563
|
label: "Decision",
|
|
550
564
|
data: {
|
|
551
565
|
status: args.isMismatch ? "contained" : "verified",
|
|
552
|
-
executionAllowed: !args.isMismatch || !this.
|
|
566
|
+
executionAllowed: !args.isMismatch || !__classPrivateFieldGet(this, _EGA_options, "f").failClosed
|
|
553
567
|
}
|
|
554
568
|
},
|
|
555
569
|
{
|
|
@@ -601,6 +615,7 @@ class EGA {
|
|
|
601
615
|
}
|
|
602
616
|
}
|
|
603
617
|
exports.EGA = EGA;
|
|
618
|
+
_EGA_options = new WeakMap();
|
|
604
619
|
function buildAnonymousClientIdentity(req, appName) {
|
|
605
620
|
const headers = req.headers ?? {};
|
|
606
621
|
const hostValue = headers.host ?? headers.Host;
|