unjwt 0.5.11 → 0.5.13
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.mts +4 -4
- package/dist/index.mjs +5 -5
- package/dist/jwe.d.mts +2 -2
- package/dist/jwe.mjs +4 -4
- package/dist/jwk.d.mts +2 -2
- package/dist/jwk.mjs +2 -2
- package/dist/jws.d.mts +2 -2
- package/dist/jws.mjs +4 -4
- package/dist/shared/{unjwt.BvhKNVNR.d.mts → unjwt.B9sSOKE3.d.mts} +6 -2
- package/dist/shared/{unjwt.QRureeXk.d.mts → unjwt.BRtnm5sB.d.mts} +6 -2
- package/dist/shared/{unjwt.D_JFPtpW.mjs → unjwt.C6flzAeB.mjs} +12 -7
- package/dist/shared/{unjwt.DuBBF25X.mjs → unjwt.CX8WRx20.mjs} +11 -7
- package/dist/shared/{unjwt.df8yQ5_5.d.mts → unjwt.Cay_cOOI.d.mts} +16 -1
- package/dist/shared/{unjwt.C_D0RMCp.mjs → unjwt.DFAKwqBz.mjs} +1 -1
- package/dist/shared/{unjwt.Cz90HQhy.d.mts → unjwt.DtVML6Qp.d.mts} +9 -1
- package/dist/shared/{unjwt.DVMpKj8x.mjs → unjwt.UfthlTWt.mjs} +12 -9
- package/dist/shared/{unjwt.Ce8yMcp_.mjs → unjwt.mBSKL6g4.mjs} +53 -2
- package/dist/utils.d.mts +1 -1
- package/dist/utils.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, m as JWK, E as JWKAlgorithm, F as JWKPEMAlgorithm, J as JWKParameters, n as JWKSet, v as JWK_AES_CBC_HMAC, w as JWK_AES_GCM, u as JWK_AES_GCM_KW, t as JWK_AES_KW, B as JWK_Asymmetric_Algorithm, h as JWK_EC, y as JWK_ECDH_ES, r as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, z as JWK_ED, o as JWK_HMAC, x as JWK_PBES2, k as JWK_RSA, s as JWK_RSA_ENC, q as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, p as JWK_RSA_SIGN, A as JWK_Symmetric_Algorithm, l as JWK_oct, L as JWT, M as JWTClaimValidationOptions, I as JWTClaims, H as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.CN1C8TlR.mjs';
|
|
2
|
-
export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, j as jws } from './shared/unjwt.
|
|
3
|
-
export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, j as jwe } from './shared/unjwt.
|
|
4
|
-
export { i as utils } from './shared/unjwt.
|
|
5
|
-
export { j as jwk } from './shared/unjwt.
|
|
2
|
+
export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, j as jws } from './shared/unjwt.BRtnm5sB.mjs';
|
|
3
|
+
export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, j as jwe } from './shared/unjwt.B9sSOKE3.mjs';
|
|
4
|
+
export { i as utils } from './shared/unjwt.Cay_cOOI.mjs';
|
|
5
|
+
export { j as jwk } from './shared/unjwt.DtVML6Qp.mjs';
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { i as utils } from './shared/unjwt.
|
|
2
|
-
export { j as jwe } from './shared/unjwt.
|
|
3
|
-
export { j as jwk } from './shared/unjwt.
|
|
4
|
-
export { j as jws } from './shared/unjwt.
|
|
5
|
-
import './shared/unjwt.
|
|
1
|
+
export { i as utils } from './shared/unjwt.mBSKL6g4.mjs';
|
|
2
|
+
export { j as jwe } from './shared/unjwt.UfthlTWt.mjs';
|
|
3
|
+
export { j as jwk } from './shared/unjwt.CX8WRx20.mjs';
|
|
4
|
+
export { j as jws } from './shared/unjwt.C6flzAeB.mjs';
|
|
5
|
+
import './shared/unjwt.DFAKwqBz.mjs';
|
package/dist/jwe.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, g as decrypt, f as encrypt } from './shared/unjwt.
|
|
1
|
+
export { L as JWT, M as JWTClaimValidationOptions, I as JWTClaims, H as JoseHeaderParameters } from './shared/unjwt.CN1C8TlR.mjs';
|
|
2
|
+
export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, g as decrypt, f as encrypt } from './shared/unjwt.B9sSOKE3.mjs';
|
package/dist/jwe.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
import './shared/unjwt.
|
|
3
|
-
export { d as decrypt, e as encrypt } from './shared/unjwt.
|
|
4
|
-
import './shared/unjwt.
|
|
1
|
+
import './shared/unjwt.CX8WRx20.mjs';
|
|
2
|
+
import './shared/unjwt.mBSKL6g4.mjs';
|
|
3
|
+
export { d as decrypt, e as encrypt } from './shared/unjwt.UfthlTWt.mjs';
|
|
4
|
+
import './shared/unjwt.DFAKwqBz.mjs';
|
package/dist/jwk.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, m as JWK, E as JWKAlgorithm, F as JWKPEMAlgorithm, J as JWKParameters, n as JWKSet, v as JWK_AES_CBC_HMAC, w as JWK_AES_GCM, u as JWK_AES_GCM_KW, t as JWK_AES_KW, B as JWK_Asymmetric_Algorithm, h as JWK_EC, y as JWK_ECDH_ES, r as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, z as JWK_ED, o as JWK_HMAC, x as JWK_PBES2, k as JWK_RSA, s as JWK_RSA_ENC, q as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, p as JWK_RSA_SIGN, A as JWK_Symmetric_Algorithm, l as JWK_oct, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.CN1C8TlR.mjs';
|
|
2
|
-
export { d as deriveKeyFromPassword, b as exportJWKToPEM, e as exportKey, g as generateKey, c as getJWKFromSet, a as importJWKFromPEM, i as importKey, u as unwrapKey, w as wrapKey } from './shared/unjwt.
|
|
1
|
+
export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, m as JWK, E as JWKAlgorithm, F as JWKPEMAlgorithm, J as JWKParameters, n as JWKSet, v as JWK_AES_CBC_HMAC, w as JWK_AES_GCM, u as JWK_AES_GCM_KW, t as JWK_AES_KW, B as JWK_Asymmetric_Algorithm, h as JWK_EC, y as JWK_ECDH_ES, r as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, z as JWK_ED, o as JWK_HMAC, x as JWK_PBES2, k as JWK_RSA, s as JWK_RSA_ENC, q as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, p as JWK_RSA_SIGN, A as JWK_Symmetric_Algorithm, l as JWK_oct, L as JWT, M as JWTClaimValidationOptions, I as JWTClaims, H as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.CN1C8TlR.mjs';
|
|
2
|
+
export { d as deriveKeyFromPassword, b as exportJWKToPEM, e as exportKey, g as generateKey, c as getJWKFromSet, a as importJWKFromPEM, i as importKey, u as unwrapKey, w as wrapKey } from './shared/unjwt.DtVML6Qp.mjs';
|
package/dist/jwk.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
export { p as deriveKeyFromPassword, t as exportJWKToPEM, q as exportKey, o as generateKey, g as getJWKFromSet, s as importJWKFromPEM, i as importKey, m as unwrapKey, r as wrapKey } from './shared/unjwt.
|
|
1
|
+
import './shared/unjwt.mBSKL6g4.mjs';
|
|
2
|
+
export { p as deriveKeyFromPassword, t as exportJWKToPEM, q as exportKey, o as generateKey, g as getJWKFromSet, s as importJWKFromPEM, i as importKey, m as unwrapKey, r as wrapKey } from './shared/unjwt.CX8WRx20.mjs';
|
package/dist/jws.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, s as sign, v as verify } from './shared/unjwt.
|
|
1
|
+
export { L as JWT, M as JWTClaimValidationOptions, I as JWTClaims, H as JoseHeaderParameters } from './shared/unjwt.CN1C8TlR.mjs';
|
|
2
|
+
export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, s as sign, v as verify } from './shared/unjwt.BRtnm5sB.mjs';
|
package/dist/jws.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
import './shared/unjwt.
|
|
3
|
-
import './shared/unjwt.
|
|
4
|
-
export { s as sign, v as verify } from './shared/unjwt.
|
|
1
|
+
import './shared/unjwt.CX8WRx20.mjs';
|
|
2
|
+
import './shared/unjwt.mBSKL6g4.mjs';
|
|
3
|
+
import './shared/unjwt.DFAKwqBz.mjs';
|
|
4
|
+
export { s as sign, v as verify } from './shared/unjwt.C6flzAeB.mjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { K as KeyManagementAlgorithm, d as ContentEncryptionAlgorithm, H as JoseHeaderParameters, f as JWK_EC_Public, m as JWK, M as JWTClaimValidationOptions, I as JWTClaims } from './unjwt.CN1C8TlR.mjs';
|
|
1
|
+
import { K as KeyManagementAlgorithm, d as ContentEncryptionAlgorithm, H as JoseHeaderParameters, f as JWK_EC_Public, m as JWK, M as JWTClaimValidationOptions, I as JWTClaims, L as JWT } from './unjwt.CN1C8TlR.mjs';
|
|
2
2
|
|
|
3
3
|
/** Recognized JWE Header Parameters, any other Header Members may also be present. */
|
|
4
4
|
interface JWEHeaderParameters extends JoseHeaderParameters {
|
|
@@ -176,10 +176,14 @@ type jwe_JWEEncryptOptions = JWEEncryptOptions;
|
|
|
176
176
|
type jwe_JWEHeaderParameters = JWEHeaderParameters;
|
|
177
177
|
type jwe_JWEKeyLookupFunction = JWEKeyLookupFunction;
|
|
178
178
|
type jwe_JWEKeyManagementHeaderParameters = JWEKeyManagementHeaderParameters;
|
|
179
|
+
declare const jwe_JWT: typeof JWT;
|
|
180
|
+
declare const jwe_JWTClaimValidationOptions: typeof JWTClaimValidationOptions;
|
|
181
|
+
declare const jwe_JWTClaims: typeof JWTClaims;
|
|
182
|
+
declare const jwe_JoseHeaderParameters: typeof JoseHeaderParameters;
|
|
179
183
|
declare const jwe_decrypt: typeof decrypt;
|
|
180
184
|
declare const jwe_encrypt: typeof encrypt;
|
|
181
185
|
declare namespace jwe {
|
|
182
|
-
export { jwe_decrypt as decrypt, jwe_encrypt as encrypt };
|
|
186
|
+
export { jwe_JWT as JWT, jwe_JWTClaimValidationOptions as JWTClaimValidationOptions, jwe_JWTClaims as JWTClaims, jwe_JoseHeaderParameters as JoseHeaderParameters, jwe_decrypt as decrypt, jwe_encrypt as encrypt };
|
|
183
187
|
export type { jwe_JWEDecryptOptions as JWEDecryptOptions, jwe_JWEDecryptResult as JWEDecryptResult, jwe_JWEEncryptOptions as JWEEncryptOptions, jwe_JWEHeaderParameters as JWEHeaderParameters, jwe_JWEKeyLookupFunction as JWEKeyLookupFunction, jwe_JWEKeyManagementHeaderParameters as JWEKeyManagementHeaderParameters };
|
|
184
188
|
}
|
|
185
189
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as JWK_HMAC, p as JWK_RSA_SIGN, q as JWK_RSA_PSS, r as JWK_ECDSA, H as JoseHeaderParameters, m as JWK, n as JWKSet, M as JWTClaimValidationOptions, I as JWTClaims } from './unjwt.CN1C8TlR.mjs';
|
|
1
|
+
import { o as JWK_HMAC, p as JWK_RSA_SIGN, q as JWK_RSA_PSS, r as JWK_ECDSA, H as JoseHeaderParameters, m as JWK, n as JWKSet, M as JWTClaimValidationOptions, I as JWTClaims, L as JWT } from './unjwt.CN1C8TlR.mjs';
|
|
2
2
|
|
|
3
3
|
type JWS_SIGN_EXTRA = "Ed25519" | "EdDSA";
|
|
4
4
|
/** JWS Signing Algorithm Identifier. */
|
|
@@ -105,10 +105,14 @@ type jws_JWSProtectedHeader = JWSProtectedHeader;
|
|
|
105
105
|
type jws_JWSSignOptions = JWSSignOptions;
|
|
106
106
|
type jws_JWSVerifyOptions = JWSVerifyOptions;
|
|
107
107
|
type jws_JWSVerifyResult<T extends JWTClaims | Uint8Array<ArrayBuffer> | string = JWTClaims | Uint8Array<ArrayBuffer> | string> = JWSVerifyResult<T>;
|
|
108
|
+
declare const jws_JWT: typeof JWT;
|
|
109
|
+
declare const jws_JWTClaimValidationOptions: typeof JWTClaimValidationOptions;
|
|
110
|
+
declare const jws_JWTClaims: typeof JWTClaims;
|
|
111
|
+
declare const jws_JoseHeaderParameters: typeof JoseHeaderParameters;
|
|
108
112
|
declare const jws_sign: typeof sign;
|
|
109
113
|
declare const jws_verify: typeof verify;
|
|
110
114
|
declare namespace jws {
|
|
111
|
-
export { jws_sign as sign, jws_verify as verify };
|
|
115
|
+
export { jws_JWT as JWT, jws_JWTClaimValidationOptions as JWTClaimValidationOptions, jws_JWTClaims as JWTClaims, jws_JoseHeaderParameters as JoseHeaderParameters, jws_sign as sign, jws_verify as verify };
|
|
112
116
|
export type { jws_JWSAlgorithm as JWSAlgorithm, jws_JWSHeaderParameters as JWSHeaderParameters, jws_JWSKeyLookupFunction as JWSKeyLookupFunction, jws_JWSProtectedHeader as JWSProtectedHeader, jws_JWSSignOptions as JWSSignOptions, jws_JWSVerifyOptions as JWSVerifyOptions, jws_JWSVerifyResult as JWSVerifyResult };
|
|
113
117
|
}
|
|
114
118
|
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { i as importKey, g as getJWKFromSet } from './unjwt.
|
|
2
|
-
import { a as isJWK, b as applyTypCtyDefaults, c as computeJwtTimeClaims, d as base64UrlEncode, t as textEncoder, e as textDecoder, f as base64UrlDecode, g as isJWKSet, h as decodePayloadFromB64UrlSegment, v as validateCriticalHeadersJWS, j as validateJwtClaims } from './unjwt.
|
|
3
|
-
import { s as sign$1, v as verify$1 } from './unjwt.
|
|
1
|
+
import { i as importKey, g as getJWKFromSet } from './unjwt.CX8WRx20.mjs';
|
|
2
|
+
import { s as sanitizeObject, a as isJWK, b as applyTypCtyDefaults, c as computeJwtTimeClaims, d as base64UrlEncode, t as textEncoder, e as textDecoder, f as base64UrlDecode, g as isJWKSet, h as decodePayloadFromB64UrlSegment, v as validateCriticalHeadersJWS, j as validateJwtClaims } from './unjwt.mBSKL6g4.mjs';
|
|
3
|
+
import { s as sign$1, v as verify$1 } from './unjwt.DFAKwqBz.mjs';
|
|
4
4
|
|
|
5
5
|
async function sign(payload, key, options = {}) {
|
|
6
6
|
const { protectedHeader: additionalProtectedHeader } = options;
|
|
7
|
+
const safeAdditionalHeader = sanitizeObject(
|
|
8
|
+
additionalProtectedHeader
|
|
9
|
+
);
|
|
7
10
|
let { alg } = options;
|
|
8
11
|
if (!alg) {
|
|
9
12
|
if (isJWK(key) && key.alg) {
|
|
@@ -15,11 +18,11 @@ async function sign(payload, key, options = {}) {
|
|
|
15
18
|
validateKeyLength(key, alg);
|
|
16
19
|
const signingKey = await importKey(key, alg);
|
|
17
20
|
const protectedHeader = {
|
|
18
|
-
...
|
|
19
|
-
...isJWK(key) && key.kid ? { kid:
|
|
21
|
+
...safeAdditionalHeader,
|
|
22
|
+
...isJWK(key) && key.kid ? { kid: safeAdditionalHeader?.kid || key.kid } : {},
|
|
20
23
|
// Include kid if available
|
|
21
24
|
alg,
|
|
22
|
-
typ:
|
|
25
|
+
typ: safeAdditionalHeader?.typ
|
|
23
26
|
};
|
|
24
27
|
applyTypCtyDefaults(protectedHeader, payload);
|
|
25
28
|
if (protectedHeader.b64 === true) {
|
|
@@ -64,7 +67,9 @@ async function verify(jws, key, options = {}) {
|
|
|
64
67
|
let protectedHeader;
|
|
65
68
|
try {
|
|
66
69
|
const protectedHeaderString = base64UrlDecode(protectedHeaderEncoded);
|
|
67
|
-
protectedHeader =
|
|
70
|
+
protectedHeader = sanitizeObject(
|
|
71
|
+
JSON.parse(protectedHeaderString)
|
|
72
|
+
);
|
|
68
73
|
} catch (error_) {
|
|
69
74
|
throw new Error(
|
|
70
75
|
`Invalid JWS: Protected header is not valid Base64URL or JSON (${error_ instanceof Error ? error_.message : error_})`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { m as isCryptoKey, k as concatUint8Arrays, d as base64UrlEncode, q as base64Decode,
|
|
1
|
+
import { m as isCryptoKey, k as concatUint8Arrays, d as base64UrlEncode, q as base64Decode, u as base64Encode, s as sanitizeObject, t as textEncoder, r as randomBytes, a as isJWK, f as base64UrlDecode, g as isJWKSet } from './unjwt.mBSKL6g4.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This is a fork of Jose library's utility functions.
|
|
@@ -882,7 +882,7 @@ async function jwkTokey(jwk) {
|
|
|
882
882
|
);
|
|
883
883
|
}
|
|
884
884
|
const { algorithm, keyUsages } = subtleMapping(jwk);
|
|
885
|
-
const keyData = { ...jwk };
|
|
885
|
+
const keyData = { ...sanitizeObject(jwk) };
|
|
886
886
|
delete keyData.alg;
|
|
887
887
|
delete keyData.use;
|
|
888
888
|
return crypto.subtle.importKey(
|
|
@@ -1098,15 +1098,19 @@ async function importKey(key, alg) {
|
|
|
1098
1098
|
return key;
|
|
1099
1099
|
}
|
|
1100
1100
|
if (isJWK(key)) {
|
|
1101
|
-
|
|
1102
|
-
|
|
1101
|
+
const safeJwk = sanitizeObject(key);
|
|
1102
|
+
if ("k" in safeJwk && typeof safeJwk.k === "string") {
|
|
1103
|
+
return base64UrlDecode(safeJwk.k, false);
|
|
1103
1104
|
} else {
|
|
1104
|
-
if (!
|
|
1105
|
+
if (!safeJwk.alg && !alg) {
|
|
1105
1106
|
throw new TypeError(
|
|
1106
1107
|
"Algorithm must be provided when importing non-oct JWK"
|
|
1107
1108
|
);
|
|
1108
1109
|
}
|
|
1109
|
-
return jwkTokey({
|
|
1110
|
+
return jwkTokey({
|
|
1111
|
+
...safeJwk,
|
|
1112
|
+
alg: safeJwk.alg || alg
|
|
1113
|
+
});
|
|
1110
1114
|
}
|
|
1111
1115
|
}
|
|
1112
1116
|
throw new Error("Invalid key type provided to importKey");
|
|
@@ -1114,7 +1118,7 @@ async function importKey(key, alg) {
|
|
|
1114
1118
|
async function exportKey(key, jwk) {
|
|
1115
1119
|
const exportedJwk = await keyToJWK(key);
|
|
1116
1120
|
if (jwk) {
|
|
1117
|
-
return { ...exportedJwk, ...jwk };
|
|
1121
|
+
return { ...exportedJwk, ...sanitizeObject(jwk) };
|
|
1118
1122
|
}
|
|
1119
1123
|
return exportedJwk;
|
|
1120
1124
|
}
|
|
@@ -50,6 +50,19 @@ declare function validateCriticalHeadersJWE(protectedHeader: {
|
|
|
50
50
|
crit?: string[];
|
|
51
51
|
} & Record<string, any>, understoodFromOptions?: string[]): void;
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Forked from unsecure@0.0.4
|
|
55
|
+
* Licensed under the MIT License.
|
|
56
|
+
*
|
|
57
|
+
* Source: https://github.com/sandros94/unsecure/blob/913ed5580c551153a19154b4916c67a8efb2be85/src/sanitize.ts
|
|
58
|
+
*/
|
|
59
|
+
/**
|
|
60
|
+
* Remove prototype-pollution vectors from a plain record in-place.
|
|
61
|
+
* This strips __proto__, prototype, and constructor own properties.
|
|
62
|
+
* Returns the same reference for convenience.
|
|
63
|
+
*/
|
|
64
|
+
declare function sanitizeObject<T extends Record<string, unknown> | undefined>(obj: T): T;
|
|
65
|
+
|
|
53
66
|
declare const textEncoder: TextEncoder;
|
|
54
67
|
declare const textDecoder: TextDecoder;
|
|
55
68
|
declare function base64Encode(data: Uint8Array<ArrayBuffer> | string): string;
|
|
@@ -91,6 +104,7 @@ declare const index_isJWKSet: typeof isJWKSet;
|
|
|
91
104
|
declare const index_isJsonContent: typeof isJsonContent;
|
|
92
105
|
declare const index_maybeArray: typeof maybeArray;
|
|
93
106
|
declare const index_randomBytes: typeof randomBytes;
|
|
107
|
+
declare const index_sanitizeObject: typeof sanitizeObject;
|
|
94
108
|
declare const index_textDecoder: typeof textDecoder;
|
|
95
109
|
declare const index_textEncoder: typeof textEncoder;
|
|
96
110
|
declare const index_validateCriticalHeadersJWE: typeof validateCriticalHeadersJWE;
|
|
@@ -117,6 +131,7 @@ declare namespace index {
|
|
|
117
131
|
index_isJsonContent as isJsonContent,
|
|
118
132
|
index_maybeArray as maybeArray,
|
|
119
133
|
index_randomBytes as randomBytes,
|
|
134
|
+
index_sanitizeObject as sanitizeObject,
|
|
120
135
|
index_textDecoder as textDecoder,
|
|
121
136
|
index_textEncoder as textEncoder,
|
|
122
137
|
index_validateCriticalHeadersJWE as validateCriticalHeadersJWE,
|
|
@@ -125,4 +140,4 @@ declare namespace index {
|
|
|
125
140
|
};
|
|
126
141
|
}
|
|
127
142
|
|
|
128
|
-
export { textDecoder as a, base64Encode as b, base64UrlEncode as c, base64Decode as d, base64UrlDecode as e, concatUint8Arrays as f, isJWK as g, isJWKSet as h, index as i, assertCryptoKey as j, isCryptoKey as k, isCryptoKeyPair as l, maybeArray as m, applyTypCtyDefaults as n, isJsonContent as o, decodeMaybeJsonString as p, decodePayloadFromBytes as q, randomBytes as r, decodePayloadFromB64UrlSegment as s, textEncoder as t, getPlaintextBytes as u, computeJwtTimeClaims as v, validateJwtClaims as w, validateCriticalHeadersJWS as x, validateCriticalHeadersJWE as y };
|
|
143
|
+
export { textDecoder as a, base64Encode as b, base64UrlEncode as c, base64Decode as d, base64UrlDecode as e, concatUint8Arrays as f, isJWK as g, isJWKSet as h, index as i, assertCryptoKey as j, isCryptoKey as k, isCryptoKeyPair as l, maybeArray as m, applyTypCtyDefaults as n, isJsonContent as o, decodeMaybeJsonString as p, decodePayloadFromBytes as q, randomBytes as r, decodePayloadFromB64UrlSegment as s, textEncoder as t, getPlaintextBytes as u, computeJwtTimeClaims as v, validateJwtClaims as w, validateCriticalHeadersJWS as x, validateCriticalHeadersJWE as y, sanitizeObject as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, x as JWK_PBES2, D as DeriveKeyOptions, c as DeriveKeyReturn, l as JWK_oct, m as JWK, K as KeyManagementAlgorithm, W as WrapKeyOptions, e as WrapKeyResult, U as UnwrapKeyOptions, F as JWKPEMAlgorithm, n as JWKSet, H as JoseHeaderParameters, C as CompositeKey, d as ContentEncryptionAlgorithm, E as JWKAlgorithm, J as JWKParameters, v as JWK_AES_CBC_HMAC, w as JWK_AES_GCM, u as JWK_AES_GCM_KW, t as JWK_AES_KW, B as JWK_Asymmetric_Algorithm, h as JWK_EC, y as JWK_ECDH_ES, r as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, z as JWK_ED, o as JWK_HMAC, k as JWK_RSA, s as JWK_RSA_ENC, q as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, p as JWK_RSA_SIGN, A as JWK_Symmetric_Algorithm } from './unjwt.CN1C8TlR.mjs';
|
|
1
|
+
import { G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, x as JWK_PBES2, D as DeriveKeyOptions, c as DeriveKeyReturn, l as JWK_oct, m as JWK, K as KeyManagementAlgorithm, W as WrapKeyOptions, e as WrapKeyResult, U as UnwrapKeyOptions, F as JWKPEMAlgorithm, n as JWKSet, H as JoseHeaderParameters, C as CompositeKey, d as ContentEncryptionAlgorithm, E as JWKAlgorithm, J as JWKParameters, v as JWK_AES_CBC_HMAC, w as JWK_AES_GCM, u as JWK_AES_GCM_KW, t as JWK_AES_KW, B as JWK_Asymmetric_Algorithm, h as JWK_EC, y as JWK_ECDH_ES, r as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, z as JWK_ED, o as JWK_HMAC, k as JWK_RSA, s as JWK_RSA_ENC, q as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, p as JWK_RSA_SIGN, A as JWK_Symmetric_Algorithm, L as JWT, M as JWTClaimValidationOptions, I as JWTClaims } from './unjwt.CN1C8TlR.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This is a fork of Jose library's utility functions.
|
|
@@ -153,6 +153,10 @@ declare const jwk_JWK_RSA_Public: typeof JWK_RSA_Public;
|
|
|
153
153
|
declare const jwk_JWK_RSA_SIGN: typeof JWK_RSA_SIGN;
|
|
154
154
|
declare const jwk_JWK_Symmetric_Algorithm: typeof JWK_Symmetric_Algorithm;
|
|
155
155
|
declare const jwk_JWK_oct: typeof JWK_oct;
|
|
156
|
+
declare const jwk_JWT: typeof JWT;
|
|
157
|
+
declare const jwk_JWTClaimValidationOptions: typeof JWTClaimValidationOptions;
|
|
158
|
+
declare const jwk_JWTClaims: typeof JWTClaims;
|
|
159
|
+
declare const jwk_JoseHeaderParameters: typeof JoseHeaderParameters;
|
|
156
160
|
declare const jwk_KeyManagementAlgorithm: typeof KeyManagementAlgorithm;
|
|
157
161
|
declare const jwk_UnwrapKeyOptions: typeof UnwrapKeyOptions;
|
|
158
162
|
declare const jwk_WrapKeyOptions: typeof WrapKeyOptions;
|
|
@@ -201,6 +205,10 @@ declare namespace jwk {
|
|
|
201
205
|
jwk_JWK_RSA_SIGN as JWK_RSA_SIGN,
|
|
202
206
|
jwk_JWK_Symmetric_Algorithm as JWK_Symmetric_Algorithm,
|
|
203
207
|
jwk_JWK_oct as JWK_oct,
|
|
208
|
+
jwk_JWT as JWT,
|
|
209
|
+
jwk_JWTClaimValidationOptions as JWTClaimValidationOptions,
|
|
210
|
+
jwk_JWTClaims as JWTClaims,
|
|
211
|
+
jwk_JoseHeaderParameters as JoseHeaderParameters,
|
|
204
212
|
jwk_KeyManagementAlgorithm as KeyManagementAlgorithm,
|
|
205
213
|
jwk_UnwrapKeyOptions as UnwrapKeyOptions,
|
|
206
214
|
jwk_WrapKeyOptions as WrapKeyOptions,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as checkEncCryptoKey, u as uint32be, b as generateCEK, e as encryptIV, w as wrap, k as keyToJWK, d as bitLengthCEK, f as jwkTokey, i as importKey, h as generateIV, l as encrypt$1, m as unwrapKey, n as decrypt$1 } from './unjwt.
|
|
2
|
-
import { k as concatUint8Arrays, t as textEncoder, l as assertCryptoKey, d as base64UrlEncode, m as isCryptoKey, a as isJWK, f as base64UrlDecode, r as randomBytes, b as applyTypCtyDefaults, c as computeJwtTimeClaims, n as getPlaintextBytes, o as decodePayloadFromBytes, p as validateCriticalHeadersJWE } from './unjwt.
|
|
3
|
-
import { c as checkKeyLength } from './unjwt.
|
|
1
|
+
import { a as checkEncCryptoKey, u as uint32be, b as generateCEK, e as encryptIV, w as wrap, k as keyToJWK, d as bitLengthCEK, f as jwkTokey, i as importKey, h as generateIV, l as encrypt$1, m as unwrapKey, n as decrypt$1 } from './unjwt.CX8WRx20.mjs';
|
|
2
|
+
import { k as concatUint8Arrays, t as textEncoder, l as assertCryptoKey, d as base64UrlEncode, m as isCryptoKey, a as isJWK, s as sanitizeObject, f as base64UrlDecode, r as randomBytes, b as applyTypCtyDefaults, c as computeJwtTimeClaims, n as getPlaintextBytes, o as decodePayloadFromBytes, p as validateCriticalHeadersJWE } from './unjwt.mBSKL6g4.mjs';
|
|
3
|
+
import { c as checkKeyLength } from './unjwt.DFAKwqBz.mjs';
|
|
4
4
|
|
|
5
5
|
function lengthAndInput(input) {
|
|
6
6
|
return concatUint8Arrays(uint32be(input.length), input);
|
|
@@ -183,10 +183,11 @@ async function normalizeKey(key, alg) {
|
|
|
183
183
|
return key;
|
|
184
184
|
}
|
|
185
185
|
if (isJWK(key)) {
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
const safeJwk = sanitizeObject(key);
|
|
187
|
+
if ("k" in safeJwk && safeJwk.k) {
|
|
188
|
+
return base64UrlDecode(safeJwk.k, false);
|
|
188
189
|
}
|
|
189
|
-
return jwkTokey({ ...
|
|
190
|
+
return jwkTokey({ ...safeJwk, alg });
|
|
190
191
|
}
|
|
191
192
|
throw new Error("unreachable");
|
|
192
193
|
}
|
|
@@ -245,12 +246,12 @@ async function encrypt(payload, key, options = {}) {
|
|
|
245
246
|
const baseProtectedHeader = { ...additionalProtectedHeader };
|
|
246
247
|
delete baseProtectedHeader.alg;
|
|
247
248
|
delete baseProtectedHeader.enc;
|
|
248
|
-
const jweProtectedHeader = {
|
|
249
|
+
const jweProtectedHeader = sanitizeObject({
|
|
249
250
|
...baseProtectedHeader,
|
|
250
251
|
...keyManagementHeaderParams,
|
|
251
252
|
alg,
|
|
252
253
|
enc
|
|
253
|
-
};
|
|
254
|
+
});
|
|
254
255
|
const protectedHeader = applyTypCtyDefaults(jweProtectedHeader, payload);
|
|
255
256
|
const computedPayload = computeJwtTimeClaims(
|
|
256
257
|
payload,
|
|
@@ -309,7 +310,9 @@ async function decrypt(jwe, key, options) {
|
|
|
309
310
|
let protectedHeader;
|
|
310
311
|
try {
|
|
311
312
|
const protectedHeaderJson = base64UrlDecode(protectedHeaderEncoded);
|
|
312
|
-
protectedHeader =
|
|
313
|
+
protectedHeader = sanitizeObject(
|
|
314
|
+
JSON.parse(protectedHeaderJson)
|
|
315
|
+
);
|
|
313
316
|
} catch (error_) {
|
|
314
317
|
throw new Error(
|
|
315
318
|
`Invalid JWE: Protected header is not valid Base64URL or JSON (${error_ instanceof Error ? error_.message : error_})`
|
|
@@ -20,7 +20,8 @@ function decodeMaybeJsonString(decodedString, header) {
|
|
|
20
20
|
const looksLikeJson = decodedString.startsWith("{") && decodedString.endsWith("}") || decodedString.startsWith("[") && decodedString.endsWith("]");
|
|
21
21
|
if (looksLikeJson) {
|
|
22
22
|
try {
|
|
23
|
-
|
|
23
|
+
const obj = JSON.parse(decodedString);
|
|
24
|
+
return sanitizeObject(obj);
|
|
24
25
|
} catch {
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -193,6 +194,55 @@ function validateCriticalHeadersJWE(protectedHeader, understoodFromOptions) {
|
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
|
|
197
|
+
const DANGEROUS_KEYS = ["__proto__", "prototype", "constructor"];
|
|
198
|
+
function sanitizeObject(obj) {
|
|
199
|
+
if (!obj || typeof obj !== "object") return obj;
|
|
200
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
201
|
+
visit(obj, seen);
|
|
202
|
+
return obj;
|
|
203
|
+
}
|
|
204
|
+
function visit(current, seen) {
|
|
205
|
+
if (!current || typeof current !== "object") return;
|
|
206
|
+
if (seen.has(current)) return;
|
|
207
|
+
seen.add(current);
|
|
208
|
+
for (const key of DANGEROUS_KEYS) {
|
|
209
|
+
if (Object.prototype.hasOwnProperty.call(current, key)) {
|
|
210
|
+
try {
|
|
211
|
+
delete current[key];
|
|
212
|
+
} catch {
|
|
213
|
+
}
|
|
214
|
+
if (Object.prototype.hasOwnProperty.call(current, key)) {
|
|
215
|
+
try {
|
|
216
|
+
current[key] = void 0;
|
|
217
|
+
delete current[key];
|
|
218
|
+
} catch {
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (Object.prototype.hasOwnProperty.call(current, key)) {
|
|
222
|
+
try {
|
|
223
|
+
Object.defineProperty(current, key, {
|
|
224
|
+
value: void 0,
|
|
225
|
+
configurable: true,
|
|
226
|
+
enumerable: false,
|
|
227
|
+
writable: true
|
|
228
|
+
});
|
|
229
|
+
delete current[key];
|
|
230
|
+
} catch {
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
delete current["__proto__"];
|
|
236
|
+
delete current["prototype"];
|
|
237
|
+
delete current["constructor"];
|
|
238
|
+
if (Array.isArray(current)) {
|
|
239
|
+
for (const value of current) visit(value, seen);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
for (const k of Object.keys(current))
|
|
243
|
+
visit(current[k], seen);
|
|
244
|
+
}
|
|
245
|
+
|
|
196
246
|
const textEncoder = /* @__PURE__ */ new TextEncoder();
|
|
197
247
|
const textDecoder = /* @__PURE__ */ new TextDecoder();
|
|
198
248
|
function base64Encode(data) {
|
|
@@ -288,6 +338,7 @@ const index = {
|
|
|
288
338
|
isJsonContent: isJsonContent,
|
|
289
339
|
maybeArray: maybeArray,
|
|
290
340
|
randomBytes: randomBytes,
|
|
341
|
+
sanitizeObject: sanitizeObject,
|
|
291
342
|
textDecoder: textDecoder,
|
|
292
343
|
textEncoder: textEncoder,
|
|
293
344
|
validateCriticalHeadersJWE: validateCriticalHeadersJWE,
|
|
@@ -295,4 +346,4 @@ const index = {
|
|
|
295
346
|
validateJwtClaims: validateJwtClaims
|
|
296
347
|
};
|
|
297
348
|
|
|
298
|
-
export { isJWK as a, applyTypCtyDefaults as b, computeJwtTimeClaims as c, base64UrlEncode as d, textDecoder as e, base64UrlDecode as f, isJWKSet as g, decodePayloadFromB64UrlSegment as h, index as i, validateJwtClaims as j, concatUint8Arrays as k, assertCryptoKey as l, isCryptoKey as m, getPlaintextBytes as n, decodePayloadFromBytes as o, validateCriticalHeadersJWE as p, base64Decode as q, randomBytes as r,
|
|
349
|
+
export { isJWK as a, applyTypCtyDefaults as b, computeJwtTimeClaims as c, base64UrlEncode as d, textDecoder as e, base64UrlDecode as f, isJWKSet as g, decodePayloadFromB64UrlSegment as h, index as i, validateJwtClaims as j, concatUint8Arrays as k, assertCryptoKey as l, isCryptoKey as m, getPlaintextBytes as n, decodePayloadFromBytes as o, validateCriticalHeadersJWE as p, base64Decode as q, randomBytes as r, sanitizeObject as s, textEncoder as t, base64Encode as u, validateCriticalHeadersJWS as v, maybeArray as w, isCryptoKeyPair as x, isJsonContent as y, decodeMaybeJsonString as z };
|
package/dist/utils.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import './shared/unjwt.CN1C8TlR.mjs';
|
|
2
|
-
export { n as applyTypCtyDefaults, j as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, v as computeJwtTimeClaims, f as concatUint8Arrays, p as decodeMaybeJsonString, s as decodePayloadFromB64UrlSegment, q as decodePayloadFromBytes, u as getPlaintextBytes, k as isCryptoKey, l as isCryptoKeyPair, g as isJWK, h as isJWKSet, o as isJsonContent, m as maybeArray, r as randomBytes, a as textDecoder, t as textEncoder, y as validateCriticalHeadersJWE, x as validateCriticalHeadersJWS, w as validateJwtClaims } from './shared/unjwt.
|
|
2
|
+
export { n as applyTypCtyDefaults, j as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, v as computeJwtTimeClaims, f as concatUint8Arrays, p as decodeMaybeJsonString, s as decodePayloadFromB64UrlSegment, q as decodePayloadFromBytes, u as getPlaintextBytes, k as isCryptoKey, l as isCryptoKeyPair, g as isJWK, h as isJWKSet, o as isJsonContent, m as maybeArray, r as randomBytes, z as sanitizeObject, a as textDecoder, t as textEncoder, y as validateCriticalHeadersJWE, x as validateCriticalHeadersJWS, w as validateJwtClaims } from './shared/unjwt.Cay_cOOI.mjs';
|
package/dist/utils.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { b as applyTypCtyDefaults, l as assertCryptoKey, q as base64Decode,
|
|
1
|
+
export { b as applyTypCtyDefaults, l as assertCryptoKey, q as base64Decode, u as base64Encode, f as base64UrlDecode, d as base64UrlEncode, c as computeJwtTimeClaims, k as concatUint8Arrays, z as decodeMaybeJsonString, h as decodePayloadFromB64UrlSegment, o as decodePayloadFromBytes, n as getPlaintextBytes, m as isCryptoKey, x as isCryptoKeyPair, a as isJWK, g as isJWKSet, y as isJsonContent, w as maybeArray, r as randomBytes, s as sanitizeObject, e as textDecoder, t as textEncoder, p as validateCriticalHeadersJWE, v as validateCriticalHeadersJWS, j as validateJwtClaims } from './shared/unjwt.mBSKL6g4.mjs';
|