@lowdefy/ajv 5.5.1 → 6.0.0

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.
Files changed (2) hide show
  1. package/dist/ajvInstance.js +13 -13
  2. package/package.json +5 -5
@@ -16,25 +16,25 @@
16
16
  import addFormats from 'ajv-formats';
17
17
  import addKeywords from 'ajv-keywords';
18
18
  import ajvErrors from 'ajv-errors';
19
- // Hard cap on errors collected per generated validator function.
19
+ // Cap on the error objects a generated validator retains.
20
20
  // `allErrors: true` is required for ajv-errors (errorMessage:), but without a
21
21
  // cap an attacker can make Ajv allocate an unbounded number of error objects
22
22
  // (CodeQL js/resource-exhaustion-from-deep-object-traversal). The code.process
23
- // hook below rewrites every `errors++;` site to early-exit at this threshold,
24
- // bounding memory at ~MAX_VALIDATION_ERRORS * ~500 bytes per validate() call.
23
+ // hook below truncates each validator's error array at this threshold, bounding
24
+ // retained memory at ~MAX_VALIDATION_ERRORS * ~500 bytes per validate() call.
25
25
  const MAX_VALIDATION_ERRORS = 20;
26
26
  // Ajv 8 emits the exact pattern `errors++;` after every error push (see
27
- // ajv/lib/compile/errors.ts addError), and ends each generated validator with
28
- // `<validateName>.errors = vErrors; return errors === 0;`. We inject a
29
- // `<validateName>.errors = vErrors; return false;` guard immediately after
30
- // each `errors++;` so the validator stops walking the input once the cap is
31
- // reached *and* the caller still sees the (capped) errors array on the
32
- // function's `.errors` property — which is how `ajv.errors` is populated.
27
+ // ajv/lib/compile/errors.ts addError), which makes it the one hook point that
28
+ // sees every allocation. Truncate there; never early-exit. A `oneOf`/`anyOf` is
29
+ // only decided once every branch has been tried, and each branch that rejects
30
+ // the data pushes an error per item it rejects — so returning false at the cap
31
+ // abandoned the walk before the branch that would have matched was reached. A
32
+ // `oneOf` of differently-typed arrays then rejected any list longer than a
33
+ // handful of entries whatever it held, since the earlier branches alone spent
34
+ // the budget. Counting is left alone, so `errors === 0` still decides validity
35
+ // and only the retained objects are bounded.
33
36
  function capErrors(code) {
34
- const fnMatch = code.match(/return\s+function\s+(\w+)\s*\(/);
35
- if (!fnMatch) return code;
36
- const fnName = fnMatch[1];
37
- return code.replace(/errors\+\+;/g, `errors++;if(errors>=${MAX_VALIDATION_ERRORS}){${fnName}.errors=vErrors;return false;}`);
37
+ return code.replace(/errors\+\+;/g, `errors++;if(vErrors!==null&&vErrors.length>${MAX_VALIDATION_ERRORS}){vErrors.length=${MAX_VALIDATION_ERRORS};}`);
38
38
  }
39
39
  const ajv = new Ajv({
40
40
  // codeql[js/resource-exhaustion-from-deep-object-traversal] -- bounded by capErrors() above
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/ajv",
3
- "version": "5.5.1",
3
+ "version": "6.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -33,15 +33,15 @@
33
33
  "dist/*"
34
34
  ],
35
35
  "dependencies": {
36
- "@lowdefy/nunjucks": "5.5.1",
37
- "ajv": "8.12.0",
36
+ "@lowdefy/nunjucks": "6.0.0",
37
+ "ajv": "8.20.0",
38
38
  "ajv-errors": "3.0.0",
39
39
  "ajv-formats": "2.1.1",
40
40
  "ajv-keywords": "5.1.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@swc/cli": "0.8.0",
44
- "@swc/core": "1.15.18",
43
+ "@swc/cli": "0.8.1",
44
+ "@swc/core": "1.15.32",
45
45
  "@swc/jest": "0.2.39",
46
46
  "jest": "28.1.3"
47
47
  },