bank20baht-validator 0.4.2 → 0.4.3
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.js +2 -21
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// every value must have the shape the UI control could actually emit before
|
|
14
14
|
// the authored validators run.
|
|
15
15
|
// ---------------------------------------------------------------------------
|
|
16
|
-
import { applyFlags, approvalFields, conditionRowRefs, createScriptContext, defaultValue, evaluate, hasScripts, runScripts, getCatalog, normalizeTagsValue, parseDisabledEntry, parseIsoDate, parseIsoDateTime, parseRowRef, resolveViewFields, setCatalog, setLocale, t, validateField, walkPath, normalizeLegacySchema, } from 'bank20baht-ui/engine';
|
|
16
|
+
import { applyFlags, approvalFields, conditionRowRefs, createScriptContext, defaultValue, evaluate, hasScripts, runScripts, getCatalog, normalizeTagsValue, parseDisabledEntry, parseIsoDate, parseIsoDateTime, parseRowRef, resolveViewFields, setCatalog, setLocale, t, isUnsafePattern, validateField, walkPath, normalizeLegacySchema, } from 'bank20baht-ui/engine';
|
|
17
17
|
/**
|
|
18
18
|
* Run `fn` with the catalog switched to `locale`, restoring the previous
|
|
19
19
|
* catalog after. The engine catalog is module-global; validation is fully
|
|
@@ -684,25 +684,6 @@ function assertValidFields(form) {
|
|
|
684
684
|
assertSubFields(field, form.form_name);
|
|
685
685
|
}
|
|
686
686
|
}
|
|
687
|
-
/**
|
|
688
|
-
* True for the textbook ReDoS shape: an unbounded quantifier (`* + {n,}`)
|
|
689
|
-
* applied to a group whose ENTIRE body is one unboundedly-quantified atom —
|
|
690
|
-
* `(a+)+`, `(\d*)*`, `(?:\w+){2,}`. That exact nesting is always either
|
|
691
|
-
* redundant (matches the same language as a single quantifier) or exponential
|
|
692
|
-
* to backtrack, so rejecting it has no legitimate false positives. It is
|
|
693
|
-
* deliberately NARROW: longer bodies like `(abc+)+` are safe (the literal
|
|
694
|
-
* prefix removes the cross-iteration ambiguity) and other catastrophic shapes
|
|
695
|
-
* (e.g. overlapping alternation `(a|a)*`) are out of scope — patterns are
|
|
696
|
-
* builder-authored, so the goal is catching the classic authoring mistake at
|
|
697
|
-
* save time, not sandboxing hostile regexes.
|
|
698
|
-
*/
|
|
699
|
-
function hasNestedUnboundedQuantifier(pattern) {
|
|
700
|
-
// Strip escaped chars and character classes first so `\+`, `[+]` etc.
|
|
701
|
-
// aren't mistaken for quantifiers or group delimiters.
|
|
702
|
-
const stripped = pattern.replace(/\\./g, 'x').replace(/\[[^\]]*\]/g, 'C');
|
|
703
|
-
const unbounded = '(?:[*+]|\\{\\d+,\\})';
|
|
704
|
-
return new RegExp(`\\((?:\\?:)?[^()|]${unbounded}\\??\\)${unbounded}`).test(stripped);
|
|
705
|
-
}
|
|
706
687
|
function assertFieldKey(field, form_name) {
|
|
707
688
|
// labels are static blocks and may omit the key; everything else needs one
|
|
708
689
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- runtime guard: value is untrusted JSON
|
|
@@ -725,7 +706,7 @@ function assertPatternValidator(v, where) {
|
|
|
725
706
|
catch {
|
|
726
707
|
throw new Error(`invalid pattern ${JSON.stringify(v.value)} on ${where}`);
|
|
727
708
|
}
|
|
728
|
-
if (
|
|
709
|
+
if (isUnsafePattern(pattern)) {
|
|
729
710
|
throw new Error(`pattern on ${where} nests unbounded quantifiers ` +
|
|
730
711
|
`(e.g. "(a+)+") — this backtracks catastrophically on hostile input; ` +
|
|
731
712
|
`an equivalent single quantifier matches the same strings`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bank20baht-validator",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Runtime validation for bahtui form/workflow JSON \u2014 the exact engine rules the client runs, on the server.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"vitest": "^3.2.4"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"bank20baht-ui": ">=0.12.
|
|
49
|
+
"bank20baht-ui": ">=0.12.2 <0.13.0"
|
|
50
50
|
},
|
|
51
51
|
"main": "./dist/index.js",
|
|
52
52
|
"types": "./dist/index.d.ts",
|