z-schema 12.0.0 → 12.0.2
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/README.md +12 -5
- package/bin/z-schema +28 -1
- package/cjs/index.d.ts +8 -0
- package/cjs/index.js +330 -212
- package/dist/format-validators.js +38 -2
- package/dist/json-schema.js +1 -1
- package/dist/report.js +13 -4
- package/dist/schema-cache.js +21 -7
- package/dist/schema-compiler.js +33 -9
- package/dist/types/utils/constants.d.ts +19 -0
- package/dist/types/z-schema-base.d.ts +10 -1
- package/dist/types/z-schema-options.d.ts +2 -1
- package/dist/utils/clone.js +1 -1
- package/dist/utils/constants.js +19 -0
- package/dist/utils/json.js +1 -1
- package/dist/utils/schema-regex.js +12 -0
- package/dist/validation/array.js +1 -2
- package/dist/validation/combinators.js +6 -7
- package/dist/validation/object.js +3 -4
- package/dist/validation/string.js +2 -10
- package/dist/z-schema-base.js +10 -0
- package/dist/z-schema-options.js +6 -1
- package/package.json +3 -1
- package/src/format-validators.ts +31 -2
- package/src/json-schema.ts +1 -1
- package/src/report.ts +14 -4
- package/src/schema-cache.ts +22 -7
- package/src/schema-compiler.ts +38 -9
- package/src/utils/clone.ts +1 -1
- package/src/utils/constants.ts +21 -0
- package/src/utils/json.ts +1 -1
- package/src/utils/schema-regex.ts +14 -0
- package/src/validation/array.ts +1 -2
- package/src/validation/combinators.ts +6 -7
- package/src/validation/object.ts +3 -4
- package/src/validation/string.ts +2 -10
- package/src/z-schema-base.ts +11 -0
- package/src/z-schema-options.ts +7 -1
- package/umd/ZSchema.js +330 -212
- package/umd/ZSchema.min.js +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Fast, lightweight JSON Schema validator for Node.js and browsers with **full sup
|
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/z-schema)
|
|
6
6
|
|
|
7
|
-
[](docs/test-coverage.md)
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -330,6 +330,13 @@ Big thanks to:
|
|
|
330
330
|
<sub><b>Geraint</b></sub>
|
|
331
331
|
</a>
|
|
332
332
|
</td>
|
|
333
|
+
<td align="center">
|
|
334
|
+
<a href="https://github.com/lirenhe">
|
|
335
|
+
<img src="https://avatars.githubusercontent.com/u/9100546?v=4" width="100;" alt="lirenhe"/>
|
|
336
|
+
<br />
|
|
337
|
+
<sub><b>Renhe Li</b></sub>
|
|
338
|
+
</a>
|
|
339
|
+
</td>
|
|
333
340
|
<td align="center">
|
|
334
341
|
<a href="https://github.com/dgerber">
|
|
335
342
|
<img src="https://avatars.githubusercontent.com/u/393344?v=4" width="100;" alt="dgerber"/>
|
|
@@ -358,6 +365,8 @@ Big thanks to:
|
|
|
358
365
|
<sub><b>barrtender</b></sub>
|
|
359
366
|
</a>
|
|
360
367
|
</td>
|
|
368
|
+
</tr>
|
|
369
|
+
<tr>
|
|
361
370
|
<td align="center">
|
|
362
371
|
<a href="https://github.com/RomanHotsiy">
|
|
363
372
|
<img src="https://avatars.githubusercontent.com/u/3975738?v=4" width="100;" alt="RomanHotsiy"/>
|
|
@@ -365,8 +374,6 @@ Big thanks to:
|
|
|
365
374
|
<sub><b>Roman Hotsiy</b></sub>
|
|
366
375
|
</a>
|
|
367
376
|
</td>
|
|
368
|
-
</tr>
|
|
369
|
-
<tr>
|
|
370
377
|
<td align="center">
|
|
371
378
|
<a href="https://github.com/sauvainr">
|
|
372
379
|
<img src="https://avatars.githubusercontent.com/u/1715747?v=4" width="100;" alt="sauvainr"/>
|
|
@@ -402,6 +409,8 @@ Big thanks to:
|
|
|
402
409
|
<sub><b>José F. Romaniello</b></sub>
|
|
403
410
|
</a>
|
|
404
411
|
</td>
|
|
412
|
+
</tr>
|
|
413
|
+
<tr>
|
|
405
414
|
<td align="center">
|
|
406
415
|
<a href="https://github.com/KEIII">
|
|
407
416
|
<img src="https://avatars.githubusercontent.com/u/1167833?v=4" width="100;" alt="KEIII"/>
|
|
@@ -409,8 +418,6 @@ Big thanks to:
|
|
|
409
418
|
<sub><b>Ivan Kasenkov</b></sub>
|
|
410
419
|
</a>
|
|
411
420
|
</td>
|
|
412
|
-
</tr>
|
|
413
|
-
<tr>
|
|
414
421
|
<td align="center">
|
|
415
422
|
<a href="https://github.com/HanOterLin">
|
|
416
423
|
<img src="https://avatars.githubusercontent.com/u/21137108?v=4" width="100;" alt="HanOterLin"/>
|
package/bin/z-schema
CHANGED
|
@@ -104,7 +104,34 @@ function validateWithAutomaticDownloads(filePath, data, schema, callback) {
|
|
|
104
104
|
var urlString = 'request: ' + url + ' - ';
|
|
105
105
|
|
|
106
106
|
if (url.match(/^https?:/)) {
|
|
107
|
-
|
|
107
|
+
var parsedUrl;
|
|
108
|
+
try {
|
|
109
|
+
parsedUrl = new URL(url);
|
|
110
|
+
} catch (_e) {
|
|
111
|
+
console.error('Invalid URL: ' + url);
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
// Guard against SSRF: only allow https and reject private/internal hostnames (CWE-918)
|
|
115
|
+
if (parsedUrl.protocol !== 'https:') {
|
|
116
|
+
console.error('Only HTTPS URLs are allowed for remote references: ' + url);
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
var hostname = parsedUrl.hostname;
|
|
120
|
+
if (
|
|
121
|
+
hostname === 'localhost' ||
|
|
122
|
+
hostname === '127.0.0.1' ||
|
|
123
|
+
hostname === '::1' ||
|
|
124
|
+
hostname === '0.0.0.0' ||
|
|
125
|
+
hostname.endsWith('.local') ||
|
|
126
|
+
hostname.startsWith('10.') ||
|
|
127
|
+
hostname.startsWith('192.168.') ||
|
|
128
|
+
/^172\.(1[6-9]|2\d|3[01])\./.test(hostname) ||
|
|
129
|
+
hostname.startsWith('169.254.')
|
|
130
|
+
) {
|
|
131
|
+
console.error('Requests to private/internal addresses are not allowed: ' + url);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
request(parsedUrl, function (response) {
|
|
108
135
|
var body = '';
|
|
109
136
|
response.on('data', function (chunk) {
|
|
110
137
|
body += chunk;
|
package/cjs/index.d.ts
CHANGED
|
@@ -231,6 +231,14 @@ declare class ZSchemaBase {
|
|
|
231
231
|
validateOptions: ValidateOptions;
|
|
232
232
|
options: ZSchemaOptions;
|
|
233
233
|
constructor(options: ZSchemaOptions | undefined, token: symbol);
|
|
234
|
+
/**
|
|
235
|
+
* Internal recursive JSON validation — delegates to the `validate` function
|
|
236
|
+
* in `json-validation.ts`. Exposed as a method so that per-keyword validator
|
|
237
|
+
* modules (array, combinators, object) can call back into the core validator
|
|
238
|
+
* via `this` without importing `json-validation.ts` directly (which would
|
|
239
|
+
* create a circular dependency).
|
|
240
|
+
*/
|
|
241
|
+
_jsonValidate(report: Report, schema: boolean | JsonSchemaInternal, json: unknown): boolean;
|
|
234
242
|
getDefaultSchemaId(): string;
|
|
235
243
|
_validate(json: unknown, schema: JsonSchema | string, options: ValidateOptions, callback: ValidateCallback): void;
|
|
236
244
|
_validate(json: unknown, schema: JsonSchema | string, callback: ValidateCallback): void;
|