@acepaste/ingress 0.9.29 → 0.9.30
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/src/classifier.d.ts +8 -0
- package/dist/src/classifier.js +138 -8
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/meaning.js +12 -2
- package/dist/src/types.d.ts +2 -2
- package/dist/src/types.js +2 -2
- package/package.json +1 -1
package/dist/src/classifier.d.ts
CHANGED
|
@@ -31,6 +31,14 @@ export declare function withoutProtectiveNotices(text: string): {
|
|
|
31
31
|
text: string;
|
|
32
32
|
setAside: number;
|
|
33
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* The string values (and keys) of JSON text, or undefined when the text is not JSON. Tried in turn: the whole
|
|
36
|
+
* text; what lies between its first and last bracket (a line of prose before the data), with the text around
|
|
37
|
+
* it returned as values too; one value per line. A value that is itself JSON text, with or without a tool
|
|
38
|
+
* server's notice around it, is returned as it is and opened the same way. Opening JSON never takes text out
|
|
39
|
+
* of what is read: only a tool server's exact notice is left out, as everywhere in this pass.
|
|
40
|
+
*/
|
|
41
|
+
export declare function jsonValues(text: string, depth?: number): string[] | undefined;
|
|
34
42
|
export interface ClassifierInput {
|
|
35
43
|
/** the text that would be delivered */
|
|
36
44
|
visible: string;
|
package/dist/src/classifier.js
CHANGED
|
@@ -205,6 +205,110 @@ export function withoutProtectiveNotices(text) {
|
|
|
205
205
|
}
|
|
206
206
|
return setAside ? { text: out + text.slice(from), setAside } : { text, setAside: 0 };
|
|
207
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Values read one by one (0.9.30). The learned pass scores a text as one bag of words, so what a text holds is
|
|
210
|
+
* averaged: an attack that scores 0.99 alone scored 0.61 beside three ordinary database rows and 0.08 beside
|
|
211
|
+
* thirty. Of 550 public attack texts that only this pass catches as a lone row of a database result, 125 were
|
|
212
|
+
* still refused with thirty ordinary rows around them. A table is not one text. Each value in it was written
|
|
213
|
+
* by whoever filled that field, and one of them is all an attacker needs.
|
|
214
|
+
*
|
|
215
|
+
* So where the text is JSON (a JSON document, a tool result that carries JSON as text, JSON printed by a
|
|
216
|
+
* command, one JSON value per line), every string value of some length is also scored as a text of its own:
|
|
217
|
+
* its opening, the rest in windows, the allowance for what it quotes. Nothing is taken away: the whole text is
|
|
218
|
+
* still scored as before, at its own line.
|
|
219
|
+
*/
|
|
220
|
+
const JSON_DEPTH = 3;
|
|
221
|
+
/**
|
|
222
|
+
* Every value is one more chance to be wrong, and a table has thousands. So a value is held to a stricter line
|
|
223
|
+
* than a lone text (0.85): 0.9 for a value of 60 characters and nine words or more, the size and the line
|
|
224
|
+
* hidden text is judged by; and 0.95 for a shorter one, which must still have 20 characters and four different
|
|
225
|
+
* words (three words and some numbers give a bag of words nothing to judge, see scanClassifier).
|
|
226
|
+
* Measured: of 10,796 ordinary long values in the JSON files of this repository's dependencies, five are over
|
|
227
|
+
* 0.9, all compiler messages in French; of 13,478 short ones, four are over 0.95; of 2,508 ordinary short text
|
|
228
|
+
* messages, none. Of the public attack texts the rules miss, 616 of 1,565 long ones and 29 of 173 short ones
|
|
229
|
+
* are over their lines.
|
|
230
|
+
*/
|
|
231
|
+
const VALUE_LINE = 0.9, SHORT_VALUE_LINE = 0.95;
|
|
232
|
+
/** scripts written without spaces: a sentence is one "word" */
|
|
233
|
+
const UNSPACED = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Thai}]/gu;
|
|
234
|
+
const longValue = (t) => t.length >= 60 && (t.split(/\s+/).length >= 9 || (t.match(UNSPACED) ?? []).length >= 30);
|
|
235
|
+
const shortValue = (t) => t.length >= 20 && new Set(t.toLowerCase().match(/\p{L}{2,}/gu) ?? []).size >= MIN_LOG_WORDS;
|
|
236
|
+
function parsed(text) {
|
|
237
|
+
if (!/^[\[{]/.test(text))
|
|
238
|
+
return undefined;
|
|
239
|
+
try {
|
|
240
|
+
return { doc: JSON.parse(text) };
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* The string values (and keys) of JSON text, or undefined when the text is not JSON. Tried in turn: the whole
|
|
248
|
+
* text; what lies between its first and last bracket (a line of prose before the data), with the text around
|
|
249
|
+
* it returned as values too; one value per line. A value that is itself JSON text, with or without a tool
|
|
250
|
+
* server's notice around it, is returned as it is and opened the same way. Opening JSON never takes text out
|
|
251
|
+
* of what is read: only a tool server's exact notice is left out, as everywhere in this pass.
|
|
252
|
+
*/
|
|
253
|
+
export function jsonValues(text, depth = 0) {
|
|
254
|
+
const t = text.trim();
|
|
255
|
+
if (t.length < 2)
|
|
256
|
+
return undefined;
|
|
257
|
+
let docs;
|
|
258
|
+
// what stands before and after the data, when the data is only part of the text: values like any other, so
|
|
259
|
+
// that nothing a text holds goes unread for having a pair of brackets after it
|
|
260
|
+
let before = "", after = "";
|
|
261
|
+
const whole = parsed(t);
|
|
262
|
+
if (whole)
|
|
263
|
+
docs = [whole.doc];
|
|
264
|
+
if (!docs) {
|
|
265
|
+
const first = t.search(/[\[{]/), last = Math.max(t.lastIndexOf("]"), t.lastIndexOf("}"));
|
|
266
|
+
const inner = first >= 0 && last > first && (first > 0 || last < t.length - 1) ? parsed(t.slice(first, last + 1)) : undefined;
|
|
267
|
+
if (inner) {
|
|
268
|
+
docs = [inner.doc];
|
|
269
|
+
before = t.slice(0, first).trim();
|
|
270
|
+
after = t.slice(last + 1).trim();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (!docs) {
|
|
274
|
+
const lines = t.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
275
|
+
if (lines.length >= 2 && lines.every((l) => /^[\[{]/.test(l))) {
|
|
276
|
+
const each = lines.map((l) => parsed(l));
|
|
277
|
+
if (each.every((x) => x))
|
|
278
|
+
docs = each.map((x) => x.doc);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (!docs)
|
|
282
|
+
return undefined;
|
|
283
|
+
const out = before ? [before] : [];
|
|
284
|
+
const walk = (v, d) => {
|
|
285
|
+
if (d > 64)
|
|
286
|
+
return;
|
|
287
|
+
if (typeof v === "string") {
|
|
288
|
+
// a value that is JSON text is read both ways: as the text it is, and value by value. Otherwise an
|
|
289
|
+
// attack cut into an array of short strings inside one field would be read as neither.
|
|
290
|
+
const mayBeJson = /[\[{]/.test(v);
|
|
291
|
+
const bare = mayBeJson ? withoutProtectiveNotices(v).text.trim() : v;
|
|
292
|
+
out.push(bare);
|
|
293
|
+
const inner = mayBeJson && depth < JSON_DEPTH ? jsonValues(bare, depth + 1) : undefined;
|
|
294
|
+
if (inner)
|
|
295
|
+
out.push(...inner);
|
|
296
|
+
}
|
|
297
|
+
else if (Array.isArray(v))
|
|
298
|
+
for (const x of v)
|
|
299
|
+
walk(x, d + 1);
|
|
300
|
+
else if (v && typeof v === "object")
|
|
301
|
+
for (const [k, x] of Object.entries(v)) {
|
|
302
|
+
out.push(k);
|
|
303
|
+
walk(x, d + 1);
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
for (const d of docs)
|
|
307
|
+
walk(d, 0);
|
|
308
|
+
if (after)
|
|
309
|
+
out.push(after);
|
|
310
|
+
return out;
|
|
311
|
+
}
|
|
208
312
|
/**
|
|
209
313
|
* The classifier pass. A finding from here scores between the suspect line and well under the hostile line,
|
|
210
314
|
* so on its own it refuses with an override and never more.
|
|
@@ -241,20 +345,46 @@ export function scanClassifier(input) {
|
|
|
241
345
|
});
|
|
242
346
|
/** recorded on the receipt, deciding nothing */
|
|
243
347
|
const note = (p, where) => ({ pass: "classifier", kind: "classifier.injection_likely", confidence: 0, severity: 0, message: `resembles an injection or jailbreak attempt (learned classifier, ${(p * 100).toFixed(0)}%); not decisive for visible ${authority} text`, location: where, action: "none" });
|
|
348
|
+
/** a text's score as a lone text gets it: its opening, then the rest in overlapping windows */
|
|
349
|
+
const read = (text) => {
|
|
350
|
+
const cps = Array.from(text);
|
|
351
|
+
let p = visibleScore(cps.slice(0, maxChars).join("")), pastOpening = false;
|
|
352
|
+
for (let s = STEP, n = 0; s < cps.length - 200 && n < MAX_WINDOWS && cps.length > maxChars; s += STEP, n++) {
|
|
353
|
+
const q = visibleScore(cps.slice(s, s + WINDOW).join(""));
|
|
354
|
+
if (q > p) {
|
|
355
|
+
p = q;
|
|
356
|
+
pastOpening = true;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return { p, pastOpening };
|
|
360
|
+
};
|
|
244
361
|
const visible = judged.text.trim();
|
|
245
362
|
if (visible.length >= 20) {
|
|
246
|
-
const
|
|
247
|
-
let best =
|
|
248
|
-
//
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
363
|
+
const whole = read(visible);
|
|
364
|
+
let best = whole.p, where = whole.pastOpening ? "visible text (past the opening)" : "visible text";
|
|
365
|
+
// JSON: each value is also read as a text of its own (see jsonValues). Only where this pass may decide.
|
|
366
|
+
let value, values = 0;
|
|
367
|
+
if (authority === "text" && !tooFewWords) {
|
|
368
|
+
const sources = input.kind === "json" ? input.segments.filter((s) => s.visibility === "visible").map((s) => withoutProtectiveNotices(s.text).text) : [judged.text];
|
|
369
|
+
for (const src of sources) {
|
|
370
|
+
const opened = jsonValues(src);
|
|
371
|
+
// a JSON document's own values are pieces as they stand; other text is a piece only when it is JSON
|
|
372
|
+
for (const v of opened ?? (input.kind === "json" && sources.length > 1 ? [src] : [])) {
|
|
373
|
+
const t = v.trim();
|
|
374
|
+
const at = longValue(t) ? VALUE_LINE : shortValue(t) ? SHORT_VALUE_LINE : 0;
|
|
375
|
+
if (!at)
|
|
376
|
+
continue;
|
|
377
|
+
values++;
|
|
378
|
+
const p = read(t).p;
|
|
379
|
+
if (p >= at && p > (value?.p ?? 0))
|
|
380
|
+
value = { p, at };
|
|
381
|
+
}
|
|
254
382
|
}
|
|
255
383
|
}
|
|
256
384
|
if (best >= line)
|
|
257
385
|
out.push(finding(best, line, where, false));
|
|
386
|
+
else if (value)
|
|
387
|
+
out.push(finding(value.p, value.at, `one value in the data, read by itself (${values} read)`, false));
|
|
258
388
|
else if (best >= Math.max(threshold, 0.9))
|
|
259
389
|
out.push(note(best, where));
|
|
260
390
|
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export { adaptEmail, parseEmail, looksLikeEmailJson, looksLikeRawEmail } from ".
|
|
|
26
26
|
export type { EmailPart } from "./email.js";
|
|
27
27
|
export { adaptCalendar, parseIcs, looksLikeCalendarJson } from "./calendar.js";
|
|
28
28
|
export { passagesOnlyIn } from "./served.js";
|
|
29
|
-
export { classifyText, scanClassifier, classifierInfo, withoutProtectiveNotices } from "./classifier.js";
|
|
29
|
+
export { classifyText, scanClassifier, classifierInfo, withoutProtectiveNotices, jsonValues } from "./classifier.js";
|
|
30
30
|
export { CLASSIFIER_MODEL } from "./classifier-model.js";
|
|
31
31
|
export { shellTokens, shellInvocations, shellOutputSource, shellWrites, shellUploads } from "./shell-commands.js";
|
|
32
32
|
export { inspectImage, helperRunner, visionHelperPath, visionHelperProblem, visionHelperSource, buildVisionHelper, buildNativeHelper } from "./image.js";
|
package/dist/src/index.js
CHANGED
|
@@ -17,7 +17,7 @@ export { adaptTerminal } from "./terminal.js";
|
|
|
17
17
|
export { adaptEmail, parseEmail, looksLikeEmailJson, looksLikeRawEmail } from "./email.js";
|
|
18
18
|
export { adaptCalendar, parseIcs, looksLikeCalendarJson } from "./calendar.js";
|
|
19
19
|
export { passagesOnlyIn } from "./served.js";
|
|
20
|
-
export { classifyText, scanClassifier, classifierInfo, withoutProtectiveNotices } from "./classifier.js";
|
|
20
|
+
export { classifyText, scanClassifier, classifierInfo, withoutProtectiveNotices, jsonValues } from "./classifier.js";
|
|
21
21
|
export { CLASSIFIER_MODEL } from "./classifier-model.js";
|
|
22
22
|
export { shellTokens, shellInvocations, shellOutputSource, shellWrites, shellUploads } from "./shell-commands.js";
|
|
23
23
|
export { inspectImage, helperRunner, visionHelperPath, visionHelperProblem, visionHelperSource, buildVisionHelper, buildNativeHelper } from "./image.js";
|
package/dist/src/meaning.js
CHANGED
|
@@ -435,10 +435,16 @@ function scoreText(text, hidden, where, findings, inCode = false) {
|
|
|
435
435
|
// tokens are symbol-laced as a matter of course, and four ordinary emails in three thousand were refused for it.
|
|
436
436
|
// In those channels a visible suffix is weak evidence: it counts beside something else, never alone.
|
|
437
437
|
if (!inCode) {
|
|
438
|
-
|
|
438
|
+
// In JSON the visible text is its values joined, and the suffix test read the last value as a suffix on the
|
|
439
|
+
// values before it: a short ordinary value with a few symbols in it, last in a document, was refused (55 of
|
|
440
|
+
// 4,615 benign public texts, as the last value after thirty rows). A suffix is appended to a prompt, so in
|
|
441
|
+
// JSON each value is tested as a text of its own, wherever it stands (0.9.30). And values are option names,
|
|
442
|
+
// identifiers and placeholders as a matter of course (a compiler's message catalogue has thousands that end
|
|
443
|
+
// in three of them), so in JSON a visible suffix is weak evidence, as in a message or a log.
|
|
444
|
+
const sfx = !hidden && valueTexts ? valueTexts.map(adversarialSuffix).find((x) => x) ?? null : adversarialSuffix(text);
|
|
439
445
|
if (sfx)
|
|
440
446
|
findings.push({
|
|
441
|
-
pass: "meaning", kind: "meaning.adversarial_suffix", confidence: hidden ? 0.7 : SUFFIX_WEAK.has(channelKind) ? 0.3 : 0.55, severity: 0.6,
|
|
447
|
+
pass: "meaning", kind: "meaning.adversarial_suffix", confidence: hidden ? 0.7 : SUFFIX_WEAK.has(channelKind) || valueTexts ? 0.3 : 0.55, severity: 0.6,
|
|
442
448
|
message: `optimizer-style adversarial suffix: ${sfx.weird} of the last ${sfx.tokens} tokens are symbol-laced fragments after ordinary prose (GCG-style jailbreak)`,
|
|
443
449
|
excerpt: sfx.tail.slice(-120), location: where, inHidden: hidden, action: "neutralized",
|
|
444
450
|
});
|
|
@@ -536,6 +542,8 @@ function adversarialSuffix(text) {
|
|
|
536
542
|
const SUFFIX_WEAK = new Set(["email", "log", "calendar", "message", "notification"]);
|
|
537
543
|
/** the kind of the content being scanned; set for the duration of one scanMeaning call (the pass is synchronous) */
|
|
538
544
|
let channelKind = "";
|
|
545
|
+
/** in JSON, the delivered values one by one: what the suffix test reads in place of the joined text (same lifetime) */
|
|
546
|
+
let valueTexts;
|
|
539
547
|
export function scanMeaning(input) {
|
|
540
548
|
channelKind = input.kind ?? "";
|
|
541
549
|
try {
|
|
@@ -543,6 +551,7 @@ export function scanMeaning(input) {
|
|
|
543
551
|
}
|
|
544
552
|
finally {
|
|
545
553
|
channelKind = "";
|
|
554
|
+
valueTexts = undefined;
|
|
546
555
|
}
|
|
547
556
|
}
|
|
548
557
|
function scanMeaningInner(input) {
|
|
@@ -556,6 +565,7 @@ function scanMeaningInner(input) {
|
|
|
556
565
|
// code blocks are scored separately with the documentation discount
|
|
557
566
|
const codeBlocks = [...(visibleRaw.match(FENCED) ?? []), ...delivered.filter(inPre).map((s) => s.text)];
|
|
558
567
|
const visible = visibleRaw.replace(FENCED, " ");
|
|
568
|
+
valueTexts = input.kind === "json" && delivered.length > 1 ? delivered.map((s) => s.text) : undefined;
|
|
559
569
|
if (visible.trim()) {
|
|
560
570
|
scoreText(visible, false, "visible text", findings);
|
|
561
571
|
// a foreign-language article quoting the phrase is reporting it, the same discount English gets
|
package/dist/src/types.d.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* at the same source would not see is suspect by default.
|
|
6
6
|
*/
|
|
7
7
|
import type { NetPolicy } from "./netpolicy.js";
|
|
8
|
-
export declare const ENGINE_VERSION = "0.9.
|
|
8
|
+
export declare const ENGINE_VERSION = "0.9.30";
|
|
9
9
|
/** bump whenever a detector's behavior changes; receipts carry it so verdicts are reproducible */
|
|
10
|
-
export declare const RULESET_VERSION = "2026.11.21-
|
|
10
|
+
export declare const RULESET_VERSION = "2026.11.21-3";
|
|
11
11
|
/**
|
|
12
12
|
* clean: delivered. suspect: refused, overridable. hostile: refused, not overridable.
|
|
13
13
|
* unreachable: nothing could be fetched or read (network error, timeout, redirect loop,
|
package/dist/src/types.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* Governing principle: anything the model would receive that a human looking
|
|
5
5
|
* at the same source would not see is suspect by default.
|
|
6
6
|
*/
|
|
7
|
-
export const ENGINE_VERSION = "0.9.
|
|
7
|
+
export const ENGINE_VERSION = "0.9.30";
|
|
8
8
|
/** bump whenever a detector's behavior changes; receipts carry it so verdicts are reproducible */
|
|
9
|
-
export const RULESET_VERSION = "2026.11.21-
|
|
9
|
+
export const RULESET_VERSION = "2026.11.21-3";
|
|
10
10
|
export const CONTENT_KINDS = ["html", "markdown", "json", "text", "javascript", "log", "email", "calendar", "message", "notification", "nearby", "automation", "captions", "image", "audio", "video"];
|
|
11
11
|
/** Read a content kind and source from untyped input (an HTTP body, tool arguments). Unknown values are dropped, never guessed. */
|
|
12
12
|
export function parseScanHints(o) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acepaste/ingress",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.30",
|
|
4
4
|
"description": "AcePaste Ingress engine: acquire, visibility, character, script, supply-chain, sandbox, meaning, verdict, envelope, receipts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/src/index.js",
|