@acepaste/ingress 0.0.0-stage → 0.7.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.
Files changed (43) hide show
  1. package/LICENSE +105 -0
  2. package/README.md +15 -2
  3. package/dist/src/acepaste-alphabet.d.ts +26 -0
  4. package/dist/src/acepaste-alphabet.js +47 -0
  5. package/dist/src/acquire.d.ts +24 -0
  6. package/dist/src/acquire.js +146 -0
  7. package/dist/src/adapters.d.ts +30 -0
  8. package/dist/src/adapters.js +160 -0
  9. package/dist/src/character.d.ts +22 -0
  10. package/dist/src/character.js +291 -0
  11. package/dist/src/cli.d.ts +2 -0
  12. package/dist/src/cli.js +63 -0
  13. package/dist/src/color.d.ts +26 -0
  14. package/dist/src/color.js +111 -0
  15. package/dist/src/engine.d.ts +108 -0
  16. package/dist/src/engine.js +612 -0
  17. package/dist/src/evidence.d.ts +21 -0
  18. package/dist/src/evidence.js +77 -0
  19. package/dist/src/index.d.ts +26 -0
  20. package/dist/src/index.js +19 -0
  21. package/dist/src/meaning.d.ts +28 -0
  22. package/dist/src/meaning.js +226 -0
  23. package/dist/src/netpolicy.d.ts +34 -0
  24. package/dist/src/netpolicy.js +122 -0
  25. package/dist/src/normalize.d.ts +34 -0
  26. package/dist/src/normalize.js +204 -0
  27. package/dist/src/policyfile.d.ts +2 -0
  28. package/dist/src/policyfile.js +50 -0
  29. package/dist/src/sandbox.d.ts +45 -0
  30. package/dist/src/sandbox.js +231 -0
  31. package/dist/src/script.d.ts +23 -0
  32. package/dist/src/script.js +220 -0
  33. package/dist/src/secrets.d.ts +24 -0
  34. package/dist/src/secrets.js +192 -0
  35. package/dist/src/supplychain.d.ts +24 -0
  36. package/dist/src/supplychain.js +182 -0
  37. package/dist/src/taint.d.ts +37 -0
  38. package/dist/src/taint.js +39 -0
  39. package/dist/src/types.d.ts +176 -0
  40. package/dist/src/types.js +25 -0
  41. package/dist/src/visibility.d.ts +41 -0
  42. package/dist/src/visibility.js +424 -0
  43. package/package.json +64 -4
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Taint guard: opt-in capability control (CaMeL-style separation of
3
+ * untrusted data from side-effecting actions).
4
+ *
5
+ * Once a session has ingested content at or above the configured tier,
6
+ * tools named in `sideEffectTools` are held until `confirm()` is called by
7
+ * the user-facing layer. Nothing here is mandatory; it is middleware the
8
+ * integrator wraps around tool dispatch.
9
+ */
10
+ import type { IngressResult, Tier } from "./types.js";
11
+ export interface TaintPolicy {
12
+ /** tier at which the session becomes tainted; default "suspect" */
13
+ taintAt: Tier;
14
+ /** tool names that must pause while tainted */
15
+ sideEffectTools: string[];
16
+ /** how long a confirmation stays valid, milliseconds */
17
+ confirmationTtlMs: number;
18
+ }
19
+ export interface TaintGuard {
20
+ /** record a gate result; returns the session's taint state */
21
+ ingest(result: IngressResult): {
22
+ tainted: boolean;
23
+ sources: string[];
24
+ };
25
+ /** true if this tool call may proceed now */
26
+ allow(toolName: string): boolean;
27
+ /** user confirmed a side-effect; unlocks sideEffectTools for the TTL */
28
+ confirm(): void;
29
+ /** forget taint (new task, new context) */
30
+ reset(): void;
31
+ readonly state: {
32
+ tainted: boolean;
33
+ sources: string[];
34
+ confirmedUntil: number;
35
+ };
36
+ }
37
+ export declare function createTaintGuard(policy?: Partial<TaintPolicy>): TaintGuard;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Taint guard: opt-in capability control (CaMeL-style separation of
3
+ * untrusted data from side-effecting actions).
4
+ *
5
+ * Once a session has ingested content at or above the configured tier,
6
+ * tools named in `sideEffectTools` are held until `confirm()` is called by
7
+ * the user-facing layer. Nothing here is mandatory; it is middleware the
8
+ * integrator wraps around tool dispatch.
9
+ */
10
+ const TIER_RANK = { clean: 0, suspect: 1, hostile: 2 };
11
+ export function createTaintGuard(policy = {}) {
12
+ const p = {
13
+ taintAt: policy.taintAt ?? "suspect",
14
+ sideEffectTools: policy.sideEffectTools ?? ["send", "email", "post", "write", "delete", "pay", "transfer", "execute", "shell", "deploy"],
15
+ confirmationTtlMs: policy.confirmationTtlMs ?? 60_000,
16
+ };
17
+ const state = { tainted: false, sources: [], confirmedUntil: 0 };
18
+ return {
19
+ state,
20
+ ingest(result) {
21
+ if (TIER_RANK[result.tier] >= TIER_RANK[p.taintAt]) {
22
+ state.tainted = true;
23
+ if (!state.sources.includes(result.receipt.finalUrl))
24
+ state.sources.push(result.receipt.finalUrl);
25
+ }
26
+ return { tainted: state.tainted, sources: [...state.sources] };
27
+ },
28
+ allow(toolName) {
29
+ if (!state.tainted)
30
+ return true;
31
+ const isSideEffect = p.sideEffectTools.some((s) => toolName.toLowerCase().includes(s));
32
+ if (!isSideEffect)
33
+ return true;
34
+ return Date.now() < state.confirmedUntil;
35
+ },
36
+ confirm() { state.confirmedUntil = Date.now() + p.confirmationTtlMs; },
37
+ reset() { state.tainted = false; state.sources.length = 0; state.confirmedUntil = 0; },
38
+ };
39
+ }
@@ -0,0 +1,176 @@
1
+ /**
2
+ * AcePaste Ingress — shared types.
3
+ *
4
+ * Governing principle: anything the model would receive that a human looking
5
+ * at the same source would not see is suspect by default.
6
+ */
7
+ import type { NetPolicy } from "./netpolicy.js";
8
+ export declare const ENGINE_VERSION = "0.7.0";
9
+ /** bump whenever a detector's behavior changes; receipts carry it so verdicts are reproducible */
10
+ export declare const RULESET_VERSION = "2026.10.31-1";
11
+ export type Tier = "clean" | "suspect" | "hostile";
12
+ export type ContentKind = "html" | "markdown" | "json" | "text" | "javascript";
13
+ export type PassName = "acquire" | "policy" | "visibility" | "character" | "script" | "supplychain" | "secrets" | "meaning" | "cloaking" | "sandbox" | "plugin";
14
+ export type FindingKind = "policy.denied_source" | "policy.redirect_chain" | "unicode.tag_characters" | "unicode.zero_width" | "unicode.bidi_control" | "unicode.variation_selector_smuggling" | "unicode.mixed_script_confusable" | "unicode.fullwidth_or_math_lookalike" | "unicode.combining_flood" | "unicode.encoded_payload" | "unicode.entity_smuggling" | "unicode.whitespace_channel" | "visibility.css_hidden" | "visibility.offscreen" | "visibility.attribute_only" | "visibility.html_comment" | "visibility.tiny_or_transparent" | "visibility.markdown_hidden" | "script.obfuscation" | "script.runtime_codegen" | "script.automation_detection" | "script.post_load_text_injection" | "script.exfil_beacon" | "script.binary_decoding" | "supplychain.lifecycle_script" | "supplychain.url_dependency" | "supplychain.offregistry_resolution" | "supplychain.install_instruction" | "secrets.credential_in_content" | "sandbox.text_injected_after_load" | "sandbox.webdriver_keyed_divergence" | "sandbox.computed_hidden_text" | "sandbox.blocked_egress_attempt" | "meaning.instruction_shaped" | "meaning.role_token" | "meaning.system_prompt_imitation" | "meaning.tool_call_shaped" | "meaning.exfil_markdown_image" | "meaning.exfil_link" | "cloaking.agent_targeted_divergence" | `plugin.${string}`;
15
+ export interface Finding {
16
+ pass: PassName;
17
+ kind: FindingKind;
18
+ /** 0..1 confidence that this is an attack rather than benign structure */
19
+ confidence: number;
20
+ /** 0..1 severity if it is an attack */
21
+ severity: number;
22
+ /** short human-readable explanation */
23
+ message: string;
24
+ /** excerpt of the offending material, already made safe to print */
25
+ excerpt?: string;
26
+ /** location hint: character offset, selector path, or script index */
27
+ location?: string;
28
+ /** what the engine did about it */
29
+ action: "none" | "neutralized" | "quarantined";
30
+ /** Kith & Revere evidence model, attached by the engine: a finding is a conclusion, never a Fact */
31
+ evidenceClass?: "inference" | "hypothesis";
32
+ /** confidence band: high >= 0.8, medium >= 0.5, low below */
33
+ band?: "high" | "medium" | "low";
34
+ /** sha256 of the artifact the finding cites: its excerpt, or the whole acquired body */
35
+ artifactDigest?: string;
36
+ /** the benign explanation a reviewer should rule out before acting */
37
+ altExplanation?: string;
38
+ }
39
+ export interface AcquireResult {
40
+ url: string;
41
+ finalUrl: string;
42
+ redirectChain: string[];
43
+ status: number;
44
+ headers: Record<string, string>;
45
+ contentType: string;
46
+ /** raw body as text (binary bodies are refused upstream) */
47
+ body: string;
48
+ /** which fingerprint this acquisition used */
49
+ fingerprint: "human" | "agent";
50
+ fetchedAt: string;
51
+ }
52
+ export interface TextSegment {
53
+ text: string;
54
+ /** visible: a sighted human reading the rendered page sees this */
55
+ visibility: "visible" | "css_hidden" | "offscreen" | "attribute" | "comment" | "tiny_or_transparent";
56
+ /** selector-ish path for the location field */
57
+ path: string;
58
+ }
59
+ export interface ScriptUnit {
60
+ index: number;
61
+ source: string;
62
+ inline: boolean;
63
+ src?: string;
64
+ }
65
+ /** What a custom detector sees. Everything is read-only. */
66
+ export interface DetectorContext {
67
+ url: string;
68
+ contentKind: ContentKind;
69
+ raw: string;
70
+ segments: ReadonlyArray<TextSegment>;
71
+ scripts: ReadonlyArray<ScriptUnit>;
72
+ decodedPayloads: ReadonlyArray<string>;
73
+ }
74
+ /** Plugin interface. Findings are returned with kind `plugin.<name>`. */
75
+ export interface Detector {
76
+ name: string;
77
+ version: string;
78
+ run(ctx: DetectorContext): Finding[] | Promise<Finding[]>;
79
+ }
80
+ export interface DomainRule {
81
+ /** exact host or `.suffix` */
82
+ match: string;
83
+ /** refuse outright regardless of content */
84
+ deny?: boolean;
85
+ suspectThreshold?: number;
86
+ hostileThreshold?: number;
87
+ /** skip the second fetch for this host */
88
+ cloakingCheck?: boolean;
89
+ }
90
+ export interface IngressPolicy {
91
+ domains: DomainRule[];
92
+ }
93
+ export interface TaintReceipt {
94
+ version: "3";
95
+ engineVersion: string;
96
+ rulesetVersion: string;
97
+ issuedAt: string;
98
+ url: string;
99
+ finalUrl: string;
100
+ redirectChain: string[];
101
+ contentKind: ContentKind;
102
+ /** count of hostile invisible characters per the shared AcePaste alphabet (cross-tool parity) */
103
+ acepasteInvisibleCount: number;
104
+ /** sha256 of the raw acquired body */
105
+ rawDigest: string;
106
+ /** sha256 of the delivered text (empty string when refused) */
107
+ deliveredDigest: string;
108
+ tier: Tier;
109
+ score: number;
110
+ /** suspect content was delivered because a human explicitly asked for it */
111
+ overridden: boolean;
112
+ /** which passes actually ran (sandbox may not have) */
113
+ passesRun: PassName[];
114
+ findings: Array<Pick<Finding, "pass" | "kind" | "confidence" | "severity" | "action" | "evidenceClass" | "band" | "artifactDigest">>;
115
+ /** how `signature` was made: a shared-secret HMAC (only the key holder can verify) or ECDSA P-256 (anyone with the public key can verify, nobody without the private key can forge) */
116
+ signatureAlg?: "hmac-sha256" | "ecdsa-p256-sha256";
117
+ /** first 16 hex characters of sha256 over the signer's public key (ECDSA only) */
118
+ keyId?: string;
119
+ /** sha256 of the previous receipt in this session, for audit chains */
120
+ previous?: string;
121
+ /** sha256 of this receipt's canonical body (without signature) */
122
+ digest: string;
123
+ /** HMAC-SHA256 over the canonical receipt body, when a signing key was configured */
124
+ signature?: string;
125
+ }
126
+ export interface IngressResult {
127
+ tier: Tier;
128
+ /** aggregate attack score, 0..1 */
129
+ score: number;
130
+ contentKind: ContentKind;
131
+ /** text delivered to the model; empty unless tier is clean or a suspect verdict was overridden */
132
+ delivered: string;
133
+ /** true when suspect text was delivered under human override */
134
+ overridden: boolean;
135
+ /** spotlighting-style envelope the caller should hand to the model verbatim */
136
+ envelope: string;
137
+ findings: Finding[];
138
+ receipt: TaintReceipt;
139
+ /** timing in milliseconds per pass, for the speed budget */
140
+ timings: Partial<Record<PassName | "total", number>>;
141
+ }
142
+ export interface IngressConfig {
143
+ /** score at or above which the page is refused and cannot be overridden */
144
+ hostileThreshold: number;
145
+ /** score at or above which the page is refused but may be overridden */
146
+ suspectThreshold: number;
147
+ /** run the second, human-fingerprinted fetch and compare */
148
+ cloakingCheck: boolean;
149
+ /** maximum body size accepted, bytes */
150
+ maxBodyBytes: number;
151
+ /** fetch timeout, milliseconds */
152
+ fetchTimeoutMs: number;
153
+ /** optional HMAC key for signing receipts (shared secret: verifiers can also forge) */
154
+ signingKey?: string;
155
+ /** optional ECDSA P-256 private key, PEM (PKCS#8). Preferred over signingKey: receipts become publicly verifiable and unforgeable */
156
+ signingPrivateKey?: string;
157
+ /** cache verdicts by url for this many seconds; 0 disables */
158
+ cacheTtlSeconds: number;
159
+ /** "off": static only. "escalate": run when the static script pass is suspicious. "always": every HTML page. */
160
+ sandbox: "off" | "escalate" | "always";
161
+ /** sandbox per-page budget, milliseconds */
162
+ sandboxTimeoutMs: number;
163
+ /** static suspicion at or above which sandbox escalates (when sandbox = "escalate") */
164
+ sandboxEscalateAt: number;
165
+ /** fetch and parse linked stylesheets for the static visibility pass (same origin only) */
166
+ fetchStylesheets: boolean;
167
+ /** network policy: what the gate itself may connect to */
168
+ net: NetPolicy;
169
+ /** per-domain rules */
170
+ policy: IngressPolicy;
171
+ /** custom detectors */
172
+ detectors: Detector[];
173
+ /** chain receipts: each receipt carries the digest of the previous one */
174
+ chainReceipts: boolean;
175
+ }
176
+ export declare const DEFAULT_CONFIG: IngressConfig;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * AcePaste Ingress — shared types.
3
+ *
4
+ * Governing principle: anything the model would receive that a human looking
5
+ * at the same source would not see is suspect by default.
6
+ */
7
+ export const ENGINE_VERSION = "0.7.0";
8
+ /** bump whenever a detector's behavior changes; receipts carry it so verdicts are reproducible */
9
+ export const RULESET_VERSION = "2026.10.31-1";
10
+ export const DEFAULT_CONFIG = {
11
+ hostileThreshold: 0.7,
12
+ suspectThreshold: 0.25,
13
+ cloakingCheck: true,
14
+ maxBodyBytes: 5 * 1024 * 1024,
15
+ fetchTimeoutMs: 15000,
16
+ cacheTtlSeconds: 86400,
17
+ sandbox: "escalate",
18
+ sandboxTimeoutMs: 8000,
19
+ sandboxEscalateAt: 0.5,
20
+ fetchStylesheets: true,
21
+ net: { denyHosts: [], allowHosts: [], extraPorts: [], allowPrivate: false },
22
+ policy: { domains: [] },
23
+ detectors: [],
24
+ chainReceipts: true,
25
+ };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Visibility pass.
3
+ *
4
+ * Labels every piece of text by whether a sighted human reading the rendered
5
+ * page would see it. Static only: inline styles, hidden attributes, the
6
+ * page's own <style> blocks and any same-origin stylesheets the engine
7
+ * fetched are consulted. Script-applied styles belong to the sandbox.
8
+ *
9
+ * Also extracts every <script> for the script pass. Traversal is iterative:
10
+ * attacker-controlled nesting depth must not be able to crash the gate.
11
+ */
12
+ import type { Finding, ScriptUnit, TextSegment } from "./types.js";
13
+ import { type RGBA } from "./color.js";
14
+ export interface HiddenRule {
15
+ selector: string;
16
+ reason: TextSegment["visibility"];
17
+ }
18
+ /** Classify a style declaration string. Returns the hiding reason or null. */
19
+ export declare function classifyStyle(style: string): TextSegment["visibility"] | null;
20
+ export declare function rulesFromCss(cssIn: string): HiddenRule[];
21
+ export interface ColorRule {
22
+ selector: string;
23
+ fg?: RGBA | null;
24
+ bg?: RGBA | null;
25
+ fill?: RGBA | null;
26
+ }
27
+ export declare function colorRulesFromCss(cssIn: string): ColorRule[];
28
+ export interface VisibilityResult {
29
+ segments: TextSegment[];
30
+ scripts: ScriptUnit[];
31
+ findings: Finding[];
32
+ /** concatenated visible text, whitespace-normalized */
33
+ visibleText: string;
34
+ /** hrefs of linked stylesheets, resolved by the caller */
35
+ stylesheetLinks: string[];
36
+ /** maximum element nesting depth seen */
37
+ maxDepth: number;
38
+ }
39
+ /** Collect hrefs of <link rel=stylesheet> so the engine can fetch them (same origin) before the real pass. */
40
+ export declare function findStylesheetLinks(html: string): string[];
41
+ export declare function analyzeHtml(html: string, externalRules?: HiddenRule[], externalColorRules?: ColorRule[]): VisibilityResult;