@hilbras/sdk 4.0.1 → 4.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 +1 -1
- package/dist/features/agent/schema-validator.js +31 -12
- package/dist/security/url-guard.js +13 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
|
-
<img src="https://img.shields.io/badge/version-4.0.
|
|
6
|
+
<img src="https://img.shields.io/badge/version-4.0.2-blue" alt="version">
|
|
7
7
|
<img src="https://img.shields.io/badge/license-MIT-green" alt="license">
|
|
8
8
|
<img src="https://img.shields.io/badge/node-%3E%3D18-brightgreen" alt="node">
|
|
9
9
|
<img src="https://img.shields.io/badge/types-strict-blueviolet" alt="types">
|
|
@@ -8,19 +8,37 @@
|
|
|
8
8
|
* bounds. Unknown keywords are ignored rather than rejected, so richer
|
|
9
9
|
* schemas still work (they are simply less strictly checked here).
|
|
10
10
|
*/
|
|
11
|
+
/**
|
|
12
|
+
* Maximum nesting depth validated before failing closed.
|
|
13
|
+
*
|
|
14
|
+
* Tool arguments come from model output, which an attacker can shape. Without
|
|
15
|
+
* a bound, a deeply nested payload overflows the call stack and takes down the
|
|
16
|
+
* agent loop (RangeError) instead of being rejected as bad input.
|
|
17
|
+
*/
|
|
18
|
+
const MAX_VALIDATION_DEPTH = 64;
|
|
11
19
|
/** Validate a value against the declared JSON Schema subset. */
|
|
12
20
|
export function validateAgainstSchema(value, schema, path = "args") {
|
|
13
21
|
const errors = [];
|
|
22
|
+
validateNode(value, schema, path, 0, errors);
|
|
23
|
+
return { valid: errors.length === 0, errors };
|
|
24
|
+
}
|
|
25
|
+
function validateNode(value, schema, path, depth, errors) {
|
|
26
|
+
if (depth > MAX_VALIDATION_DEPTH) {
|
|
27
|
+
errors.push(`${path}: nesting deeper than ${MAX_VALIDATION_DEPTH} levels`);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
14
30
|
if (!schema || typeof schema !== "object")
|
|
15
|
-
return
|
|
31
|
+
return;
|
|
16
32
|
const expectedType = schema.type;
|
|
17
33
|
if (typeof expectedType === "string") {
|
|
18
34
|
const actual = jsonType(value);
|
|
19
35
|
if (actual !== expectedType && !(expectedType === "integer" && actual === "number")) {
|
|
20
|
-
|
|
36
|
+
errors.push(`${path}: expected ${expectedType}, got ${actual}`);
|
|
37
|
+
return;
|
|
21
38
|
}
|
|
22
39
|
if (expectedType === "integer" && typeof value === "number" && !Number.isInteger(value)) {
|
|
23
|
-
|
|
40
|
+
errors.push(`${path}: expected integer`);
|
|
41
|
+
return;
|
|
24
42
|
}
|
|
25
43
|
}
|
|
26
44
|
if (Array.isArray(schema.enum) && !schema.enum.some((option) => option === value)) {
|
|
@@ -38,28 +56,29 @@ export function validateAgainstSchema(value, schema, path = "args") {
|
|
|
38
56
|
const properties = isRecord(schema.properties) ? schema.properties : {};
|
|
39
57
|
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
40
58
|
for (const key of required) {
|
|
41
|
-
if (!(key
|
|
59
|
+
if (!Object.prototype.hasOwnProperty.call(value, key))
|
|
42
60
|
errors.push(`${path}.${key}: required`);
|
|
43
61
|
}
|
|
44
|
-
for (const
|
|
45
|
-
if (key
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
62
|
+
for (const key of Object.keys(properties)) {
|
|
63
|
+
if (!Object.prototype.hasOwnProperty.call(value, key))
|
|
64
|
+
continue;
|
|
65
|
+
const child = properties[key];
|
|
66
|
+
validateNode(value[key], isRecord(child) ? child : undefined, `${path}.${key}`, depth + 1, errors);
|
|
49
67
|
}
|
|
50
68
|
if (schema.additionalProperties === false) {
|
|
51
69
|
for (const key of Object.keys(value)) {
|
|
52
|
-
if (!(key
|
|
70
|
+
if (!Object.prototype.hasOwnProperty.call(properties, key)) {
|
|
53
71
|
errors.push(`${path}.${key}: additional property not allowed`);
|
|
72
|
+
}
|
|
54
73
|
}
|
|
55
74
|
}
|
|
56
75
|
}
|
|
57
76
|
if (expectedType === "array" && Array.isArray(value) && isRecord(schema.items)) {
|
|
77
|
+
const itemSchema = schema.items;
|
|
58
78
|
value.forEach((item, index) => {
|
|
59
|
-
|
|
79
|
+
validateNode(item, itemSchema, `${path}[${index}]`, depth + 1, errors);
|
|
60
80
|
});
|
|
61
81
|
}
|
|
62
|
-
return { valid: errors.length === 0, errors };
|
|
63
82
|
}
|
|
64
83
|
function jsonType(value) {
|
|
65
84
|
if (value === null)
|
|
@@ -264,6 +264,19 @@ function embeddedIPv4FromIPv6(groups) {
|
|
|
264
264
|
groups[5] === 0) {
|
|
265
265
|
return `${(groups[6] >> 8) & 0xff}.${groups[6] & 0xff}.${(groups[7] >> 8) & 0xff}.${groups[7] & 0xff}`;
|
|
266
266
|
}
|
|
267
|
+
// 6to4 (RFC 3056): 2002:VVVV:VVVV::/48 carries the IPv4 address in bits
|
|
268
|
+
// 16..47 (groups 1 and 2). A 6to4-capable host relays traffic to that
|
|
269
|
+
// address, so `2002:a9fe:a9fe::` reaches 169.254.169.254.
|
|
270
|
+
if (groups[0] === 0x2002) {
|
|
271
|
+
return `${(groups[1] >> 8) & 0xff}.${groups[1] & 0xff}.${(groups[2] >> 8) & 0xff}.${groups[2] & 0xff}`;
|
|
272
|
+
}
|
|
273
|
+
// Teredo (RFC 4380): 2001:0000::/32. The client's IPv4 is stored inverted
|
|
274
|
+
// (XOR 0xffffffff) in the last two groups.
|
|
275
|
+
if (groups[0] === 0x2001 && groups[1] === 0x0000) {
|
|
276
|
+
const a = ~groups[6] & 0xffff;
|
|
277
|
+
const b = ~groups[7] & 0xffff;
|
|
278
|
+
return `${(a >> 8) & 0xff}.${a & 0xff}.${(b >> 8) & 0xff}.${b & 0xff}`;
|
|
279
|
+
}
|
|
267
280
|
// IPv4-compatible (deprecated but still parsed by some stacks): ::a.b.c.d,
|
|
268
281
|
// excluding :: and ::1 which are handled as special cases above.
|
|
269
282
|
if (high.every((group) => group === 0) && groups[5] === 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hilbras/sdk",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Provider-agnostic LLM client SDK — streaming, tool calling, embeddings, image generation, speech synthesis, transcription, reranking, circuit breaker, retry, reasoning normalization, cost enforcement, structured output with schema validation, type-safe tool builder, and SSRF-safe provider registration. Zero runtime dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|