@raibitsi/tiresias 1.0.1 → 1.2.0
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 +88 -0
- package/README.md +72 -33
- package/data/README.md +33 -0
- package/data/guard-ordinary-urls.txt +102 -0
- package/data/guard-starter.jsonl +424 -0
- package/dist/aimed.js +23 -0
- package/dist/anchor.js +26 -13
- package/dist/browsecli.js +17 -13
- package/dist/cdp.js +22 -1
- package/dist/cleanup.js +3 -1
- package/dist/cli.js +216 -68
- package/dist/config.js +75 -1
- package/dist/confirm.js +20 -5
- package/dist/cooldown.js +57 -32
- package/dist/dailylog.js +11 -5
- package/dist/dom.js +13 -8
- package/dist/doors.js +1 -1
- package/dist/engine.js +9 -4
- package/dist/envelope.js +10 -1
- package/dist/fetcher.js +29 -2
- package/dist/filereply.js +7 -1
- package/dist/formflow.js +21 -3
- package/dist/forms.js +337 -42
- package/dist/getactions.js +119 -0
- package/dist/guard.js +1240 -0
- package/dist/guardclient.js +245 -0
- package/dist/guardnetwork.js +22 -0
- package/dist/history.js +11 -5
- package/dist/hook.js +2 -0
- package/dist/hosts.js +34 -27
- package/dist/keys.js +420 -18
- package/dist/local.js +537 -0
- package/dist/mcp.js +56 -25
- package/dist/needs.js +9 -5
- package/dist/parentwatch.js +6 -16
- package/dist/pdf.js +4 -1
- package/dist/pdfchild.js +0 -2
- package/dist/pdfproc.js +26 -11
- package/dist/pdfwatch.js +14 -0
- package/dist/pipeline.js +117 -26
- package/dist/preformatted.js +12 -0
- package/dist/profiles.js +3 -3
- package/dist/queue.js +24 -20
- package/dist/reader.js +441 -87
- package/dist/receipts.js +7 -2
- package/dist/render.js +156 -27
- package/dist/renderactions.js +69 -0
- package/dist/resume.js +8 -6
- package/dist/rules.js +24 -5
- package/dist/safebrowsing.js +3 -3
- package/dist/safety.js +15 -7
- package/dist/sandbox.js +1 -1
- package/dist/saved.js +24 -9
- package/dist/savedlock.js +99 -5
- package/dist/settings.js +10 -3
- package/dist/shelf.js +1 -1
- package/dist/shield.js +15 -0
- package/dist/slips.js +43 -1
- package/dist/store.js +119 -25
- package/dist/tabs.js +1 -1
- package/dist/textview.js +16 -0
- package/dist/translate.js +22 -2
- package/dist/types.js +9 -2
- package/dist/watchflow.js +1 -2
- package/dist/work.js +10 -2
- package/docs/LOCAL-MODELS.md +271 -0
- package/package.json +5 -2
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Known GET form targets are policy, not a guess about what an arbitrary GET does.
|
|
3
|
+
import { loadChoice } from "./config.js";
|
|
4
|
+
import { Refused } from "./errors.js";
|
|
5
|
+
import { cachePath, homeDir, isPrivate, readJson, sha256, writeJson } from "./store.js";
|
|
6
|
+
import { normalizePath } from "./rules.js";
|
|
7
|
+
import { callContext } from "./context.js";
|
|
8
|
+
import { claimSlip, claimedStillValid } from "./slips.js";
|
|
9
|
+
const shared = { seen: new Set() };
|
|
10
|
+
const MAX_SEEN = 4096;
|
|
11
|
+
// Every shared overflow target enters this fixed 8 KiB Bloom filter, saved or not.
|
|
12
|
+
// With 65,536 bits and 4 probes, estimated false positive rates (uniform hashes) are
|
|
13
|
+
// 0.239% at 4,096, 16.0% at 16,384 and 92.9% at 65,536 overflow targets. No false
|
|
14
|
+
// negatives during this process; collisions only require extra slips. Private observations never enter it.
|
|
15
|
+
const sharedOverflow = new Uint8Array(8192);
|
|
16
|
+
function overflowBits(key) {
|
|
17
|
+
const hash = sha256(key);
|
|
18
|
+
return [0, 4, 8, 12].map((i) => parseInt(hash.slice(i, i + 4), 16));
|
|
19
|
+
}
|
|
20
|
+
function inSharedOverflow(key) {
|
|
21
|
+
return overflowBits(key).every((bit) => (sharedOverflow[bit >>> 3] & (1 << (bit & 7))) !== 0);
|
|
22
|
+
}
|
|
23
|
+
// A denial comparison, never a URL to send or a permission-slip scope. Reuse the robots path
|
|
24
|
+
// normalizer for unreserved octets and escape case, then fold ambiguous server routing spellings
|
|
25
|
+
// conservatively: repeated decoding, separators, path parameters, Unicode, case and dot segments.
|
|
26
|
+
// At a fixed point, keep only Unicode letters and digits per segment, dropping empty segments.
|
|
27
|
+
// URL already handles IDNA, IP spellings, host case and default ports. No DNS alias guessing.
|
|
28
|
+
export function getActionTarget(u) {
|
|
29
|
+
const host = new URL(u.origin);
|
|
30
|
+
host.hostname = host.hostname.replace(/\.+$/, "");
|
|
31
|
+
let path = normalizePath(u.pathname);
|
|
32
|
+
// Repeat the whole fold: NFKC itself can introduce a fresh percent escape.
|
|
33
|
+
// Bound nested encoding work; the wildcard is a denial key for the entire origin.
|
|
34
|
+
for (let i = 0; i < 64; i++) {
|
|
35
|
+
let next = path.replace(/(?:%[0-9a-f]{2})+/gi, (s) => {
|
|
36
|
+
try {
|
|
37
|
+
return decodeURIComponent(s);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return s.replace(/%([0-7][0-9a-f])/gi, (_, h) => String.fromCharCode(parseInt(h, 16)));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
// URL parsers remove these controls before resolving dot segments and escapes.
|
|
44
|
+
next = next.replace(/[\t\n\r]/g, "");
|
|
45
|
+
next = next.normalize("NFKC").toLowerCase().replace(/\\/g, "/").split(/[?#\0]/)[0];
|
|
46
|
+
const parts = [];
|
|
47
|
+
for (const part of next.split("/")) {
|
|
48
|
+
const seg = part.split(";")[0].replace(/ +$/, "");
|
|
49
|
+
if (seg === "..")
|
|
50
|
+
parts.pop();
|
|
51
|
+
// Keep dots until nested escapes can expose a dot segment, such as .%2509.
|
|
52
|
+
else if (seg && seg !== ".")
|
|
53
|
+
parts.push(/%[0-9a-f]{2}/i.test(seg) ? seg : seg.replace(/[. ]+$/, ""));
|
|
54
|
+
}
|
|
55
|
+
next = "/" + parts.filter(Boolean).join("/");
|
|
56
|
+
if (next === path) {
|
|
57
|
+
// Preserve the origin wildcard, including when a denial key is folded again.
|
|
58
|
+
if (next === "/*")
|
|
59
|
+
return `${host.origin}/*`;
|
|
60
|
+
next = "/" + next.split("/").map((seg) => seg.replace(/[^\p{L}\p{N}]/gu, "")).filter(Boolean).join("/");
|
|
61
|
+
if (next === path)
|
|
62
|
+
return `${host.origin}${next}`;
|
|
63
|
+
// Removing punctuation can join Unicode letters that then compose under NFKC.
|
|
64
|
+
// Converge again within the same bound so the final denial key stays idempotent.
|
|
65
|
+
}
|
|
66
|
+
path = next;
|
|
67
|
+
}
|
|
68
|
+
return `${host.origin}/*`;
|
|
69
|
+
}
|
|
70
|
+
// Inputs are already folded, so a renderer folds its request only once.
|
|
71
|
+
export function getActionTargetsMatch(a, b) {
|
|
72
|
+
return a === b || ((a.endsWith("/*") || b.endsWith("/*")) && new URL(a).origin === new URL(b).origin);
|
|
73
|
+
}
|
|
74
|
+
const actionKey = (u) => `get-form:${getActionTarget(u)}`;
|
|
75
|
+
function observations() {
|
|
76
|
+
if (!isPrivate())
|
|
77
|
+
return shared;
|
|
78
|
+
const ctx = callContext.getStore();
|
|
79
|
+
// A caller without a call scope must never put private observations in shared memory.
|
|
80
|
+
return ctx ? (ctx.getActions ??= { seen: new Set(), full: false }) : undefined;
|
|
81
|
+
}
|
|
82
|
+
const memoryKey = (key) => `${homeDir()}\0${key}`;
|
|
83
|
+
export function noteGetActions(forms = [], keep = false) {
|
|
84
|
+
const state = observations();
|
|
85
|
+
for (const f of forms) {
|
|
86
|
+
if (f.method !== "GET" || !f.action)
|
|
87
|
+
continue;
|
|
88
|
+
const key = actionKey(new URL(f.action));
|
|
89
|
+
const mk = memoryKey(key);
|
|
90
|
+
const saved = keep && !isPrivate() && !callContext.getStore()?.readOnly;
|
|
91
|
+
if (state && !state.seen.has(mk)) {
|
|
92
|
+
if (state.seen.size < MAX_SEEN)
|
|
93
|
+
state.seen.add(mk);
|
|
94
|
+
else if (state === shared)
|
|
95
|
+
for (const bit of overflowBits(mk))
|
|
96
|
+
sharedOverflow[bit >>> 3] |= 1 << (bit & 7);
|
|
97
|
+
else if ("full" in state)
|
|
98
|
+
state.full = true; // private overflow fails closed only for this call
|
|
99
|
+
}
|
|
100
|
+
// Record policy in memory before writing, so a failed write also fails closed.
|
|
101
|
+
if (saved)
|
|
102
|
+
writeJson(cachePath(key), { get_form_action: true, fetched_at: new Date().toISOString() });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export function guardGetAction(u) {
|
|
106
|
+
if (loadChoice("get_form_actions") !== "slip")
|
|
107
|
+
return;
|
|
108
|
+
const target = getActionTarget(u);
|
|
109
|
+
const key = `get-form:${target}`;
|
|
110
|
+
const state = callContext.getStore()?.getActions;
|
|
111
|
+
const wildcard = `get-form:${new URL(target).origin}/*`;
|
|
112
|
+
const known = key === wildcard || [key, wildcard].some((k) => inSharedOverflow(memoryKey(k))) || state?.full || [state, shared].some((s) => s?.seen.has(memoryKey(key)) || s?.seen.has(memoryKey(wildcard))) ||
|
|
113
|
+
[key, wildcard].some((k) => readJson(cachePath(k))?.get_form_action === true);
|
|
114
|
+
if (!known)
|
|
115
|
+
return;
|
|
116
|
+
const claim = claimSlip("submit_form", u.href, "get_form_action");
|
|
117
|
+
if ("refused" in claim || !claimedStillValid(claim, "submit_form", u.href))
|
|
118
|
+
throw new Refused("This GET needs a current submit_form permission slip: its target matches an observed form action, or the observation limit was reached. Nothing was sent.");
|
|
119
|
+
}
|