leakshield 0.3.0 → 0.4.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/LICENSE +202 -21
- package/NOTICE +2 -0
- package/README.md +39 -9
- package/README.zh-TW.md +38 -9
- package/dist/adapters/claude-code/capabilities.d.ts +14 -0
- package/dist/adapters/claude-code/capabilities.js +47 -0
- package/dist/adapters/claude-code/cli.d.ts +10 -0
- package/dist/adapters/claude-code/cli.js +51 -0
- package/dist/adapters/claude-code/doctor.d.ts +19 -0
- package/dist/adapters/claude-code/doctor.js +177 -0
- package/dist/adapters/claude-code/proxy.d.ts +47 -0
- package/dist/adapters/claude-code/proxy.js +348 -0
- package/dist/adapters/opencode/capabilities.d.ts +10 -0
- package/dist/adapters/opencode/capabilities.js +48 -0
- package/dist/adapters/opencode/doctor.d.ts +67 -0
- package/dist/{doctor.js → adapters/opencode/doctor.js} +16 -42
- package/dist/adapters/opencode/env-queries.d.ts +133 -0
- package/dist/adapters/opencode/env-tools.d.ts +20 -0
- package/dist/adapters/opencode/hooks.d.ts +4 -0
- package/dist/adapters/opencode/plugin.d.ts +12 -0
- package/dist/{opencode.js → adapters/opencode/plugin.js} +7 -7
- package/dist/adapters/opencode/tool-policy.d.ts +2 -0
- package/dist/adapters/opencode/tool-policy.js +23 -0
- package/dist/adapters/opencode/transparent-aisdk.d.ts +6 -0
- package/dist/{opencode-transparent-aisdk.js → adapters/opencode/transparent-aisdk.js} +1 -1
- package/dist/adapters/opencode/transparent.d.ts +66 -0
- package/dist/adapters/opencode/transparent.js +237 -0
- package/dist/adapters/opencode/v2.d.ts +20 -0
- package/dist/{opencode-v2.js → adapters/opencode/v2.js} +3 -3
- package/dist/adapters/pi/capabilities.d.ts +10 -0
- package/dist/adapters/pi/capabilities.js +50 -0
- package/dist/adapters/pi/doctor.d.ts +26 -0
- package/dist/adapters/pi/doctor.js +276 -0
- package/dist/adapters/pi/extension.d.ts +28 -0
- package/dist/adapters/pi/extension.js +109 -0
- package/dist/adapters/pi/guard.d.ts +33 -0
- package/dist/adapters/pi/guard.js +154 -0
- package/dist/adapters/pi/persistence.d.ts +9 -0
- package/dist/adapters/pi/persistence.js +69 -0
- package/dist/adapters/pi/settings.d.ts +51 -0
- package/dist/adapters/pi/settings.js +136 -0
- package/dist/adapters/pi/tool-policy.d.ts +11 -0
- package/dist/adapters/pi/tool-policy.js +114 -0
- package/dist/cli.d.ts +18 -0
- package/dist/cli.js +17 -6
- package/dist/config/loader.d.ts +70 -0
- package/dist/config/plain-object.d.ts +2 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.js +9 -0
- package/dist/core/session-guard.d.ts +61 -0
- package/dist/{opencode-transparent.js → core/session-guard.js} +55 -713
- package/dist/core/sse-recovery.d.ts +6 -0
- package/dist/core/tool-restore-policy.d.ts +153 -0
- package/dist/core/tool-restore-policy.js +453 -0
- package/dist/core/wire.d.ts +213 -0
- package/dist/{opencode-transparent-http.js → core/wire.js} +170 -50
- package/dist/core/ws.d.ts +26 -0
- package/dist/{opencode-transparent-ws.js → core/ws.js} +1 -1
- package/dist/decision/deidentify.d.ts +63 -0
- package/dist/decision/ingress.d.ts +40 -0
- package/dist/decision/mapping-key.d.ts +91 -0
- package/dist/decision/mapping-store.d.ts +166 -0
- package/dist/decision/model.d.ts +41 -0
- package/dist/decision/pseudonymization.d.ts +176 -0
- package/dist/decision/redaction.d.ts +56 -0
- package/dist/decision/schema-strings.d.ts +23 -0
- package/dist/decision/schema-strings.js +2 -2
- package/dist/decision/value-search.d.ts +39 -0
- package/dist/doctor-capabilities.d.ts +21 -0
- package/dist/doctor-capabilities.js +58 -0
- package/dist/doctor-hosts.d.ts +18 -0
- package/dist/doctor-hosts.js +144 -0
- package/dist/doctor-report.d.ts +45 -0
- package/dist/doctor-report.js +111 -0
- package/dist/forget.d.ts +18 -0
- package/dist/guard-options.d.ts +45 -0
- package/dist/{plugin-options.js → guard-options.js} +4 -1
- package/dist/help.d.ts +2 -0
- package/dist/help.js +15 -1
- package/dist/i18n/en.d.ts +65 -0
- package/dist/i18n/index.d.ts +15 -0
- package/dist/i18n/zh-TW.d.ts +65 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +1 -1
- package/dist/rules/builtin.d.ts +4 -0
- package/dist/rules/dynamic.d.ts +33 -0
- package/dist/scanner/allowlist.d.ts +22 -0
- package/dist/scanner/cidr.d.ts +39 -0
- package/dist/scanner/encoding.d.ts +87 -0
- package/dist/scanner/engine.d.ts +43 -0
- package/dist/scanner/exact-values.d.ts +11 -0
- package/dist/scanner/redaction-verifier.d.ts +24 -0
- package/dist/scanner/remotes.d.ts +29 -0
- package/dist/scanner/unicode.d.ts +57 -0
- package/dist/scanner/utils.d.ts +22 -0
- package/dist/transports/cli.d.ts +27 -0
- package/dist/transports/web-ui.d.ts +1 -0
- package/dist/transports/web-ui.js +1 -1
- package/dist/transports/web.d.ts +4 -0
- package/dist/types/capabilities.d.ts +67 -0
- package/dist/types/capabilities.js +133 -0
- package/dist/types.d.ts +149 -0
- package/dist/utils/files.d.ts +3 -0
- package/dist/utils/path-security.d.ts +18 -0
- package/dist/utils/win-encoding.d.ts +16 -0
- package/package.json +15 -5
- /package/dist/{env-queries.js → adapters/opencode/env-queries.js} +0 -0
- /package/dist/{opencode-env-tools.js → adapters/opencode/env-tools.js} +0 -0
- /package/dist/{opencode-hooks.js → adapters/opencode/hooks.js} +0 -0
- /package/dist/{opencode-transparent-stream.js → core/sse-recovery.js} +0 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export type CapabilityState = "protected" | "refused" | "not-present" | "outside" | "unknown";
|
|
2
|
+
export interface Capability {
|
|
3
|
+
state: CapabilityState;
|
|
4
|
+
/** The core handler this egress reaches, or where the request is refused. */
|
|
5
|
+
mechanism: string;
|
|
6
|
+
/** Required for protected and not-present; expected for refused. A repo-relative path. */
|
|
7
|
+
evidence?: string;
|
|
8
|
+
/** Residual risk or coverage limit; only what is true. */
|
|
9
|
+
note?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface HostCapabilities {
|
|
12
|
+
/** "opencode" | "claude-code" | "pi" */
|
|
13
|
+
host: string;
|
|
14
|
+
/** The host version the rows were verified against. */
|
|
15
|
+
verifiedVersion: string;
|
|
16
|
+
interception: "in-process-fetch" | "in-process-host-hook" | "loopback-proxy" | "preload";
|
|
17
|
+
transports: {
|
|
18
|
+
/** Model HTTP: the three wire families, or the proxy's route. */
|
|
19
|
+
http: Capability;
|
|
20
|
+
websocket: Capability;
|
|
21
|
+
/** smithy / gRPC / node:http / an SDK's built-in transport. */
|
|
22
|
+
nonFetch: Capability;
|
|
23
|
+
};
|
|
24
|
+
surfaces: {
|
|
25
|
+
/** The local tool execution boundary. */
|
|
26
|
+
toolArgs: Capability;
|
|
27
|
+
/** Assistant text restoration. */
|
|
28
|
+
replyDisplay: Capability;
|
|
29
|
+
/** Compaction / branch summary / title. */
|
|
30
|
+
background: Capability;
|
|
31
|
+
};
|
|
32
|
+
credentials: "in-process" | "separated";
|
|
33
|
+
persistence: "opt-in" | "none";
|
|
34
|
+
/**
|
|
35
|
+
* Load order, a disabled extension, an unsupported provider, …
|
|
36
|
+
* Each entry starts with the row it qualifies, `<section>.<field>: `, so an
|
|
37
|
+
* `outside` row can be traced to its residual by invariant 4.
|
|
38
|
+
*/
|
|
39
|
+
residuals: string[];
|
|
40
|
+
}
|
|
41
|
+
export declare const CAPABILITY_ROWS: readonly ["transports.http", "transports.websocket", "transports.nonFetch", "surfaces.toolArgs", "surfaces.replyDisplay", "surfaces.background"];
|
|
42
|
+
export type CapabilityRow = (typeof CAPABILITY_ROWS)[number];
|
|
43
|
+
export declare const CAPABILITY_ROW_TITLES: Readonly<Record<CapabilityRow, string>>;
|
|
44
|
+
export declare function capabilityAt(capabilities: HostCapabilities, row: CapabilityRow): Capability;
|
|
45
|
+
export interface CapabilityVerdict {
|
|
46
|
+
verdict: "PROTECTED" | "PARTIAL";
|
|
47
|
+
unknown: CapabilityRow[];
|
|
48
|
+
outside: CapabilityRow[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* `unknown` and `outside` rows cap the host at PARTIAL. A host can still be
|
|
52
|
+
* PARTIAL for install-level reasons (hook-first mode, load order); this only
|
|
53
|
+
* answers what the declaration itself allows.
|
|
54
|
+
*/
|
|
55
|
+
export declare function capabilityVerdict(capabilities: HostCapabilities): CapabilityVerdict;
|
|
56
|
+
export declare class CapabilityInvariantError extends Error {
|
|
57
|
+
constructor(host: string, message: string);
|
|
58
|
+
}
|
|
59
|
+
export interface CapabilityAudit {
|
|
60
|
+
/** Repository root that evidence paths are resolved against. */
|
|
61
|
+
root?: string;
|
|
62
|
+
/** Injectable for tests that declare synthetic evidence. */
|
|
63
|
+
fileExists?(filePath: string): boolean;
|
|
64
|
+
/** Injectable alongside `fileExists`; a directory is not evidence. */
|
|
65
|
+
isFile?(filePath: string): boolean;
|
|
66
|
+
}
|
|
67
|
+
export declare function assertCapabilities(capabilities: HostCapabilities, audit?: CapabilityAudit): void;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host capability declaration.
|
|
3
|
+
*
|
|
4
|
+
* Every host adapter declares, for each model egress and each local surface,
|
|
5
|
+
* whether LeakShield protects it, refuses it, proves it does not exist, cannot
|
|
6
|
+
* reach it, or has not audited it yet. The doctor prints the same declaration;
|
|
7
|
+
* `docs/host-capabilities.md` explains the states and why they are shared.
|
|
8
|
+
*
|
|
9
|
+
* `assertCapabilities` is meant to run in tests, not at runtime: it checks that
|
|
10
|
+
* evidence paths exist in a source checkout, which a published package does not
|
|
11
|
+
* carry.
|
|
12
|
+
*/
|
|
13
|
+
import fs from "node:fs";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
16
|
+
export const CAPABILITY_ROWS = [
|
|
17
|
+
"transports.http",
|
|
18
|
+
"transports.websocket",
|
|
19
|
+
"transports.nonFetch",
|
|
20
|
+
"surfaces.toolArgs",
|
|
21
|
+
"surfaces.replyDisplay",
|
|
22
|
+
"surfaces.background",
|
|
23
|
+
];
|
|
24
|
+
export const CAPABILITY_ROW_TITLES = {
|
|
25
|
+
"transports.http": "HTTP",
|
|
26
|
+
"transports.websocket": "WebSocket",
|
|
27
|
+
"transports.nonFetch": "non-fetch",
|
|
28
|
+
"surfaces.toolArgs": "tool args",
|
|
29
|
+
"surfaces.replyDisplay": "reply",
|
|
30
|
+
"surfaces.background": "background",
|
|
31
|
+
};
|
|
32
|
+
export function capabilityAt(capabilities, row) {
|
|
33
|
+
const [section, field] = row.split(".");
|
|
34
|
+
return capabilities[section][field];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* `unknown` and `outside` rows cap the host at PARTIAL. A host can still be
|
|
38
|
+
* PARTIAL for install-level reasons (hook-first mode, load order); this only
|
|
39
|
+
* answers what the declaration itself allows.
|
|
40
|
+
*/
|
|
41
|
+
export function capabilityVerdict(capabilities) {
|
|
42
|
+
const unknown = CAPABILITY_ROWS.filter((row) => capabilityAt(capabilities, row).state === "unknown");
|
|
43
|
+
const outside = CAPABILITY_ROWS.filter((row) => capabilityAt(capabilities, row).state === "outside");
|
|
44
|
+
return {
|
|
45
|
+
verdict: unknown.length > 0 || outside.length > 0 ? "PARTIAL" : "PROTECTED",
|
|
46
|
+
unknown,
|
|
47
|
+
outside,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export class CapabilityInvariantError extends Error {
|
|
51
|
+
constructor(host, message) {
|
|
52
|
+
super(`${host}: ${message}`);
|
|
53
|
+
this.name = "CapabilityInvariantError";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Where `refused` evidence may point: a runtime test or an end-to-end record. */
|
|
57
|
+
const RUNTIME_EVIDENCE = /^(tests\/|scripts\/e2e\/|docs\/evidence\/)/;
|
|
58
|
+
export function assertCapabilities(capabilities, audit = {}) {
|
|
59
|
+
const host = capabilities.host;
|
|
60
|
+
const root = audit.root ?? fileURLToPath(new URL("../../", import.meta.url));
|
|
61
|
+
const fileExists = audit.fileExists ?? ((filePath) => fs.existsSync(path.resolve(root, filePath)));
|
|
62
|
+
const isFile = audit.isFile ?? ((filePath) => {
|
|
63
|
+
try {
|
|
64
|
+
return fs.statSync(path.resolve(root, filePath)).isFile();
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
const fail = (message) => {
|
|
71
|
+
throw new CapabilityInvariantError(host, message);
|
|
72
|
+
};
|
|
73
|
+
/** Evidence must be a normalized, repository-relative file, not a directory or a traversal. */
|
|
74
|
+
const requireEvidence = (row, evidence, label) => {
|
|
75
|
+
const evidencePath = evidence ?? fail(`${row} is ${label} without an evidence path`);
|
|
76
|
+
if (path.isAbsolute(evidencePath))
|
|
77
|
+
fail(`${row} evidence must be repository-relative: ${evidencePath}`);
|
|
78
|
+
if (path.posix.normalize(evidencePath) !== evidencePath || evidencePath.endsWith("/")) {
|
|
79
|
+
fail(`${row} evidence must be a normalized file path: ${evidencePath}`);
|
|
80
|
+
}
|
|
81
|
+
if (evidencePath.split("/").includes("..")) {
|
|
82
|
+
fail(`${row} evidence must stay inside the repository: ${evidencePath}`);
|
|
83
|
+
}
|
|
84
|
+
const resolved = path.resolve(root, evidencePath);
|
|
85
|
+
if (!resolved.startsWith(root.endsWith(path.sep) ? root : `${root}${path.sep}`)) {
|
|
86
|
+
fail(`${row} evidence must stay inside the repository: ${evidencePath}`);
|
|
87
|
+
}
|
|
88
|
+
if (!fileExists(evidencePath))
|
|
89
|
+
fail(`${row} evidence does not exist: ${evidencePath}`);
|
|
90
|
+
if (!isFile(evidencePath))
|
|
91
|
+
fail(`${row} evidence is not a file: ${evidencePath}`);
|
|
92
|
+
return evidencePath;
|
|
93
|
+
};
|
|
94
|
+
if (host.length === 0)
|
|
95
|
+
fail("host is empty");
|
|
96
|
+
if (capabilities.verifiedVersion.length === 0)
|
|
97
|
+
fail("verifiedVersion is empty");
|
|
98
|
+
if (capabilities.credentials !== "in-process" && capabilities.credentials !== "separated") {
|
|
99
|
+
fail(`credentials must be declared explicitly (got ${String(capabilities.credentials)})`);
|
|
100
|
+
}
|
|
101
|
+
if (capabilities.persistence !== "opt-in" && capabilities.persistence !== "none") {
|
|
102
|
+
fail(`persistence must be declared explicitly (got ${String(capabilities.persistence)})`);
|
|
103
|
+
}
|
|
104
|
+
for (const row of CAPABILITY_ROWS) {
|
|
105
|
+
const capability = capabilityAt(capabilities, row);
|
|
106
|
+
const state = capability.state;
|
|
107
|
+
if (!["protected", "refused", "not-present", "outside", "unknown"].includes(state)) {
|
|
108
|
+
fail(`${row} has an unknown state ${String(state)}`);
|
|
109
|
+
}
|
|
110
|
+
if (capability.mechanism.length === 0)
|
|
111
|
+
fail(`${row} has no mechanism`);
|
|
112
|
+
if (state === "protected" || state === "not-present") {
|
|
113
|
+
requireEvidence(row, capability.evidence, state);
|
|
114
|
+
}
|
|
115
|
+
if (state === "refused") {
|
|
116
|
+
const evidence = requireEvidence(row, capability.evidence, "refused");
|
|
117
|
+
if (!RUNTIME_EVIDENCE.test(evidence)) {
|
|
118
|
+
fail(`${row} is refused but ${evidence} is not a runtime test or an e2e record`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (state === "outside") {
|
|
122
|
+
if (capability.note === undefined || capability.note.length === 0) {
|
|
123
|
+
fail(`${row} is outside without a note explaining the residual`);
|
|
124
|
+
}
|
|
125
|
+
if (!capabilities.residuals.some((entry) => entry.startsWith(`${row}: `))) {
|
|
126
|
+
fail(`${row} is outside but has no matching entry in residuals`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (state === "unknown" && !/#\d+/.test(capability.note ?? "")) {
|
|
130
|
+
fail(`${row} is unknown without a tracking issue in its note`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { ExactValueDetector } from "./scanner/exact-values.js";
|
|
2
|
+
export interface CustomRuleConfig {
|
|
3
|
+
description: string;
|
|
4
|
+
pattern: string;
|
|
5
|
+
severity: "HIGH" | "MEDIUM" | "LOW";
|
|
6
|
+
/**
|
|
7
|
+
* Extra regex flags, a subset of `imsuy`; `g` is always added. Invalid flags
|
|
8
|
+
* fail config load rather than being ignored.
|
|
9
|
+
*/
|
|
10
|
+
flags?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Wrap the pattern edges in `\b` where that edge is an ASCII word character.
|
|
13
|
+
* CJK edges are left alone for the same reason as `keywordPattern`: `\b` never
|
|
14
|
+
* holds between two non-word characters.
|
|
15
|
+
*/
|
|
16
|
+
word_boundary?: boolean;
|
|
17
|
+
/** Exact strings this rule never reports. Not a regex; not a partial match. */
|
|
18
|
+
allow?: string[];
|
|
19
|
+
/**
|
|
20
|
+
* Reserved. Accepted and validated, but the scanner has no source path for
|
|
21
|
+
* chat/tool text, so it does not scope anything yet; `--doctor` warns when set.
|
|
22
|
+
*/
|
|
23
|
+
path?: string[];
|
|
24
|
+
}
|
|
25
|
+
export interface GuardConfig {
|
|
26
|
+
nda_keywords: string[];
|
|
27
|
+
private_domains: string[];
|
|
28
|
+
custom_rules: CustomRuleConfig[];
|
|
29
|
+
settings: {
|
|
30
|
+
max_chars: number;
|
|
31
|
+
show_line_numbers: boolean;
|
|
32
|
+
preview_length: number;
|
|
33
|
+
encoding_detection: boolean;
|
|
34
|
+
env_files?: string[];
|
|
35
|
+
/** Built-in rule id → enabled. Absent id = the rule's own default (opt-in rules stay off). */
|
|
36
|
+
rule_overrides?: Record<string, boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Networks the opt-in `private-ipv4` rule reports. Empty or absent uses
|
|
39
|
+
* RFC 1918, CGNAT and link-local. Entries are validated at config load.
|
|
40
|
+
*/
|
|
41
|
+
private_cidrs?: string[];
|
|
42
|
+
/**
|
|
43
|
+
* Exact strings that never produce a finding, for any rule. A bypass
|
|
44
|
+
* surface: every entry is surfaced by `--doctor`, and every suppression is
|
|
45
|
+
* counted. Not a regex, not a partial match.
|
|
46
|
+
*/
|
|
47
|
+
allowlist?: string[];
|
|
48
|
+
};
|
|
49
|
+
/** In-memory only; serializes to a fingerprint without retaining raw values. */
|
|
50
|
+
exact_value_detector?: ExactValueDetector;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Runtime-closed enumeration (R-round F1.2): the SGP2 category whitelist is
|
|
54
|
+
* enforced at persisted-seed intake, so the legal labels must exist as a
|
|
55
|
+
* value, not just a type. Keep list and type in one place.
|
|
56
|
+
*/
|
|
57
|
+
export declare const FINDING_TYPES: readonly ["API_KEY", "SECRET", "TOKEN", "PII_EMAIL", "PII_PHONE_TW", "PII_PHONE_INTL", "PII_ID_TW", "DB_CONNECTION", "PRIVATE_DOMAIN", "NDA_KEYWORD", "ENV_SECRET", "CUSTOM", "PII_CREDIT_CARD", "PII_IBAN", "PII_IP", "PII_URL", "ENCODED"];
|
|
58
|
+
export type FindingType = (typeof FINDING_TYPES)[number];
|
|
59
|
+
export interface Finding {
|
|
60
|
+
type: FindingType;
|
|
61
|
+
severity: "HIGH" | "MEDIUM" | "LOW";
|
|
62
|
+
line?: number;
|
|
63
|
+
column?: number;
|
|
64
|
+
preview: string;
|
|
65
|
+
description: string;
|
|
66
|
+
/** Internal-only: UTF-16 code-unit offset of the match start in the original content (regex `.index`; the scanner slices with String.slice). Not a byte offset. */
|
|
67
|
+
match_start?: number;
|
|
68
|
+
/** Internal-only: UTF-16 code-unit offset of the match end (match_start + match length). Not a byte offset. */
|
|
69
|
+
match_end?: number;
|
|
70
|
+
/** Internal-only: the raw matched text. Never expose to transport outputs. */
|
|
71
|
+
match_text?: string;
|
|
72
|
+
/** Metadata about encoding detection (if found via decoding) */
|
|
73
|
+
encoding_detected?: {
|
|
74
|
+
type: 'Base64' | 'URL' | 'Hex';
|
|
75
|
+
confidence: number;
|
|
76
|
+
encoded_length?: number;
|
|
77
|
+
decoded_length?: number;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export interface ScanResult {
|
|
81
|
+
safe: boolean;
|
|
82
|
+
total_findings: number;
|
|
83
|
+
findings: Finding[];
|
|
84
|
+
summary: string;
|
|
85
|
+
recommendation: string;
|
|
86
|
+
/** Indica se o conteúdo foi truncado durante a verificação */
|
|
87
|
+
was_truncated?: boolean;
|
|
88
|
+
/** Warnings appended to `summary` as ` [WARNING: a, b]`; kept so a rebuilt summary can restore them */
|
|
89
|
+
warnings?: string[];
|
|
90
|
+
/** Metadados sobre sanitização Unicode */
|
|
91
|
+
unicode_sanitized?: {
|
|
92
|
+
hadZeroWidth: boolean;
|
|
93
|
+
hadVariants: boolean;
|
|
94
|
+
removedChars: number;
|
|
95
|
+
homographSuspected: boolean;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export interface RedactResult {
|
|
99
|
+
redacted: string;
|
|
100
|
+
findings: Finding[];
|
|
101
|
+
total_findings: number;
|
|
102
|
+
summary: string;
|
|
103
|
+
}
|
|
104
|
+
export interface Rule {
|
|
105
|
+
type: FindingType;
|
|
106
|
+
severity: Finding["severity"];
|
|
107
|
+
description: string;
|
|
108
|
+
pattern: RegExp;
|
|
109
|
+
/**
|
|
110
|
+
* Exact strings this rule never reports. Compared against the matched text,
|
|
111
|
+
* never partially. A suppression is counted and surfaced by `--doctor`.
|
|
112
|
+
*/
|
|
113
|
+
allow?: ReadonlySet<string>;
|
|
114
|
+
/**
|
|
115
|
+
* Stable identifier for built-in rules, the key used by
|
|
116
|
+
* `settings.rule_overrides` in the guard config. Every BUILTIN_RULES entry
|
|
117
|
+
* must set one (tests enforce this) so any built-in can be toggled.
|
|
118
|
+
*/
|
|
119
|
+
id?: string;
|
|
120
|
+
/**
|
|
121
|
+
* Opt-in rules are disabled unless explicitly enabled via
|
|
122
|
+
* `settings.rule_overrides`. Used for high-noise rules (e.g. URL) that
|
|
123
|
+
* must not run always-on.
|
|
124
|
+
*/
|
|
125
|
+
optIn?: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Optional semantic validation for a regex match (Luhn for credit cards,
|
|
128
|
+
* mod-97 for IBAN, routability for IPv4). Returning false skips the match
|
|
129
|
+
* entirely — used to keep checksum-capable formats at near-zero false
|
|
130
|
+
* positives without weakening the pattern shape.
|
|
131
|
+
*
|
|
132
|
+
* `context` carries the scanned text and the match offset for rules whose
|
|
133
|
+
* meaning depends on surrounding syntax (an email-shaped span that is really
|
|
134
|
+
* an SSH remote authority). It is supplied by the engine, never by callers
|
|
135
|
+
* that only know the matched string.
|
|
136
|
+
*/
|
|
137
|
+
validate?: (match: string, context: {
|
|
138
|
+
text: string;
|
|
139
|
+
index: number;
|
|
140
|
+
}) => boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Characters at the start of `pattern`'s match that are syntax, not the
|
|
143
|
+
* finding. The engine reports and redacts from `match.index + skipPrefix`.
|
|
144
|
+
* Used by url-userinfo, which must anchor on `://` without a variable-length
|
|
145
|
+
* lookbehind (V8 retries that lookbehind at every position, which is
|
|
146
|
+
* quadratic on a long token).
|
|
147
|
+
*/
|
|
148
|
+
skipPrefix?: number;
|
|
149
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve an inputPath relative to baseDir (does NOT call realpathSync —
|
|
3
|
+
* safe to call for paths that may not exist yet).
|
|
4
|
+
*/
|
|
5
|
+
export declare function resolveWorkspacePath(baseDir: string, inputPath: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Returns true when candidatePath is inside (or equal to) baseDir.
|
|
8
|
+
* Both paths must already be absolute; call resolveWorkspacePath / realpathSync
|
|
9
|
+
* before passing them here.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isPathInsideBase(baseDir: string, candidatePath: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Validate a CLI scan path against the workspace root.
|
|
14
|
+
* Throws a user-facing Error when the path would escape the workspace and
|
|
15
|
+
* allowOutside is false.
|
|
16
|
+
* Returns the resolved absolute path on success.
|
|
17
|
+
*/
|
|
18
|
+
export declare function validateCliScanPath(baseDir: string, inputPath: string, allowOutside: boolean): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows terminal encoding initialisation.
|
|
3
|
+
*
|
|
4
|
+
* Windows cmd/PowerShell defaults to legacy code pages (437, 936, 950)
|
|
5
|
+
* instead of UTF-8 (65001). This module sets UTF-8 so Chinese / emoji
|
|
6
|
+
* output is not garbled.
|
|
7
|
+
*/
|
|
8
|
+
/** Try to switch Windows console to UTF-8 code page (65001). */
|
|
9
|
+
export declare function initWindowsEncoding(): void;
|
|
10
|
+
/**
|
|
11
|
+
* Read a file with BOM-aware encoding detection.
|
|
12
|
+
*
|
|
13
|
+
* Windows editors sometimes save files as UTF-16LE or UTF-8 with BOM.
|
|
14
|
+
* Plain `readFileSync(p, "utf-8")` mangles those.
|
|
15
|
+
*/
|
|
16
|
+
export declare function readFileWithEncoding(path: string): string;
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "leakshield",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "OpenCode plugin, CLI, and web scanner for sensitive content before sending it to AI",
|
|
5
|
-
"license": "
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "OpenCode plugin, pi adapter, CLI, and web scanner for sensitive content before sending it to AI",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "Jared Wang",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
8
9
|
"url": "git+https://github.com/jwcrystal/leakshield.git"
|
|
@@ -14,6 +15,7 @@
|
|
|
14
15
|
"keywords": [
|
|
15
16
|
"opencode",
|
|
16
17
|
"opencode-plugin",
|
|
18
|
+
"pi-package",
|
|
17
19
|
"secrets",
|
|
18
20
|
"pii",
|
|
19
21
|
"redaction",
|
|
@@ -25,11 +27,19 @@
|
|
|
25
27
|
"main": "./dist/index.js",
|
|
26
28
|
"exports": {
|
|
27
29
|
".": "./dist/index.js",
|
|
28
|
-
"./package.json": "./package.json"
|
|
30
|
+
"./package.json": "./package.json",
|
|
31
|
+
"./core": {
|
|
32
|
+
"types": "./dist/core/index.d.ts",
|
|
33
|
+
"default": "./dist/core/index.js"
|
|
34
|
+
}
|
|
29
35
|
},
|
|
30
36
|
"files": [
|
|
31
|
-
"dist"
|
|
37
|
+
"dist",
|
|
38
|
+
"NOTICE"
|
|
32
39
|
],
|
|
40
|
+
"pi": {
|
|
41
|
+
"extensions": ["./dist/adapters/pi/extension.js"]
|
|
42
|
+
},
|
|
33
43
|
"engines": {
|
|
34
44
|
"node": ">=20"
|
|
35
45
|
},
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|