@silmaril-security/sdk 0.10.0 → 0.10.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/CHANGELOG.md +18 -0
- package/README.md +2 -2
- package/dist/index.cjs +35 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +35 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.10.2
|
|
4
|
+
|
|
5
|
+
- Reject blank and Python-whitespace-only primary outcome labels and harmful
|
|
6
|
+
score/count map keys while preserving nonblank open-ended labels verbatim.
|
|
7
|
+
This includes Python's separator controls, NEL, and non-ASCII spaces while
|
|
8
|
+
retaining U+FEFF as nonblank.
|
|
9
|
+
|
|
10
|
+
## 0.10.1
|
|
11
|
+
|
|
12
|
+
- Reject missing, null, string, non-finite, or out-of-range response `score`
|
|
13
|
+
and `threshold` values instead of coercing them during single or batch
|
|
14
|
+
verdict decoding.
|
|
15
|
+
- Reject non-finite or out-of-range `outcome_scores` and `detector_scores`
|
|
16
|
+
values while continuing to require non-negative integer `detector_counts`.
|
|
17
|
+
- Reject present blank or whitespace-only governance `reason` and
|
|
18
|
+
`identity_revision` evidence. Omitted and null legacy evidence remains valid,
|
|
19
|
+
and nonblank strings are returned without trimming.
|
|
20
|
+
|
|
3
21
|
## 0.10.0
|
|
4
22
|
|
|
5
23
|
- Classify model output by default: `LLM_END` joins `DEFAULT_HOOKS` for the
|
package/README.md
CHANGED
|
@@ -35,10 +35,10 @@ This SDK is distributed as an npm package.
|
|
|
35
35
|
npm install @silmaril-security/sdk
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
Pin version 0.10.
|
|
38
|
+
Pin version 0.10.2 for reproducible installs:
|
|
39
39
|
|
|
40
40
|
```sh
|
|
41
|
-
npm install @silmaril-security/sdk@0.10.
|
|
41
|
+
npm install @silmaril-security/sdk@0.10.2
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
Requires Node 20 or later.
|
package/dist/index.cjs
CHANGED
|
@@ -1491,6 +1491,10 @@ var OUTCOME_DESCRIPTIONS = {
|
|
|
1491
1491
|
};
|
|
1492
1492
|
var PRIMARY_OUTCOME_SET = new Set(PRIMARY_OUTCOMES);
|
|
1493
1493
|
var HARMFUL_OUTCOME_SET = new Set(HARMFUL_OUTCOMES);
|
|
1494
|
+
var PYTHON_NONBLANK = /[^\p{White_Space}\u001c-\u001f]/u;
|
|
1495
|
+
function isNonblankOutcomeLabel(value) {
|
|
1496
|
+
return typeof value === "string" && PYTHON_NONBLANK.test(value);
|
|
1497
|
+
}
|
|
1494
1498
|
function isPrimaryOutcome(value) {
|
|
1495
1499
|
return typeof value === "string" && PRIMARY_OUTCOME_SET.has(value);
|
|
1496
1500
|
}
|
|
@@ -1498,18 +1502,18 @@ function isHarmfulOutcome(value) {
|
|
|
1498
1502
|
return typeof value === "string" && HARMFUL_OUTCOME_SET.has(value);
|
|
1499
1503
|
}
|
|
1500
1504
|
function normalizePrimaryOutcome(value, fieldName = "primary_outcome") {
|
|
1501
|
-
if (
|
|
1505
|
+
if (!isNonblankOutcomeLabel(value)) {
|
|
1502
1506
|
throw new Error(`Firewall: invalid ${fieldName} ${JSON.stringify(value)}`);
|
|
1503
1507
|
}
|
|
1504
1508
|
return isPrimaryOutcome(value) ? value : value;
|
|
1505
1509
|
}
|
|
1506
1510
|
function normalizeHarmfulOutcome(value, fieldName = "outcome") {
|
|
1507
|
-
if (
|
|
1511
|
+
if (!isNonblankOutcomeLabel(value) || value === Outcome.Benign) {
|
|
1508
1512
|
throw new Error(`Firewall: invalid ${fieldName} ${JSON.stringify(value)}`);
|
|
1509
1513
|
}
|
|
1510
1514
|
return isHarmfulOutcome(value) ? value : value;
|
|
1511
1515
|
}
|
|
1512
|
-
function
|
|
1516
|
+
function normalizeNumericOutcomeMap(values, fieldName, accepts) {
|
|
1513
1517
|
if (values === void 0 || values === null) {
|
|
1514
1518
|
return void 0;
|
|
1515
1519
|
}
|
|
@@ -1519,24 +1523,23 @@ function normalizeHarmfulOutcomeMap(values, fieldName) {
|
|
|
1519
1523
|
const out = {};
|
|
1520
1524
|
for (const [key, value] of Object.entries(values)) {
|
|
1521
1525
|
const normalizedKey = normalizeHarmfulOutcome(key, `${fieldName} key`);
|
|
1522
|
-
if (typeof value !== "number") {
|
|
1526
|
+
if (typeof value !== "number" || !accepts(value)) {
|
|
1523
1527
|
throw new Error(`Firewall: invalid ${fieldName} value for ${JSON.stringify(key)}`);
|
|
1524
1528
|
}
|
|
1525
|
-
out
|
|
1529
|
+
Object.defineProperty(out, normalizedKey, {
|
|
1530
|
+
value,
|
|
1531
|
+
enumerable: true,
|
|
1532
|
+
configurable: true,
|
|
1533
|
+
writable: true
|
|
1534
|
+
});
|
|
1526
1535
|
}
|
|
1527
1536
|
return Object.freeze(out);
|
|
1528
1537
|
}
|
|
1538
|
+
function normalizeHarmfulOutcomeMap(values, fieldName) {
|
|
1539
|
+
return normalizeNumericOutcomeMap(values, fieldName, (value) => value >= 0 && value <= 1);
|
|
1540
|
+
}
|
|
1529
1541
|
function normalizeHarmfulOutcomeCountMap(values, fieldName) {
|
|
1530
|
-
|
|
1531
|
-
if (out === void 0) {
|
|
1532
|
-
return void 0;
|
|
1533
|
-
}
|
|
1534
|
-
for (const [key, value] of Object.entries(out)) {
|
|
1535
|
-
if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value) || value < 0) {
|
|
1536
|
-
throw new Error(`Firewall: invalid ${fieldName} value for ${JSON.stringify(key)}`);
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
return out;
|
|
1542
|
+
return normalizeNumericOutcomeMap(values, fieldName, (value) => Number.isInteger(value) && value >= 0);
|
|
1540
1543
|
}
|
|
1541
1544
|
|
|
1542
1545
|
// src/firewall.ts
|
|
@@ -1568,8 +1571,16 @@ function sanitizeText(text) {
|
|
|
1568
1571
|
return out;
|
|
1569
1572
|
}
|
|
1570
1573
|
|
|
1574
|
+
// src/validation.ts
|
|
1575
|
+
function validateThreshold(name, value) {
|
|
1576
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) {
|
|
1577
|
+
throw new Error(`Firewall: ${name} must be a finite number between 0 and 1`);
|
|
1578
|
+
}
|
|
1579
|
+
return value;
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1571
1582
|
// src/firewall.ts
|
|
1572
|
-
var SDK_VERSION = "0.10.
|
|
1583
|
+
var SDK_VERSION = "0.10.2";
|
|
1573
1584
|
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
1574
1585
|
var DEFAULT_MAX_RETRIES = 5;
|
|
1575
1586
|
var MAX_BACKOFF_SECONDS = 30;
|
|
@@ -1613,8 +1624,8 @@ function blockResultFromResponse(data, requestedMode, requestedReview) {
|
|
|
1613
1624
|
}
|
|
1614
1625
|
const result = {
|
|
1615
1626
|
prediction: data.prediction,
|
|
1616
|
-
score:
|
|
1617
|
-
threshold:
|
|
1627
|
+
score: validateThreshold("response score", data.score),
|
|
1628
|
+
threshold: validateThreshold("response threshold", data.threshold)
|
|
1618
1629
|
};
|
|
1619
1630
|
if (requestedReview !== void 0) {
|
|
1620
1631
|
result.review = requestedReview;
|
|
@@ -1776,13 +1787,15 @@ function governanceDecisionFromResponse(value) {
|
|
|
1776
1787
|
if (value.rule_id !== void 0 && value.rule_id !== null && typeof value.rule_id !== "string") {
|
|
1777
1788
|
throw new Error("Firewall: response governance rule_id must be a string when provided");
|
|
1778
1789
|
}
|
|
1779
|
-
if (value.identity_revision !== void 0 && value.identity_revision !== null && typeof value.identity_revision !== "string") {
|
|
1790
|
+
if (value.identity_revision !== void 0 && value.identity_revision !== null && (typeof value.identity_revision !== "string" || !value.identity_revision.trim())) {
|
|
1780
1791
|
throw new Error(
|
|
1781
|
-
"Firewall: response governance identity_revision must be a string when provided"
|
|
1792
|
+
"Firewall: response governance identity_revision must be a non-empty string when provided"
|
|
1782
1793
|
);
|
|
1783
1794
|
}
|
|
1784
|
-
if (value.reason !== void 0 && value.reason !== null && typeof value.reason !== "string") {
|
|
1785
|
-
throw new Error(
|
|
1795
|
+
if (value.reason !== void 0 && value.reason !== null && (typeof value.reason !== "string" || !value.reason.trim())) {
|
|
1796
|
+
throw new Error(
|
|
1797
|
+
"Firewall: response governance reason must be a non-empty string when provided"
|
|
1798
|
+
);
|
|
1786
1799
|
}
|
|
1787
1800
|
const resource = value.resource === void 0 || value.resource === null ? void 0 : governanceResourceFromResponse(value.resource);
|
|
1788
1801
|
return Object.freeze({
|