@forklaunch/core 1.5.18 → 1.5.20
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/lib/http/discriminateAuthMethod.d.ts.map +1 -1
- package/lib/http/index.js +66 -10
- package/lib/http/index.js.map +1 -1
- package/lib/http/index.mjs +64 -8
- package/lib/http/index.mjs.map +1 -1
- package/lib/http/middleware/request/auth.middleware.d.ts.map +1 -1
- package/lib/http/middleware/request/authLogContext.d.ts +44 -0
- package/lib/http/middleware/request/authLogContext.d.ts.map +1 -0
- package/package.json +22 -22
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discriminateAuthMethod.d.ts","sourceRoot":"","sources":["../../src/http/discriminateAuthMethod.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,UAAU,EAAa,MAAM,MAAM,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAK9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EACjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAYzE;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,aAAa,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CA4B5E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAsB,sBAAsB,CAC1C,EAAE,SAAS,kBAAkB,EAC7B,CAAC,SAAS,gBAAgB,EAC1B,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvC,QAAQ,SAAS,QAAQ,EACzB,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACzC,aAAa,SAAS,iBAAiB,EACvC,WAAW,EAEX,IAAI,EAAE,WAAW,CACf,EAAE,EACF,CAAC,EACD,OAAO,EACP,QAAQ,EACR,UAAU,EACV,aAAa,EACb,WAAW,CACZ,EACD,sBAAsB,CAAC,EAAE,sBAAsB,CAAC,iBAAiB,CAAC,GACjE,OAAO,CACN;IACE,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE;QACJ,cAAc,CAAC,EAAE,cAAc,CAAC;QAChC,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC;KAC3C,CAAC;CACH,GACD;IACE,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,EACA;QACE,cAAc,CAAC,EAAE,cAAc,CAAC;KACjC,GACD;QACE,oBAAoB,EAAE,CACpB,KAAK,EAAE,MAAM,KACV,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;KACtC,CAAC;CACP,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE;QACJ,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACnC,oBAAoB,EAAE,CAAC,EACrB,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,SAAS,EACT,KAAK,EACL,SAAS,EACT,SAAS,EACV,EAAE;YACD,MAAM,EAAE,MAAM,CAAC;YACf,IAAI,EAAE,MAAM,CAAC;YACb,IAAI,CAAC,EAAE,OAAO,CAAC;YACf,SAAS,EAAE,IAAI,CAAC;YAChB,KAAK,EAAE,MAAM,CAAC;YACd,SAAS,EAAE,MAAM,CAAC;YAClB,SAAS,EAAE,MAAM,CAAC;SACnB,KAAK,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;KACpC,CAAC;CACH,CACJ,
|
|
1
|
+
{"version":3,"file":"discriminateAuthMethod.d.ts","sourceRoot":"","sources":["../../src/http/discriminateAuthMethod.ts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,IAAI,EACA;QACE,cAAc,CAAC,EAAE,cAAc,CAAC;KACjC,GACD;QACE,oBAAoB,EAAE,CACpB,KAAK,EAAE,MAAM,KACV,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;KACtC,CAAC;CACP,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE;QACJ,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACnC,oBAAoB,EAAE,CAAC,EACrB,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,SAAS,EACT,KAAK,EACL,SAAS,EACT,SAAS,EACV,EAAE;YACD,MAAM,EAAE,MAAM,CAAC;YACf,IAAI,EAAE,MAAM,CAAC;YACb,IAAI,CAAC,EAAE,OAAO,CAAC;YACf,SAAS,EAAE,IAAI,CAAC;YAChB,KAAK,EAAE,MAAM,CAAC;YACd,SAAS,EAAE,MAAM,CAAC;YAClB,SAAS,EAAE,MAAM,CAAC;SACnB,KAAK,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;KACpC,CAAC;CACH,CACJ,CAqHA"}
|
package/lib/http/index.js
CHANGED
|
@@ -809,17 +809,20 @@ async function discriminateAuthMethod(auth, openTelemetryCollector) {
|
|
|
809
809
|
jwks = [jwt.jwksPublicKey];
|
|
810
810
|
}
|
|
811
811
|
verificationFunction = async (token) => {
|
|
812
|
+
let lastError;
|
|
812
813
|
for (const key of jwks) {
|
|
813
814
|
try {
|
|
814
815
|
const { payload } = await (0, import_jose.jwtVerify)(token, key);
|
|
815
816
|
return payload;
|
|
816
|
-
} catch {
|
|
817
|
+
} catch (error) {
|
|
818
|
+
lastError = error;
|
|
817
819
|
cachedJwks.value = null;
|
|
818
820
|
cachedJwks.lastUpdated = null;
|
|
819
821
|
cachedJwks.ttl = DEFAULT_TTL;
|
|
820
822
|
continue;
|
|
821
823
|
}
|
|
822
824
|
}
|
|
825
|
+
if (lastError !== void 0) throw lastError;
|
|
823
826
|
};
|
|
824
827
|
}
|
|
825
828
|
authMethod = {
|
|
@@ -888,6 +891,58 @@ function hasSubscriptionChecks(maybeSubscriptionAuth) {
|
|
|
888
891
|
return typeof maybeSubscriptionAuth === "object" && maybeSubscriptionAuth !== null && "requireActiveSubscription" in maybeSubscriptionAuth && maybeSubscriptionAuth.requireActiveSubscription === true;
|
|
889
892
|
}
|
|
890
893
|
|
|
894
|
+
// src/http/middleware/request/authLogContext.ts
|
|
895
|
+
var import_crypto2 = require("crypto");
|
|
896
|
+
var import_jose2 = require("jose");
|
|
897
|
+
var FINGERPRINT_LENGTH = 8;
|
|
898
|
+
var MAX_CLAIM_LENGTH = 128;
|
|
899
|
+
function bounded(value) {
|
|
900
|
+
return typeof value === "string" && value.length > 0 ? value.slice(0, MAX_CLAIM_LENGTH) : void 0;
|
|
901
|
+
}
|
|
902
|
+
function authLogContext(headerValue) {
|
|
903
|
+
if (typeof headerValue !== "string" || headerValue.length === 0) {
|
|
904
|
+
return { hasToken: false };
|
|
905
|
+
}
|
|
906
|
+
const context2 = {
|
|
907
|
+
hasToken: true,
|
|
908
|
+
tokenFingerprint: (0, import_crypto2.createHash)("sha256").update(headerValue).digest("hex").slice(0, FINGERPRINT_LENGTH)
|
|
909
|
+
};
|
|
910
|
+
const parts = headerValue.trim().split(/\s+/);
|
|
911
|
+
const candidate = parts[parts.length - 1];
|
|
912
|
+
if (candidate.split(".").length !== 3) {
|
|
913
|
+
return context2;
|
|
914
|
+
}
|
|
915
|
+
try {
|
|
916
|
+
const payload = (0, import_jose2.decodeJwt)(candidate);
|
|
917
|
+
const header = (0, import_jose2.decodeProtectedHeader)(candidate);
|
|
918
|
+
context2.claimed = {
|
|
919
|
+
sub: bounded(payload.sub),
|
|
920
|
+
organizationId: bounded(payload.organizationId),
|
|
921
|
+
iss: bounded(payload.iss),
|
|
922
|
+
exp: typeof payload.exp === "number" ? payload.exp : void 0,
|
|
923
|
+
kid: bounded(header.kid)
|
|
924
|
+
};
|
|
925
|
+
} catch {
|
|
926
|
+
}
|
|
927
|
+
return context2;
|
|
928
|
+
}
|
|
929
|
+
function jwtFailureReason(error) {
|
|
930
|
+
if (error instanceof import_jose2.errors.JWTExpired) return "jwt_expired";
|
|
931
|
+
if (error instanceof import_jose2.errors.JWTClaimValidationFailed) {
|
|
932
|
+
return `jwt_claim_${error.claim}`;
|
|
933
|
+
}
|
|
934
|
+
if (error instanceof import_jose2.errors.JWSSignatureVerificationFailed) {
|
|
935
|
+
return "jwt_bad_signature";
|
|
936
|
+
}
|
|
937
|
+
if (error instanceof import_jose2.errors.JWKSNoMatchingKey) return "jwks_no_key";
|
|
938
|
+
if (error instanceof import_jose2.errors.JWKSTimeout) return "jwks_unavailable";
|
|
939
|
+
if (error instanceof import_jose2.errors.JWTInvalid || error instanceof import_jose2.errors.JWSInvalid) {
|
|
940
|
+
return "jwt_malformed";
|
|
941
|
+
}
|
|
942
|
+
if (error instanceof import_jose2.errors.JOSEError) return error.code.toLowerCase();
|
|
943
|
+
return "unknown";
|
|
944
|
+
}
|
|
945
|
+
|
|
891
946
|
// src/http/middleware/request/auth.middleware.ts
|
|
892
947
|
var invalidAuthorizationTokenFormat = [
|
|
893
948
|
401,
|
|
@@ -1003,13 +1058,14 @@ async function checkAuthorizationToken(req, authorizationMethod, authorizationTo
|
|
|
1003
1058
|
}
|
|
1004
1059
|
sessionPayload = decodedJwt;
|
|
1005
1060
|
} catch (error) {
|
|
1006
|
-
req?.openTelemetryCollector?.
|
|
1061
|
+
req?.openTelemetryCollector?.warn(
|
|
1007
1062
|
"JWT Verification Failed",
|
|
1008
1063
|
meta({
|
|
1009
|
-
error,
|
|
1064
|
+
reason: jwtFailureReason(error),
|
|
1065
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1010
1066
|
method: req.method,
|
|
1011
1067
|
path: req.path,
|
|
1012
|
-
token
|
|
1068
|
+
...authLogContext(token)
|
|
1013
1069
|
})
|
|
1014
1070
|
);
|
|
1015
1071
|
return invalidAuthorizationToken;
|
|
@@ -1160,13 +1216,13 @@ async function parseRequestAuth(req, res, next) {
|
|
|
1160
1216
|
const token = req.headers[auth?.headerName ?? "Authorization"] || req.headers[auth?.headerName ?? "authorization"];
|
|
1161
1217
|
const [error, message] = await checkAuthorizationToken(req, auth, token, req._globalOptions?.()?.auth, access) ?? [];
|
|
1162
1218
|
if (error != null) {
|
|
1163
|
-
req.openTelemetryCollector?.
|
|
1219
|
+
req.openTelemetryCollector?.warn(
|
|
1164
1220
|
message || "Authorization Failed",
|
|
1165
1221
|
meta({
|
|
1166
1222
|
statusCode: error,
|
|
1167
1223
|
method: req.method,
|
|
1168
1224
|
path: req.path,
|
|
1169
|
-
token
|
|
1225
|
+
...authLogContext(token)
|
|
1170
1226
|
})
|
|
1171
1227
|
);
|
|
1172
1228
|
res.type("text/plain");
|
|
@@ -2395,7 +2451,7 @@ function isPortBound(port, host = "localhost") {
|
|
|
2395
2451
|
}
|
|
2396
2452
|
|
|
2397
2453
|
// src/http/generateHmacAuthHeaders.ts
|
|
2398
|
-
var
|
|
2454
|
+
var import_crypto3 = require("crypto");
|
|
2399
2455
|
function generateHmacAuthHeaders({
|
|
2400
2456
|
secretKey,
|
|
2401
2457
|
method,
|
|
@@ -2404,7 +2460,7 @@ function generateHmacAuthHeaders({
|
|
|
2404
2460
|
keyId = "default"
|
|
2405
2461
|
}) {
|
|
2406
2462
|
const timestamp = /* @__PURE__ */ new Date();
|
|
2407
|
-
const nonce = (0,
|
|
2463
|
+
const nonce = (0, import_crypto3.randomUUID)();
|
|
2408
2464
|
const signature = createHmacToken({
|
|
2409
2465
|
secretKey,
|
|
2410
2466
|
method,
|
|
@@ -4379,7 +4435,7 @@ function generateOpenApiSpecs(schemaValidator, serverUrls, serverDescriptions, a
|
|
|
4379
4435
|
}
|
|
4380
4436
|
|
|
4381
4437
|
// src/http/telemetry/auditLogger.ts
|
|
4382
|
-
var
|
|
4438
|
+
var import_crypto4 = require("crypto");
|
|
4383
4439
|
var AuditLogger = class {
|
|
4384
4440
|
_otel;
|
|
4385
4441
|
constructor(otel) {
|
|
@@ -4412,7 +4468,7 @@ var AuditLogger = class {
|
|
|
4412
4468
|
if (body === void 0 || body === null || body === "") {
|
|
4413
4469
|
return "";
|
|
4414
4470
|
}
|
|
4415
|
-
return (0,
|
|
4471
|
+
return (0, import_crypto4.createHash)("sha256").update(body).digest("hex");
|
|
4416
4472
|
}
|
|
4417
4473
|
};
|
|
4418
4474
|
|