jose 6.2.14 → 6.2.16

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.
@@ -13,9 +13,10 @@ async function generalDecrypt(jwe, key, options) {
13
13
  throw new JWEInvalid("JWE Recipients missing or incorrect type");
14
14
  if (!recipients.length)
15
15
  throw new JWEInvalid("JWE Recipients has no members");
16
- let shared, sharedJwe, token;
16
+ const shared = prepareDecrypt(options);
17
+ let sharedJwe, token;
17
18
  try {
18
- shared = prepareDecrypt(options), sharedJwe = snapshotSharedJWE(jwe), token = shareJWE(sharedJwe);
19
+ sharedJwe = snapshotSharedJWE(jwe), token = shareJWE(sharedJwe);
19
20
  } catch {
20
21
  throw new JWEDecryptionFailed();
21
22
  }
@@ -5,7 +5,7 @@ function isCloudflareWorkers() {
5
5
  return typeof WebSocketPair < "u" || typeof navigator < "u" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime < "u" && EdgeRuntime === "vercel";
6
6
  }
7
7
  let USER_AGENT;
8
- (typeof navigator > "u" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) && (USER_AGENT = "jose/v6.2.14");
8
+ (typeof navigator > "u" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) && (USER_AGENT = "jose/v6.2.16");
9
9
  const customFetch = /* @__PURE__ */ Symbol();
10
10
  async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
11
11
  const response = await fetchImpl(url, {
@@ -31,6 +31,8 @@ function isFreshFor(timestamp, duration) {
31
31
  function validateDuration(value, fallback, option) {
32
32
  if (Number.isNaN(value))
33
33
  throw new TypeError(`"${option}" option must not be NaN`);
34
+ if (typeof value == "number" && value < 0)
35
+ throw new TypeError(`"${option}" option must not be negative`);
34
36
  return typeof value == "number" ? value : fallback;
35
37
  }
36
38
  function createRemoteJWKSet(url, options) {
@@ -22,15 +22,9 @@ async function generalVerify(jws, key, options) {
22
22
  const signatureEntries = Array.from(signatures);
23
23
  if (!signatureEntries.every(isObject))
24
24
  throw new JWSInvalid("JWS Signatures missing or incorrect type");
25
- let shared;
26
- try {
27
- if (inputPayload === void 0)
28
- throw new Error();
29
- shared = prepareVerify(options);
30
- } catch {
25
+ if (inputPayload === void 0)
31
26
  throw new JWSSignatureVerificationFailed();
32
- }
33
- const payload = inputPayload instanceof Uint8Array ? new Uint8Array(inputPayload) : inputPayload, candidates = signatureEntries.map((signature) => snapshotSignature(signature, payload)).filter((candidate) => candidate !== void 0);
27
+ const shared = prepareVerify(options), payload = inputPayload instanceof Uint8Array ? new Uint8Array(inputPayload) : inputPayload, candidates = signatureEntries.map((signature) => snapshotSignature(signature, payload)).filter((candidate) => candidate !== void 0);
34
28
  let payloadEncodings = 0;
35
29
  for (const [, , payloadEncoding] of candidates)
36
30
  if (payloadEncodings |= payloadEncoding, payloadEncodings === 3)
@@ -23,7 +23,8 @@ async function transform(stream, input, maxLength = 1 / 0) {
23
23
  if (done)
24
24
  break;
25
25
  if (chunks.push(value), length += value.byteLength, maxLength !== 1 / 0 && length > maxLength)
26
- throw new JWEInvalid("Decompressed plaintext exceeded the configured limit");
26
+ throw await reader.cancel().catch(() => {
27
+ }), new JWEInvalid("Decompressed plaintext exceeded the configured limit");
27
28
  }
28
29
  return concat(...chunks);
29
30
  }
@@ -1,7 +1,7 @@
1
1
  import { decrypt, generateCek } from "./content_encryption.js";
2
2
  import { decodeBase64url, encodeAsciiMember, parseJoseHeader, isDisjoint, isObject, validateCrit, validateAlgorithms, JWE_RECOGNIZED } from "./validate.js";
3
3
  import { JOSEAlgNotAllowed, JOSENotSupported, JWEInvalid } from "../util/errors.js";
4
- import { decryptKeyManagement } from "./key_management.js";
4
+ import { decryptKeyManagement, validateMaxPBES2Count } from "./key_management.js";
5
5
  import { decoder } from "./buffer_utils.js";
6
6
  import { prepareKey } from "./key.js";
7
7
  import { JWE, isJWECEKTransport, jweAlgorithm, jweEncryption } from "./jwe_algorithms.js";
@@ -69,12 +69,17 @@ function shareJWE(jwe) {
69
69
  ];
70
70
  }
71
71
  function prepareDecrypt(options) {
72
+ const keyManagementAlgorithms = options && validateAlgorithms("keyManagementAlgorithms", options.keyManagementAlgorithms), contentEncryptionAlgorithms = options && validateAlgorithms("contentEncryptionAlgorithms", options.contentEncryptionAlgorithms), { crit, maxPBES2Count, maxDecompressedLength } = options ?? {};
73
+ validateMaxPBES2Count(maxPBES2Count);
74
+ const decompressionLimit = maxDecompressedLength ?? 25e4;
75
+ if (decompressionLimit !== 0 && decompressionLimit !== 1 / 0 && (!Number.isSafeInteger(decompressionLimit) || decompressionLimit < 1))
76
+ throw new TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");
72
77
  return [
73
- options && validateAlgorithms("keyManagementAlgorithms", options.keyManagementAlgorithms),
74
- options && validateAlgorithms("contentEncryptionAlgorithms", options.contentEncryptionAlgorithms),
75
- options?.crit,
76
- options?.maxPBES2Count,
77
- options?.maxDecompressedLength
78
+ keyManagementAlgorithms,
79
+ contentEncryptionAlgorithms,
80
+ crit,
81
+ maxPBES2Count,
82
+ maxDecompressedLength
78
83
  ];
79
84
  }
80
85
  async function decryptJWE(jwe, shared, key, token = shareJWE(jwe)) {
@@ -145,8 +150,6 @@ async function decryptJWE(jwe, shared, key, token = shareJWE(jwe)) {
145
150
  const decompressionLimit = maxDecompressedLength ?? 25e4;
146
151
  if (decompressionLimit === 0)
147
152
  throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
148
- if (decompressionLimit !== 1 / 0 && (!Number.isSafeInteger(decompressionLimit) || decompressionLimit < 1))
149
- throw new TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");
150
153
  plaintext = await decompress(plaintext, decompressionLimit).catch((cause) => {
151
154
  throw cause instanceof JWEInvalid ? cause : new JWEInvalid("Failed to decompress plaintext", { cause });
152
155
  });
@@ -77,7 +77,8 @@ function validateClaimsSet(protectedHeader, claimsSetBytes, options = {}) {
77
77
  throw new TypeError("Invalid clockTolerance option type");
78
78
  tolerance = clockTolerance;
79
79
  }
80
- validateInput("clockTolerance option", tolerance);
80
+ if (validateInput("clockTolerance option", tolerance), tolerance < 0)
81
+ throw new TypeError("Invalid clockTolerance option input");
81
82
  const { currentDate } = options, now = validateInput("currentDate option", epoch(currentDate === void 0 ? /* @__PURE__ */ new Date() : currentDate)), iat = validateNumericDate(claimsSet, "iat", maxTokenAge !== void 0), nbf = validateNumericDate(claimsSet, "nbf");
82
83
  if (nbf !== void 0 && nbf > now + tolerance)
83
84
  throw new JWTClaimValidationFailed('"nbf" claim timestamp check failed', claimsSet, "nbf", checkFailed);
@@ -111,7 +111,6 @@ async function decryptKeyManagement(entry, enc, key, encryptedKey, joseHeader, m
111
111
  case "PBKDF2": {
112
112
  if (typeof joseHeader.p2c != "number")
113
113
  throw new JWEInvalid('JOSE Header "p2c" (PBES2 Count) missing or invalid');
114
- validateMaxPBES2Count(maxPBES2Count);
115
114
  const p2cLimit = maxPBES2Count ?? 1e4;
116
115
  if (joseHeader.p2c > p2cLimit)
117
116
  throw new JWEInvalid('JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jose",
3
- "version": "6.2.14",
3
+ "version": "6.2.16",
4
4
  "description": "JWA, JWS, JWE, JWT, JWK, JWKS for Node.js, Browser, Cloudflare Workers, Deno, Bun, and other Web-interoperable runtimes",
5
5
  "keywords": [
6
6
  "akp",