xploitscan-shared-rules 2.4.32 → 2.4.33
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.cjs +119 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +119 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -169,7 +169,7 @@ interface CustomRule {
|
|
|
169
169
|
* before a scan can be saved without enough provenance to explain a changed
|
|
170
170
|
* grade.
|
|
171
171
|
*/
|
|
172
|
-
declare const SCANNER_VERSION = "2.4.
|
|
172
|
+
declare const SCANNER_VERSION = "2.4.33";
|
|
173
173
|
|
|
174
174
|
/**
|
|
175
175
|
* Line-oriented helpers shared by every rule. Pure string manipulation — no fs
|
|
@@ -1498,6 +1498,14 @@ declare function packReviewBatches(fileFindings: Finding[], content: string): Fi
|
|
|
1498
1498
|
*/
|
|
1499
1499
|
declare function filterFalsePositives(findings: Finding[], fileContents: Map<string, string>, budgetMs?: number, options?: {
|
|
1500
1500
|
surface?: AiSurface;
|
|
1501
|
+
/**
|
|
1502
|
+
* Hosted scans only (api / web / app). When true, a model call that
|
|
1503
|
+
* threw a retryable error gets one more attempt if the remaining budget
|
|
1504
|
+
* still fits a full per-call window. Ignored unless the surface is
|
|
1505
|
+
* hosted (api, web, app): a CLI, Action, or MCP scan runs on the user's
|
|
1506
|
+
* machine, should fail fast, and can simply be rerun.
|
|
1507
|
+
*/
|
|
1508
|
+
retryTransient?: boolean;
|
|
1501
1509
|
}): Promise<AIFilterResult>;
|
|
1502
1510
|
|
|
1503
1511
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -169,7 +169,7 @@ interface CustomRule {
|
|
|
169
169
|
* before a scan can be saved without enough provenance to explain a changed
|
|
170
170
|
* grade.
|
|
171
171
|
*/
|
|
172
|
-
declare const SCANNER_VERSION = "2.4.
|
|
172
|
+
declare const SCANNER_VERSION = "2.4.33";
|
|
173
173
|
|
|
174
174
|
/**
|
|
175
175
|
* Line-oriented helpers shared by every rule. Pure string manipulation — no fs
|
|
@@ -1498,6 +1498,14 @@ declare function packReviewBatches(fileFindings: Finding[], content: string): Fi
|
|
|
1498
1498
|
*/
|
|
1499
1499
|
declare function filterFalsePositives(findings: Finding[], fileContents: Map<string, string>, budgetMs?: number, options?: {
|
|
1500
1500
|
surface?: AiSurface;
|
|
1501
|
+
/**
|
|
1502
|
+
* Hosted scans only (api / web / app). When true, a model call that
|
|
1503
|
+
* threw a retryable error gets one more attempt if the remaining budget
|
|
1504
|
+
* still fits a full per-call window. Ignored unless the surface is
|
|
1505
|
+
* hosted (api, web, app): a CLI, Action, or MCP scan runs on the user's
|
|
1506
|
+
* machine, should fail fast, and can simply be rerun.
|
|
1507
|
+
*/
|
|
1508
|
+
retryTransient?: boolean;
|
|
1501
1509
|
}): Promise<AIFilterResult>;
|
|
1502
1510
|
|
|
1503
1511
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var SCANNER_VERSION = "2.4.
|
|
2
|
+
var SCANNER_VERSION = "2.4.33";
|
|
3
3
|
|
|
4
4
|
// src/snippet.ts
|
|
5
5
|
var cacheContent = null;
|
|
@@ -10237,6 +10237,70 @@ function callWasAborted(err) {
|
|
|
10237
10237
|
const name = "name" in err ? String(err.name) : "";
|
|
10238
10238
|
return name === "AbortError" || name === "APIUserAbortError";
|
|
10239
10239
|
}
|
|
10240
|
+
var SAFE_ERROR_IDENT = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
|
|
10241
|
+
var SAFE_ERROR_CODE = /^[A-Z][A-Z0-9_]{1,47}$/;
|
|
10242
|
+
function safeIdent(value) {
|
|
10243
|
+
return typeof value === "string" && SAFE_ERROR_IDENT.test(value) ? value : null;
|
|
10244
|
+
}
|
|
10245
|
+
function errorClassChain(err) {
|
|
10246
|
+
const names = [];
|
|
10247
|
+
let proto = Object.getPrototypeOf(err);
|
|
10248
|
+
for (let depth = 0; proto && depth < 8; depth++) {
|
|
10249
|
+
const ctor = proto.constructor;
|
|
10250
|
+
const name = safeIdent(ctor?.name);
|
|
10251
|
+
if (name && name !== "Object") names.push(name);
|
|
10252
|
+
proto = Object.getPrototypeOf(proto);
|
|
10253
|
+
}
|
|
10254
|
+
return names;
|
|
10255
|
+
}
|
|
10256
|
+
function causeLabel(err) {
|
|
10257
|
+
const cause = err.cause;
|
|
10258
|
+
if (!cause || typeof cause !== "object") return null;
|
|
10259
|
+
const chain = errorClassChain(cause);
|
|
10260
|
+
const name = chain[0] ?? safeIdent(cause.name);
|
|
10261
|
+
let code = null;
|
|
10262
|
+
let node = cause;
|
|
10263
|
+
for (let depth = 0; node && typeof node === "object" && depth < 3 && !code; depth++) {
|
|
10264
|
+
const raw = node.code;
|
|
10265
|
+
if (typeof raw === "string" && SAFE_ERROR_CODE.test(raw)) code = raw;
|
|
10266
|
+
node = node.cause;
|
|
10267
|
+
}
|
|
10268
|
+
if (!name && !code) return null;
|
|
10269
|
+
return code ? `${name ?? "unknown"}/${code}` : name;
|
|
10270
|
+
}
|
|
10271
|
+
function classifyModelError(err) {
|
|
10272
|
+
if (!err || typeof err !== "object") {
|
|
10273
|
+
return { name: "unknown", category: "unknown", status: null, cause: null };
|
|
10274
|
+
}
|
|
10275
|
+
const chain = errorClassChain(err);
|
|
10276
|
+
const ownName = safeIdent(err.name);
|
|
10277
|
+
const specific = chain.find((name2) => name2 !== "Error");
|
|
10278
|
+
const name = specific ?? (ownName && ownName !== "Error" ? ownName : chain[0] ?? ownName ?? "unknown");
|
|
10279
|
+
const status = errorHttpStatus(err);
|
|
10280
|
+
const names = new Set(chain);
|
|
10281
|
+
if (ownName) names.add(ownName);
|
|
10282
|
+
let category = "unknown";
|
|
10283
|
+
if (status === 401 || status === 403) category = "auth";
|
|
10284
|
+
else if (status === 400) category = "bad_request";
|
|
10285
|
+
else if (status === 429) category = "rate_limit";
|
|
10286
|
+
else if (status != null && status >= 500) category = "server";
|
|
10287
|
+
else if (status != null && status >= 400) category = "client";
|
|
10288
|
+
else if (names.has("APIConnectionTimeoutError") || names.has("TimeoutError")) category = "timeout";
|
|
10289
|
+
else if (names.has("APIUserAbortError") || names.has("AbortError")) category = "abort";
|
|
10290
|
+
else if (names.has("APIConnectionError")) category = "connection";
|
|
10291
|
+
const cause = causeLabel(err);
|
|
10292
|
+
if (category === "unknown" && cause && cause.includes("/")) category = "connection";
|
|
10293
|
+
return { name, category, status, cause };
|
|
10294
|
+
}
|
|
10295
|
+
function isRetryableModelError(info) {
|
|
10296
|
+
if (info.category === "timeout" || info.category === "abort") return false;
|
|
10297
|
+
if (info.status == null) return true;
|
|
10298
|
+
if (info.status === 408 || info.status === 409 || info.status === 429) return true;
|
|
10299
|
+
return info.status >= 500;
|
|
10300
|
+
}
|
|
10301
|
+
var MODEL_RETRY_DELAY_MS = 300;
|
|
10302
|
+
var HOSTED_RETRY_SURFACES = /* @__PURE__ */ new Set(["api", "web", "app"]);
|
|
10303
|
+
var MAX_MODEL_THROW_LOGS = 3;
|
|
10240
10304
|
var SEVERITY_PRIORITY = {
|
|
10241
10305
|
critical: 0,
|
|
10242
10306
|
high: 1,
|
|
@@ -10528,6 +10592,7 @@ function parseReviewResponse(text) {
|
|
|
10528
10592
|
}
|
|
10529
10593
|
async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER_BUDGET_MS, options) {
|
|
10530
10594
|
const surface = options?.surface ?? "cli";
|
|
10595
|
+
const retryTransient = options?.retryTransient === true && HOSTED_RETRY_SURFACES.has(surface);
|
|
10531
10596
|
const emptyMask = { prompt_batches: 0, prompt_chars: 0, masked_count: 0, had_secret_pattern: false, raw_after_mask: 0 };
|
|
10532
10597
|
const early = (status2, reason2, extra) => ({
|
|
10533
10598
|
findings,
|
|
@@ -10603,6 +10668,14 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
10603
10668
|
let fenceDropCount = 0;
|
|
10604
10669
|
let timedOutCount = 0;
|
|
10605
10670
|
let missingContentCount = 0;
|
|
10671
|
+
let modelThrowLogs = 0;
|
|
10672
|
+
const logModelThrow = (info, action) => {
|
|
10673
|
+
if (modelThrowLogs >= MAX_MODEL_THROW_LOGS) return;
|
|
10674
|
+
modelThrowLogs += 1;
|
|
10675
|
+
console.error(
|
|
10676
|
+
`[ai-fp-filter] model call threw: class ${info.name}, category ${info.category}, status ${info.status ?? "none"}, cause ${info.cause ?? "none"}, model ${MODEL_TRIAGE}; ${action}`
|
|
10677
|
+
);
|
|
10678
|
+
};
|
|
10606
10679
|
const detectionCaches = /* @__PURE__ */ new Map();
|
|
10607
10680
|
const cacheFor = (file) => {
|
|
10608
10681
|
let cache2 = detectionCaches.get(file);
|
|
@@ -10735,34 +10808,53 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
10735
10808
|
);
|
|
10736
10809
|
}
|
|
10737
10810
|
const perCall = perCallTimeoutMs(budgetMs);
|
|
10738
|
-
|
|
10739
|
-
const
|
|
10740
|
-
|
|
10741
|
-
|
|
10742
|
-
|
|
10743
|
-
|
|
10811
|
+
let callAborted = false;
|
|
10812
|
+
const send = async (callTimeout) => {
|
|
10813
|
+
const callAbort = new AbortController();
|
|
10814
|
+
const onParentAbort = () => callAbort.abort();
|
|
10815
|
+
if (abortController.signal.aborted) callAbort.abort();
|
|
10816
|
+
else abortController.signal.addEventListener("abort", onParentAbort, { once: true });
|
|
10817
|
+
const callTimer = setTimeout(() => callAbort.abort(), callTimeout);
|
|
10818
|
+
try {
|
|
10819
|
+
return await client.messages.create(
|
|
10820
|
+
{
|
|
10821
|
+
model: MODEL_TRIAGE,
|
|
10822
|
+
max_tokens: 2048,
|
|
10823
|
+
// Haiku 5.5 rejects non-default sampling params with HTTP 400
|
|
10824
|
+
// ("temperature is deprecated for this model"). Omit temperature /
|
|
10825
|
+
// top_p / top_k entirely — do NOT send MODEL_TEMPERATURE (0).
|
|
10826
|
+
// Adaptive thinking is on by default for 5.5; disable it here: this
|
|
10827
|
+
// is binary FP classification, not open-ended analysis, and thinking
|
|
10828
|
+
// burns the shared AI budget (Isobar rescan: every call 400'd on
|
|
10829
|
+
// temperature, then timed_out with aiReviewed:false → grade D).
|
|
10830
|
+
thinking: { type: "disabled" },
|
|
10831
|
+
system: REVIEW_SYSTEM_PROMPT,
|
|
10832
|
+
messages: [{ role: "user", content: prompt }]
|
|
10833
|
+
},
|
|
10834
|
+
{ timeout: callTimeout, signal: callAbort.signal }
|
|
10835
|
+
);
|
|
10836
|
+
} finally {
|
|
10837
|
+
callAborted = callAbort.signal.aborted;
|
|
10838
|
+
clearTimeout(callTimer);
|
|
10839
|
+
abortController.signal.removeEventListener("abort", onParentAbort);
|
|
10840
|
+
}
|
|
10841
|
+
};
|
|
10744
10842
|
let response;
|
|
10745
10843
|
try {
|
|
10746
|
-
response = await
|
|
10747
|
-
|
|
10748
|
-
|
|
10749
|
-
|
|
10750
|
-
|
|
10751
|
-
|
|
10752
|
-
|
|
10753
|
-
|
|
10754
|
-
|
|
10755
|
-
|
|
10756
|
-
|
|
10757
|
-
|
|
10758
|
-
|
|
10759
|
-
|
|
10760
|
-
},
|
|
10761
|
-
{ timeout: callTimeout, signal: callAbort.signal }
|
|
10762
|
-
);
|
|
10763
|
-
} finally {
|
|
10764
|
-
clearTimeout(callTimer);
|
|
10765
|
-
abortController.signal.removeEventListener("abort", onParentAbort);
|
|
10844
|
+
response = await send(Math.min(perCall, remaining));
|
|
10845
|
+
} catch (err) {
|
|
10846
|
+
const info = classifyModelError(err);
|
|
10847
|
+
const budgetAbort = abortController.signal.aborted;
|
|
10848
|
+
const retry = retryTransient && !callAborted && !budgetAbort && !authFailed && isRetryableModelError(info) && deadlineMs - Date.now() - MODEL_RETRY_DELAY_MS >= perCall;
|
|
10849
|
+
if (!budgetAbort) logModelThrow(info, retry ? "retrying once" : "not retried");
|
|
10850
|
+
if (!retry) throw err;
|
|
10851
|
+
await new Promise((resolve) => setTimeout(resolve, MODEL_RETRY_DELAY_MS));
|
|
10852
|
+
try {
|
|
10853
|
+
response = await send(Math.min(perCall, Math.max(1, deadlineMs - Date.now())));
|
|
10854
|
+
} catch (retryErr) {
|
|
10855
|
+
if (!abortController.signal.aborted) logModelThrow(classifyModelError(retryErr), "retry failed");
|
|
10856
|
+
throw retryErr;
|
|
10857
|
+
}
|
|
10766
10858
|
}
|
|
10767
10859
|
const text = response.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
10768
10860
|
const results = parseReviewResponse(text);
|