xploitscan-shared-rules 2.4.32 → 2.4.34
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 +123 -36
- 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 +123 -36
- 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.34";
|
|
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.34";
|
|
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.34";
|
|
3
3
|
|
|
4
4
|
// src/snippet.ts
|
|
5
5
|
var cacheContent = null;
|
|
@@ -10216,9 +10216,8 @@ if (!(perCallTimeoutMs(AI_FILTER_BUDGET_MS) < AI_FILTER_BUDGET_MS)) {
|
|
|
10216
10216
|
throw new Error("per-call AI timeout must be strictly below the filter budget");
|
|
10217
10217
|
}
|
|
10218
10218
|
function isAbortError(err) {
|
|
10219
|
-
|
|
10220
|
-
|
|
10221
|
-
return name === "AbortError" || name === "APIUserAbortError";
|
|
10219
|
+
const { category } = classifyModelError(err);
|
|
10220
|
+
return category === "abort" || category === "timeout";
|
|
10222
10221
|
}
|
|
10223
10222
|
function isTimeoutError(err) {
|
|
10224
10223
|
if (!err || typeof err !== "object") return false;
|
|
@@ -10232,11 +10231,71 @@ function errorHttpStatus(err) {
|
|
|
10232
10231
|
const status = err.status;
|
|
10233
10232
|
return typeof status === "number" && Number.isFinite(status) ? Math.trunc(status) : null;
|
|
10234
10233
|
}
|
|
10235
|
-
|
|
10236
|
-
|
|
10237
|
-
|
|
10238
|
-
return
|
|
10234
|
+
var SAFE_ERROR_IDENT = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
|
|
10235
|
+
var SAFE_ERROR_CODE = /^[A-Z][A-Z0-9_]{1,47}$/;
|
|
10236
|
+
function safeIdent(value) {
|
|
10237
|
+
return typeof value === "string" && SAFE_ERROR_IDENT.test(value) ? value : null;
|
|
10239
10238
|
}
|
|
10239
|
+
function errorClassChain(err) {
|
|
10240
|
+
const names = [];
|
|
10241
|
+
let proto = Object.getPrototypeOf(err);
|
|
10242
|
+
for (let depth = 0; proto && depth < 8; depth++) {
|
|
10243
|
+
const ctor = proto.constructor;
|
|
10244
|
+
const name = safeIdent(ctor?.name);
|
|
10245
|
+
if (name && name !== "Object") names.push(name);
|
|
10246
|
+
proto = Object.getPrototypeOf(proto);
|
|
10247
|
+
}
|
|
10248
|
+
return names;
|
|
10249
|
+
}
|
|
10250
|
+
function causeInfo(err) {
|
|
10251
|
+
const cause = err.cause;
|
|
10252
|
+
if (!cause || typeof cause !== "object") return { label: null, code: null };
|
|
10253
|
+
const chain = errorClassChain(cause);
|
|
10254
|
+
const name = chain[0] ?? safeIdent(cause.name);
|
|
10255
|
+
let code = null;
|
|
10256
|
+
let node = cause;
|
|
10257
|
+
for (let depth = 0; node && typeof node === "object" && depth < 3 && !code; depth++) {
|
|
10258
|
+
const raw = node.code;
|
|
10259
|
+
if (typeof raw === "string" && SAFE_ERROR_CODE.test(raw)) code = raw;
|
|
10260
|
+
node = node.cause;
|
|
10261
|
+
}
|
|
10262
|
+
if (!name && !code) return { label: null, code: null };
|
|
10263
|
+
return { label: code ? `${name ?? "unknown"}/${code}` : name, code };
|
|
10264
|
+
}
|
|
10265
|
+
function classifyModelError(err) {
|
|
10266
|
+
if (!err || typeof err !== "object") {
|
|
10267
|
+
return { name: "unknown", category: "unknown", status: null, cause: null };
|
|
10268
|
+
}
|
|
10269
|
+
const chain = errorClassChain(err);
|
|
10270
|
+
const ownName = safeIdent(err.name);
|
|
10271
|
+
const specific = chain.find((name2) => name2 !== "Error");
|
|
10272
|
+
const name = specific ?? (ownName && ownName !== "Error" ? ownName : chain[0] ?? ownName ?? "unknown");
|
|
10273
|
+
const status = errorHttpStatus(err);
|
|
10274
|
+
const names = new Set(chain);
|
|
10275
|
+
if (ownName) names.add(ownName);
|
|
10276
|
+
const { label: cause, code: causeCode } = causeInfo(err);
|
|
10277
|
+
let category = "unknown";
|
|
10278
|
+
if (status === 401 || status === 403) category = "auth";
|
|
10279
|
+
else if (status === 400) category = "bad_request";
|
|
10280
|
+
else if (status === 429) category = "rate_limit";
|
|
10281
|
+
else if (status != null && status >= 500) category = "server";
|
|
10282
|
+
else if (status != null && status >= 400) category = "client";
|
|
10283
|
+
else if (names.has("APIConnectionTimeoutError") || names.has("TimeoutError") || causeCode === "ETIMEDOUT") {
|
|
10284
|
+
category = "timeout";
|
|
10285
|
+
} else if (names.has("APIUserAbortError") || names.has("AbortError")) category = "abort";
|
|
10286
|
+
else if (names.has("APIConnectionError")) category = "connection";
|
|
10287
|
+
if (category === "unknown" && causeCode) category = "connection";
|
|
10288
|
+
return { name, category, status, cause };
|
|
10289
|
+
}
|
|
10290
|
+
function isRetryableModelError(info) {
|
|
10291
|
+
if (info.category === "timeout" || info.category === "abort") return false;
|
|
10292
|
+
if (info.status == null) return true;
|
|
10293
|
+
if (info.status === 408 || info.status === 409 || info.status === 429) return true;
|
|
10294
|
+
return info.status >= 500;
|
|
10295
|
+
}
|
|
10296
|
+
var MODEL_RETRY_DELAY_MS = 300;
|
|
10297
|
+
var HOSTED_RETRY_SURFACES = /* @__PURE__ */ new Set(["api", "web", "app"]);
|
|
10298
|
+
var MAX_MODEL_THROW_LOGS = 3;
|
|
10240
10299
|
var SEVERITY_PRIORITY = {
|
|
10241
10300
|
critical: 0,
|
|
10242
10301
|
high: 1,
|
|
@@ -10528,6 +10587,7 @@ function parseReviewResponse(text) {
|
|
|
10528
10587
|
}
|
|
10529
10588
|
async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER_BUDGET_MS, options) {
|
|
10530
10589
|
const surface = options?.surface ?? "cli";
|
|
10590
|
+
const retryTransient = options?.retryTransient === true && HOSTED_RETRY_SURFACES.has(surface);
|
|
10531
10591
|
const emptyMask = { prompt_batches: 0, prompt_chars: 0, masked_count: 0, had_secret_pattern: false, raw_after_mask: 0 };
|
|
10532
10592
|
const early = (status2, reason2, extra) => ({
|
|
10533
10593
|
findings,
|
|
@@ -10581,7 +10641,7 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
10581
10641
|
const totalBefore = findings.length;
|
|
10582
10642
|
let client;
|
|
10583
10643
|
try {
|
|
10584
|
-
client = new Anthropic();
|
|
10644
|
+
client = retryTransient ? new Anthropic({ maxRetries: 1 }) : new Anthropic();
|
|
10585
10645
|
} catch {
|
|
10586
10646
|
if (budgetTimer) clearTimeout(budgetTimer);
|
|
10587
10647
|
return early("failed", "client_init", {
|
|
@@ -10603,6 +10663,14 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
10603
10663
|
let fenceDropCount = 0;
|
|
10604
10664
|
let timedOutCount = 0;
|
|
10605
10665
|
let missingContentCount = 0;
|
|
10666
|
+
let modelThrowLogs = 0;
|
|
10667
|
+
const logModelThrow = (info, action) => {
|
|
10668
|
+
if (modelThrowLogs >= MAX_MODEL_THROW_LOGS) return;
|
|
10669
|
+
modelThrowLogs += 1;
|
|
10670
|
+
console.error(
|
|
10671
|
+
`[ai-fp-filter] model call threw: class ${info.name}, category ${info.category}, status ${info.status ?? "none"}, cause ${info.cause ?? "none"}, model ${MODEL_TRIAGE}; ${action}`
|
|
10672
|
+
);
|
|
10673
|
+
};
|
|
10606
10674
|
const detectionCaches = /* @__PURE__ */ new Map();
|
|
10607
10675
|
const cacheFor = (file) => {
|
|
10608
10676
|
let cache2 = detectionCaches.get(file);
|
|
@@ -10673,6 +10741,7 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
10673
10741
|
return;
|
|
10674
10742
|
}
|
|
10675
10743
|
let active = targets;
|
|
10744
|
+
let callAborted = false;
|
|
10676
10745
|
try {
|
|
10677
10746
|
const remaining = Math.max(1, deadlineMs - Date.now());
|
|
10678
10747
|
const fences = assignFileFences(targets, fileContents);
|
|
@@ -10735,34 +10804,52 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
10735
10804
|
);
|
|
10736
10805
|
}
|
|
10737
10806
|
const perCall = perCallTimeoutMs(budgetMs);
|
|
10738
|
-
const
|
|
10739
|
-
|
|
10740
|
-
|
|
10741
|
-
|
|
10742
|
-
|
|
10743
|
-
|
|
10807
|
+
const send = async (callTimeout) => {
|
|
10808
|
+
const callAbort = new AbortController();
|
|
10809
|
+
const onParentAbort = () => callAbort.abort();
|
|
10810
|
+
if (abortController.signal.aborted) callAbort.abort();
|
|
10811
|
+
else abortController.signal.addEventListener("abort", onParentAbort, { once: true });
|
|
10812
|
+
const callTimer = setTimeout(() => callAbort.abort(), callTimeout);
|
|
10813
|
+
try {
|
|
10814
|
+
return await client.messages.create(
|
|
10815
|
+
{
|
|
10816
|
+
model: MODEL_TRIAGE,
|
|
10817
|
+
max_tokens: 2048,
|
|
10818
|
+
// Haiku 5.5 rejects non-default sampling params with HTTP 400
|
|
10819
|
+
// ("temperature is deprecated for this model"). Omit temperature /
|
|
10820
|
+
// top_p / top_k entirely — do NOT send MODEL_TEMPERATURE (0).
|
|
10821
|
+
// Adaptive thinking is on by default for 5.5; disable it here: this
|
|
10822
|
+
// is binary FP classification, not open-ended analysis, and thinking
|
|
10823
|
+
// burns the shared AI budget (Isobar rescan: every call 400'd on
|
|
10824
|
+
// temperature, then timed_out with aiReviewed:false → grade D).
|
|
10825
|
+
thinking: { type: "disabled" },
|
|
10826
|
+
system: REVIEW_SYSTEM_PROMPT,
|
|
10827
|
+
messages: [{ role: "user", content: prompt }]
|
|
10828
|
+
},
|
|
10829
|
+
{ timeout: callTimeout, signal: callAbort.signal }
|
|
10830
|
+
);
|
|
10831
|
+
} finally {
|
|
10832
|
+
callAborted = callAbort.signal.aborted;
|
|
10833
|
+
clearTimeout(callTimer);
|
|
10834
|
+
abortController.signal.removeEventListener("abort", onParentAbort);
|
|
10835
|
+
}
|
|
10836
|
+
};
|
|
10744
10837
|
let response;
|
|
10745
10838
|
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);
|
|
10839
|
+
response = await send(Math.min(perCall, remaining));
|
|
10840
|
+
} catch (err) {
|
|
10841
|
+
const info = classifyModelError(err);
|
|
10842
|
+
const budgetAbort = abortController.signal.aborted;
|
|
10843
|
+
const retry = retryTransient && !callAborted && !budgetAbort && !authFailed && isRetryableModelError(info) && deadlineMs - Date.now() - MODEL_RETRY_DELAY_MS >= perCall;
|
|
10844
|
+
if (!budgetAbort) logModelThrow(info, retry ? "retrying once" : "not retried");
|
|
10845
|
+
if (!retry) throw err;
|
|
10846
|
+
await new Promise((resolve) => setTimeout(resolve, MODEL_RETRY_DELAY_MS));
|
|
10847
|
+
try {
|
|
10848
|
+
response = await send(Math.min(perCall, Math.max(1, deadlineMs - Date.now())));
|
|
10849
|
+
} catch (retryErr) {
|
|
10850
|
+
if (!abortController.signal.aborted) logModelThrow(classifyModelError(retryErr), "retry failed");
|
|
10851
|
+
throw retryErr;
|
|
10852
|
+
}
|
|
10766
10853
|
}
|
|
10767
10854
|
const text = response.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
10768
10855
|
const results = parseReviewResponse(text);
|
|
@@ -10821,7 +10908,7 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
10821
10908
|
console.error(`[ai-fp-filter] AI review failed: auth status ${status2}`);
|
|
10822
10909
|
return;
|
|
10823
10910
|
}
|
|
10824
|
-
const callTimedOut = isAbortError(err) || isTimeoutError(err) || abortController.signal.aborted
|
|
10911
|
+
const callTimedOut = callAborted || isAbortError(err) || isTimeoutError(err) || abortController.signal.aborted;
|
|
10825
10912
|
if (callTimedOut) {
|
|
10826
10913
|
timedOutCount += active.length;
|
|
10827
10914
|
budgetExpired = true;
|