leakshield 0.1.3 โ 0.3.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/README.md +294 -173
- package/README.zh-TW.md +290 -164
- package/dist/config/loader.js +14 -10
- package/dist/config/plain-object.js +14 -0
- package/dist/decision/pseudonymization.js +133 -82
- package/dist/decision/redaction.js +2 -0
- package/dist/decision/value-search.js +250 -0
- package/dist/doctor.js +429 -138
- package/dist/i18n/en.js +4 -0
- package/dist/i18n/zh-TW.js +4 -0
- package/dist/index.js +3 -2
- package/dist/opencode-env-tools.js +0 -75
- package/dist/opencode-hooks.js +4 -73
- package/dist/opencode-transparent.js +582 -89
- package/dist/opencode.js +12 -54
- package/dist/plugin-options.js +15 -21
- package/dist/scanner/encoding.js +291 -7
- package/dist/scanner/engine.js +68 -40
- package/dist/scanner/utils.js +26 -2
- package/dist/transports/cli.js +2 -2
- package/dist/transports/web.js +3 -3
- package/dist/types.js +1 -0
- package/package.json +3 -3
package/dist/i18n/en.js
CHANGED
|
@@ -4,6 +4,10 @@ export const en = {
|
|
|
4
4
|
"scan.unsafe_summary": "๐จ Found {count} potential sensitive item(s) (HIGH: {high}, MEDIUM: {med}, LOW: {low})",
|
|
5
5
|
"scan.safe_recommendation": "Content looks safe, but please verify there are no business-logic secrets.",
|
|
6
6
|
"scan.unsafe_recommendation": "โ Please address the above sensitive items before sending to AI services. Use placeholder data or remove sensitive fields, then retry.",
|
|
7
|
+
"scan.warning_encoded": "Encoded content: {types}",
|
|
8
|
+
"scan.warning_truncated": "Content truncated",
|
|
9
|
+
"scan.warning_zero_width": "Zero-width characters",
|
|
10
|
+
"scan.warning_suspicious_unicode": "Suspicious Unicode",
|
|
7
11
|
// engine โ redact
|
|
8
12
|
"redact.safe_summary": "โ
No sensitive content detected, nothing to redact.",
|
|
9
13
|
"redact.unsafe_summary": "๐ Redacted {count} sensitive item(s).",
|
package/dist/i18n/zh-TW.js
CHANGED
|
@@ -4,6 +4,10 @@ export const zhTW = {
|
|
|
4
4
|
"scan.unsafe_summary": "๐จ ็ผ็พ {count} ๅๆฝๅจๆๆ้
็ฎ๏ผHIGH: {high}, MEDIUM: {med}, LOW: {low}๏ผ",
|
|
5
5
|
"scan.safe_recommendation": "ๅ
งๅฎน็่ตทไพๅฎๅ
จ๏ผไฝไป่ซ็ขบ่ชๆฒๆๆฅญๅ้่ผฏไธ็ๆฉๅฏ่ณ่จใ",
|
|
6
6
|
"scan.unsafe_recommendation": "โ ๅปบ่ญฐๅ
่็ไธ่ฟฐๆๆ้
็ฎๅพๅๅณ้็ตฆ AI ๆๅใ่ซ็จๅ่ณๆใไฝไฝ็ฌฆๆ็งป้คๆๆๆฌไฝๅพๅ้่ฉฆใ",
|
|
7
|
+
"scan.warning_encoded": "็ทจ็ขผๆชขๆธฌ: {types}",
|
|
8
|
+
"scan.warning_truncated": "ๅ
งๅฎนๆชๆท",
|
|
9
|
+
"scan.warning_zero_width": "้ถๅฏฌๅญ็ฌฆ",
|
|
10
|
+
"scan.warning_suspicious_unicode": "ๅฏ็ Unicode",
|
|
7
11
|
// engine โ redact
|
|
8
12
|
"redact.safe_summary": "โ
ๆชๅตๆธฌๅฐๆๆๅ
งๅฎน๏ผ็ก้่ซๆใ",
|
|
9
13
|
"redact.unsafe_summary": "๐ ๅทฒ่ซๆ {count} ๅๆๆ้
็ฎใ",
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* - OpenCode v2 resolves the package `main` (or `<dir>/index.js` when the dist
|
|
5
5
|
* directory is configured directly) to this file.
|
|
6
|
-
* - The default export is the
|
|
7
|
-
* `
|
|
6
|
+
* - The default export is the OpenCode v2 plugin definition (`id` +
|
|
7
|
+
* `setup(ctx)`). Its `server` export is a fail-closed stub for v1 hosts,
|
|
8
|
+
* which are no longer supported.
|
|
8
9
|
*
|
|
9
10
|
* The CLI/web entrypoint lives in `./cli.js` (published as the `leakshield`
|
|
10
11
|
* bin) so importing this module never starts an interactive process.
|
|
@@ -78,81 +78,6 @@ function readCompareArgs(input) {
|
|
|
78
78
|
? { left_file_id, left_key, right_file_id, right_key }
|
|
79
79
|
: undefined;
|
|
80
80
|
}
|
|
81
|
-
// โโโ OpenCode v1 โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
82
|
-
/** Builds the v1 tool map for `Hooks["tool"]` when `envQueries` is enabled. */
|
|
83
|
-
export async function createV1EnvTools(service) {
|
|
84
|
-
// Runtime dependency on the v1 SDK's tool helper; loaded dynamically so a
|
|
85
|
-
// v2 host never needs the v1 SDK package. A v1 host always provides it.
|
|
86
|
-
const { tool } = await import("@opencode-ai/plugin/tool");
|
|
87
|
-
const z = tool.schema;
|
|
88
|
-
const guardEnvList = tool({
|
|
89
|
-
description: LIST_DESCRIPTION,
|
|
90
|
-
args: {},
|
|
91
|
-
async execute(_args, context) {
|
|
92
|
-
return {
|
|
93
|
-
title: "guard_env_list",
|
|
94
|
-
output: JSON.stringify(safePayload(() => listPayload(service, context.sessionID))),
|
|
95
|
-
};
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
const guardEnvInspect = tool({
|
|
99
|
-
description: INSPECT_DESCRIPTION,
|
|
100
|
-
args: {
|
|
101
|
-
file_id: z
|
|
102
|
-
.string()
|
|
103
|
-
.min(1)
|
|
104
|
-
.max(MAX_FILE_ID_LENGTH)
|
|
105
|
-
.describe("Session-local file id issued by guard_env_list."),
|
|
106
|
-
key: z
|
|
107
|
-
.string()
|
|
108
|
-
.min(1)
|
|
109
|
-
.max(MAX_KEY_NAME_LENGTH)
|
|
110
|
-
.describe("Key name as listed by guard_env_list."),
|
|
111
|
-
},
|
|
112
|
-
async execute(args, context) {
|
|
113
|
-
return {
|
|
114
|
-
title: "guard_env_inspect",
|
|
115
|
-
output: JSON.stringify(safePayload(() => inspectPayload(service, context.sessionID, args.file_id, args.key))),
|
|
116
|
-
};
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
const guardEnvCompare = tool({
|
|
120
|
-
description: COMPARE_DESCRIPTION,
|
|
121
|
-
args: {
|
|
122
|
-
left_file_id: z
|
|
123
|
-
.string()
|
|
124
|
-
.min(1)
|
|
125
|
-
.max(MAX_FILE_ID_LENGTH)
|
|
126
|
-
.describe("Session-local file id of the left operand."),
|
|
127
|
-
left_key: z
|
|
128
|
-
.string()
|
|
129
|
-
.min(1)
|
|
130
|
-
.max(MAX_KEY_NAME_LENGTH)
|
|
131
|
-
.describe("Key name of the left operand."),
|
|
132
|
-
right_file_id: z
|
|
133
|
-
.string()
|
|
134
|
-
.min(1)
|
|
135
|
-
.max(MAX_FILE_ID_LENGTH)
|
|
136
|
-
.describe("Session-local file id of the right operand."),
|
|
137
|
-
right_key: z
|
|
138
|
-
.string()
|
|
139
|
-
.min(1)
|
|
140
|
-
.max(MAX_KEY_NAME_LENGTH)
|
|
141
|
-
.describe("Key name of the right operand."),
|
|
142
|
-
},
|
|
143
|
-
async execute(args, context) {
|
|
144
|
-
return {
|
|
145
|
-
title: "guard_env_compare",
|
|
146
|
-
output: JSON.stringify(safePayload(() => comparePayload(service, context.sessionID, { fileId: args.left_file_id, key: args.left_key }, { fileId: args.right_file_id, key: args.right_key }))),
|
|
147
|
-
};
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
return {
|
|
151
|
-
guard_env_list: guardEnvList,
|
|
152
|
-
guard_env_inspect: guardEnvInspect,
|
|
153
|
-
guard_env_compare: guardEnvCompare,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
81
|
// โโโ OpenCode v2 โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
157
82
|
/**
|
|
158
83
|
* Registers the env query tools on an OpenCode v2 plugin context via
|
package/dist/opencode-hooks.js
CHANGED
|
@@ -1,78 +1,9 @@
|
|
|
1
|
-
import { ContentHashCache, protectUnknownStrings, } from "./decision/ingress.js";
|
|
2
1
|
const INITIALIZATION_ERROR = "LeakShield initialization failed, so the request was blocked before anything was sent.";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
sessionID: part.sessionID,
|
|
7
|
-
messageID: part.messageID,
|
|
8
|
-
type: "text",
|
|
9
|
-
text: "[LeakShield blocked an attachment: its content cannot be scanned, so it was not sent.]",
|
|
10
|
-
synthetic: true,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function protectParts(parts, config, mode, protector) {
|
|
14
|
-
return parts.map((part) => {
|
|
15
|
-
if (part.type === "file")
|
|
16
|
-
return blockedAttachment(part);
|
|
17
|
-
if (part.type === "text") {
|
|
18
|
-
const protectedText = protector(part.text, config, { mode, context: "message text" });
|
|
19
|
-
return { ...part, text: protectedText.text };
|
|
20
|
-
}
|
|
21
|
-
if (part.type === "reasoning") {
|
|
22
|
-
const protectedText = protector(part.text, config, { mode, context: "reasoning text" });
|
|
23
|
-
return { ...part, text: protectedText.text };
|
|
24
|
-
}
|
|
25
|
-
if (part.type === "tool") {
|
|
26
|
-
return {
|
|
27
|
-
...part,
|
|
28
|
-
state: protectUnknownStrings(part.state, config, { mode, context: "tool history" }, protector),
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
if (part.type === "subtask") {
|
|
32
|
-
const protectedPrompt = protector(part.prompt, config, { mode, context: "subtask prompt" });
|
|
33
|
-
const protectedDescription = protector(part.description, config, { mode, context: "subtask description" });
|
|
34
|
-
return { ...part, prompt: protectedPrompt.text, description: protectedDescription.text };
|
|
35
|
-
}
|
|
36
|
-
if (part.type === "retry") {
|
|
37
|
-
return {
|
|
38
|
-
...part,
|
|
39
|
-
error: protectUnknownStrings(part.error, config, { mode, context: "retry error" }, protector),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
return part;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
export function createHooks(config, mode) {
|
|
46
|
-
const cache = new ContentHashCache();
|
|
47
|
-
const protectWithCache = (text, currentConfig, options) => cache.protect(text, currentConfig, options);
|
|
48
|
-
return {
|
|
49
|
-
"chat.message": async (_input, output) => {
|
|
50
|
-
output.parts.splice(0, output.parts.length, ...protectParts(output.parts, config, mode, protectWithCache));
|
|
51
|
-
},
|
|
52
|
-
"tool.execute.after": async (_input, output) => {
|
|
53
|
-
const protectedTitle = protectWithCache(output.title, config, { mode, context: "tool title" });
|
|
54
|
-
const protectedOutput = protectWithCache(output.output, config, { mode, context: "tool output" });
|
|
55
|
-
output.title = protectedTitle.text;
|
|
56
|
-
output.output = protectedOutput.text;
|
|
57
|
-
output.metadata = protectUnknownStrings(output.metadata, config, { mode, context: "tool metadata" }, protectWithCache);
|
|
58
|
-
},
|
|
59
|
-
"experimental.chat.messages.transform": async (_input, output) => {
|
|
60
|
-
for (const message of output.messages) {
|
|
61
|
-
message.parts.splice(0, message.parts.length, ...protectParts(message.parts, config, mode, protectWithCache));
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
"experimental.chat.system.transform": async (_input, output) => {
|
|
65
|
-
output.system.splice(0, output.system.length, ...output.system.map((text) => protectWithCache(text, config, { mode, context: "system prompt" }).text));
|
|
66
|
-
},
|
|
67
|
-
"tool.definition": async (_input, output) => {
|
|
68
|
-
output.description = protectWithCache(output.description, config, { mode, context: "tool description" }).text;
|
|
69
|
-
output.parameters = protectUnknownStrings(output.parameters, config, { mode, context: "tool parameters" }, protectWithCache);
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
export function createFailClosedHooks() {
|
|
2
|
+
/** Hooks that reject every model request. `message` names the reason shown to
|
|
3
|
+
* the user; the default is the generic initialization failure. */
|
|
4
|
+
export function createFailClosedHooks(message = INITIALIZATION_ERROR) {
|
|
74
5
|
const blockRequest = async () => {
|
|
75
|
-
throw new Error(
|
|
6
|
+
throw new Error(message);
|
|
76
7
|
};
|
|
77
8
|
return {
|
|
78
9
|
"chat.message": blockRequest,
|