@scenarist/core 0.4.11 → 0.4.14
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/domain/regex-matching.d.ts +14 -1
- package/dist/domain/regex-matching.d.ts.map +1 -1
- package/dist/domain/regex-matching.js +32 -6
- package/dist/domain/response-selector.js +2 -5
- package/dist/schemas/match-criteria.d.ts.map +1 -1
- package/dist/schemas/match-criteria.js +8 -2
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type SerializedRegex } from "../schemas/match-criteria.js";
|
|
2
2
|
/**
|
|
3
3
|
* Match a value against a regex pattern.
|
|
4
4
|
*
|
|
@@ -17,4 +17,17 @@ import type { SerializedRegex } from "../schemas/match-criteria.js";
|
|
|
17
17
|
* @returns true if pattern matches, false otherwise
|
|
18
18
|
*/
|
|
19
19
|
export declare const matchesRegex: (value: string, pattern: SerializedRegex) => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Match a value against a native RegExp from trusted developer code.
|
|
22
|
+
*
|
|
23
|
+
* **Security:**
|
|
24
|
+
* - Bypasses serialized regex validation intentionally for native RegExp scenario criteria
|
|
25
|
+
* - Do not use with patterns derived from serialized data or user input
|
|
26
|
+
* - Reconstructs from source and flags before testing to avoid mutating caller-owned lastIndex state
|
|
27
|
+
*
|
|
28
|
+
* @param value - String to test against pattern
|
|
29
|
+
* @param pattern - Native RegExp from trusted code
|
|
30
|
+
* @returns true if pattern matches, false otherwise
|
|
31
|
+
*/
|
|
32
|
+
export declare const matchesTrustedNativeRegex: (value: string, pattern: RegExp) => boolean;
|
|
20
33
|
//# sourceMappingURL=regex-matching.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regex-matching.d.ts","sourceRoot":"","sources":["../../src/domain/regex-matching.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"regex-matching.d.ts","sourceRoot":"","sources":["../../src/domain/regex-matching.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,8BAA8B,CAAC;AAiBtC;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,YAAY,GACvB,OAAO,MAAM,EACb,SAAS,eAAe,KACvB,OAQF,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,yBAAyB,GACpC,OAAO,MAAM,EACb,SAAS,MAAM,KACd,OAKF,CAAC"}
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import { SerializedRegexSchema, } from "../schemas/match-criteria.js";
|
|
2
|
+
const testRegex = (value, pattern) => {
|
|
3
|
+
try {
|
|
4
|
+
// eslint-disable-next-line security/detect-non-literal-regexp -- Serialized patterns are schema-validated and native RegExp inputs are trusted code.
|
|
5
|
+
const regex = new RegExp(pattern.source, pattern.flags); // nosemgrep
|
|
6
|
+
return regex.test(value);
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
1
12
|
/**
|
|
2
13
|
* Match a value against a regex pattern.
|
|
3
14
|
*
|
|
@@ -16,12 +27,27 @@
|
|
|
16
27
|
* @returns true if pattern matches, false otherwise
|
|
17
28
|
*/
|
|
18
29
|
export const matchesRegex = (value, pattern) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const regex = new RegExp(pattern.source, pattern.flags); // nosemgrep
|
|
22
|
-
return regex.test(value);
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
30
|
+
const validationResult = SerializedRegexSchema.safeParse(pattern);
|
|
31
|
+
if (!validationResult.success) {
|
|
25
32
|
return false;
|
|
26
33
|
}
|
|
34
|
+
return testRegex(value, validationResult.data);
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Match a value against a native RegExp from trusted developer code.
|
|
38
|
+
*
|
|
39
|
+
* **Security:**
|
|
40
|
+
* - Bypasses serialized regex validation intentionally for native RegExp scenario criteria
|
|
41
|
+
* - Do not use with patterns derived from serialized data or user input
|
|
42
|
+
* - Reconstructs from source and flags before testing to avoid mutating caller-owned lastIndex state
|
|
43
|
+
*
|
|
44
|
+
* @param value - String to test against pattern
|
|
45
|
+
* @param pattern - Native RegExp from trusted code
|
|
46
|
+
* @returns true if pattern matches, false otherwise
|
|
47
|
+
*/
|
|
48
|
+
export const matchesTrustedNativeRegex = (value, pattern) => {
|
|
49
|
+
return testRegex(value, {
|
|
50
|
+
source: pattern.source,
|
|
51
|
+
flags: pattern.flags,
|
|
52
|
+
});
|
|
27
53
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ScenaristError, ErrorCodes } from "../types/errors.js";
|
|
2
2
|
import { extractFromPath } from "./path-extraction.js";
|
|
3
3
|
import { applyTemplates } from "./template-replacement.js";
|
|
4
|
-
import { matchesRegex } from "./regex-matching.js";
|
|
4
|
+
import { matchesRegex, matchesTrustedNativeRegex } from "./regex-matching.js";
|
|
5
5
|
import { createStateResponseResolver } from "./state-response-resolver.js";
|
|
6
6
|
import { deepEquals } from "./deep-equals.js";
|
|
7
7
|
import { isRecord } from "./type-guards.js";
|
|
@@ -469,10 +469,7 @@ const matchesValue = (requestValue, criteriaValue) => {
|
|
|
469
469
|
}
|
|
470
470
|
// Native RegExp support (ADR-0016)
|
|
471
471
|
if (criteriaValue instanceof RegExp) {
|
|
472
|
-
return
|
|
473
|
-
source: criteriaValue.source,
|
|
474
|
-
flags: criteriaValue.flags,
|
|
475
|
-
});
|
|
472
|
+
return matchesTrustedNativeRegex(requestValue, criteriaValue);
|
|
476
473
|
}
|
|
477
474
|
if (typeof criteriaValue === "number" || typeof criteriaValue === "boolean") {
|
|
478
475
|
return requestValue === String(criteriaValue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match-criteria.d.ts","sourceRoot":"","sources":["../../src/schemas/match-criteria.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"match-criteria.d.ts","sourceRoot":"","sources":["../../src/schemas/match-criteria.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgDxB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,qBAAqB;;;iBAchC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
|
|
@@ -29,13 +29,19 @@ const VALID_REGEX_FLAGS = /^[gimsuvy]*$/;
|
|
|
29
29
|
*
|
|
30
30
|
* Uses redos-detector to analyze the pattern for exponential backtracking.
|
|
31
31
|
* Patterns that could cause catastrophic backtracking are rejected.
|
|
32
|
+
* redos-detector errors are treated as unsafe.
|
|
32
33
|
*
|
|
33
34
|
* @param pattern - The regex pattern to validate
|
|
34
35
|
* @returns true if the pattern is safe, false otherwise
|
|
35
36
|
*/
|
|
36
37
|
const isPatternSafeFromReDoS = (pattern) => {
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
try {
|
|
39
|
+
const result = isSafePattern(pattern);
|
|
40
|
+
return result.safe;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
39
45
|
};
|
|
40
46
|
/**
|
|
41
47
|
* Schema for serialized regex patterns.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scenarist/core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.14",
|
|
4
4
|
"description": "Internal: Hexagonal architecture core for scenario-based testing with MSW",
|
|
5
5
|
"author": "Paul Hammond (citypaul) <paul@packsoftware.co.uk>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"zod": "^4.3.6"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@vitest/coverage-v8": "^4.1.
|
|
54
|
-
"@vitest/ui": "^4.1.
|
|
53
|
+
"@vitest/coverage-v8": "^4.1.5",
|
|
54
|
+
"@vitest/ui": "^4.1.5",
|
|
55
55
|
"eslint": "^9.39.4",
|
|
56
56
|
"fast-check": "^4.5.3",
|
|
57
57
|
"typescript": "^5.9.3",
|
|
58
|
-
"vitest": "^4.1.
|
|
58
|
+
"vitest": "^4.1.5",
|
|
59
59
|
"@scenarist/eslint-config": "0.0.0",
|
|
60
60
|
"@scenarist/typescript-config": "0.0.0"
|
|
61
61
|
},
|