sdtk-code-kit 0.3.0 → 0.3.1
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 +204 -204
- package/assets/manifest/toolkit-bundle.manifest.json +147 -147
- package/assets/manifest/toolkit-bundle.sha256.txt +5 -5
- package/bin/sdtk-code.js +14 -14
- package/package.json +44 -44
- package/src/commands/agent-team.js +425 -174
- package/src/commands/build.js +53 -53
- package/src/commands/doctor.js +51 -51
- package/src/commands/generate.js +11 -11
- package/src/commands/guardrails.js +215 -215
- package/src/commands/help.js +264 -257
- package/src/commands/init.js +98 -98
- package/src/commands/plan.js +53 -53
- package/src/commands/readiness.js +77 -77
- package/src/commands/resume.js +61 -61
- package/src/commands/runtime.js +224 -224
- package/src/commands/ship.js +59 -59
- package/src/commands/sleep.js +132 -132
- package/src/commands/start.js +89 -89
- package/src/commands/status.js +77 -77
- package/src/commands/update.js +11 -11
- package/src/commands/verify.js +71 -71
- package/src/index.js +112 -112
- package/src/lib/agent-team-author.js +521 -0
- package/src/lib/agent-team-evidence.js +302 -0
- package/src/lib/agent-team-execute.js +892 -0
- package/src/lib/agent-team-export.js +411 -409
- package/src/lib/agent-team-plan.js +514 -514
- package/src/lib/agent-team-readiness.js +161 -0
- package/src/lib/agent-team-report.js +165 -0
- package/src/lib/args.js +107 -107
- package/src/lib/errors.js +41 -41
- package/src/lib/model-provider.js +219 -0
- package/src/lib/powershell.js +65 -65
- package/src/lib/project-target-guard.js +53 -53
- package/src/lib/scope.js +72 -72
- package/src/lib/ship-readiness.js +281 -281
- package/src/lib/sleep-plan.js +175 -175
- package/src/lib/sleep-report.js +229 -229
- package/src/lib/toolkit-payload.js +72 -72
- package/src/lib/trust-events.js +252 -185
- package/src/lib/trust-file-scope.js +154 -154
- package/src/lib/trust-policy.js +212 -212
- package/src/lib/trust-redact.js +58 -35
- package/src/lib/trust-trace.js +179 -179
- package/src/lib/update.js +344 -344
- package/src/lib/workflow-artifact.js +503 -503
- package/src/lib/workflow-build.js +127 -127
- package/src/lib/workflow-doctor.js +83 -83
- package/src/lib/workflow-handoff.js +1029 -1029
- package/src/lib/workflow-intake.js +101 -101
- package/src/lib/workflow-plan.js +193 -193
- package/src/lib/workflow-review-packet.js +650 -650
- package/src/lib/workflow-ship.js +213 -213
- package/src/lib/workflow-state.js +438 -438
- package/src/lib/workflow-verify.js +393 -393
package/src/lib/trust-policy.js
CHANGED
|
@@ -1,212 +1,212 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const { ValidationError } = require("./errors");
|
|
6
|
-
|
|
7
|
-
// Default allow/ask/deny pack (BK-240 §5), derived from the reference harness
|
|
8
|
-
// settings.json command classes. Patterns starting with "^" are treated as
|
|
9
|
-
// anchored regular expressions; all other patterns are case-sensitive
|
|
10
|
-
// substring matches against the command string. NO shell execution: this is
|
|
11
|
-
// advisory classification only.
|
|
12
|
-
const DEFAULT_POLICY = {
|
|
13
|
-
deny: [
|
|
14
|
-
"^rm -rf",
|
|
15
|
-
"^rm -fr",
|
|
16
|
-
"^sudo ",
|
|
17
|
-
"git reset --hard",
|
|
18
|
-
"git push --force",
|
|
19
|
-
"git push -f",
|
|
20
|
-
"mkfs",
|
|
21
|
-
"^dd ",
|
|
22
|
-
".env",
|
|
23
|
-
".pem",
|
|
24
|
-
"secrets/",
|
|
25
|
-
"^psql",
|
|
26
|
-
"^mysql",
|
|
27
|
-
"^mongod",
|
|
28
|
-
],
|
|
29
|
-
ask: [
|
|
30
|
-
"npm install",
|
|
31
|
-
"npm publish",
|
|
32
|
-
"npm exec",
|
|
33
|
-
"npx",
|
|
34
|
-
"git merge",
|
|
35
|
-
"git rebase",
|
|
36
|
-
"git clean -fd",
|
|
37
|
-
"git clean -fx",
|
|
38
|
-
"git clean -fdx",
|
|
39
|
-
],
|
|
40
|
-
allow: [
|
|
41
|
-
"git status",
|
|
42
|
-
"git diff",
|
|
43
|
-
"git log",
|
|
44
|
-
"git branch",
|
|
45
|
-
"git show",
|
|
46
|
-
"npm test",
|
|
47
|
-
"npm run test",
|
|
48
|
-
"npm run lint",
|
|
49
|
-
"npm run build",
|
|
50
|
-
"pytest",
|
|
51
|
-
"python -m unittest",
|
|
52
|
-
"rg ",
|
|
53
|
-
"ls ",
|
|
54
|
-
"node --check",
|
|
55
|
-
],
|
|
56
|
-
// limits.max_actions is omitted by default; callers may add it (and supply
|
|
57
|
-
// --action-count) to enable the action-count cap.
|
|
58
|
-
limits: {},
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
function assertPatternArray(value, label) {
|
|
62
|
-
if (!Array.isArray(value)) {
|
|
63
|
-
throw new ValidationError(
|
|
64
|
-
`Invalid trust policy: "${label}" must be an array of string patterns.`
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
value.forEach((entry, index) => {
|
|
68
|
-
if (typeof entry !== "string") {
|
|
69
|
-
throw new ValidationError(
|
|
70
|
-
`Invalid trust policy: "${label}[${index}]" must be a string pattern.`
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function validatePolicy(obj) {
|
|
77
|
-
if (!obj || typeof obj !== "object" || Array.isArray(obj)) {
|
|
78
|
-
throw new ValidationError("Invalid trust policy: expected a JSON object.");
|
|
79
|
-
}
|
|
80
|
-
assertPatternArray(obj.deny, "deny");
|
|
81
|
-
assertPatternArray(obj.ask, "ask");
|
|
82
|
-
assertPatternArray(obj.allow, "allow");
|
|
83
|
-
|
|
84
|
-
if (obj.limits !== undefined && obj.limits !== null) {
|
|
85
|
-
if (typeof obj.limits !== "object" || Array.isArray(obj.limits)) {
|
|
86
|
-
throw new ValidationError('Invalid trust policy: "limits" must be an object.');
|
|
87
|
-
}
|
|
88
|
-
if (
|
|
89
|
-
obj.limits.max_actions !== undefined &&
|
|
90
|
-
typeof obj.limits.max_actions !== "number"
|
|
91
|
-
) {
|
|
92
|
-
throw new ValidationError(
|
|
93
|
-
'Invalid trust policy: "limits.max_actions" must be a number.'
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return obj;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function policyFile(projectPath) {
|
|
101
|
-
return path.join(path.resolve(projectPath || "."), ".sdtk", "trust", "policy.json");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function loadPolicy(projectPath) {
|
|
105
|
-
const file = policyFile(projectPath);
|
|
106
|
-
if (!fs.existsSync(file)) {
|
|
107
|
-
return DEFAULT_POLICY;
|
|
108
|
-
}
|
|
109
|
-
let parsed;
|
|
110
|
-
try {
|
|
111
|
-
parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
112
|
-
} catch (error) {
|
|
113
|
-
throw new ValidationError(
|
|
114
|
-
`Invalid trust policy: ${file} is not valid JSON (${error.message}).`
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
return validatePolicy(parsed);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Match a single pattern against the command string. "^"-prefixed patterns are
|
|
121
|
-
// anchored regexes; everything else is a case-sensitive substring match. A
|
|
122
|
-
// malformed regex pattern is treated as a non-match so classify never crashes.
|
|
123
|
-
function matchesPattern(pattern, command) {
|
|
124
|
-
if (typeof pattern !== "string" || pattern.length === 0) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
if (pattern.startsWith("^")) {
|
|
128
|
-
try {
|
|
129
|
-
return new RegExp(pattern).test(command);
|
|
130
|
-
} catch (_error) {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return command.includes(pattern);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function firstMatch(patterns, command) {
|
|
138
|
-
if (!Array.isArray(patterns)) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
for (const pattern of patterns) {
|
|
142
|
-
if (matchesPattern(pattern, command)) {
|
|
143
|
-
return pattern;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Classify a command as allow/ask/deny against a policy. Most-restrictive-wins,
|
|
150
|
-
// deterministic. Stateless: the caller supplies opts.actionCount; trust-policy
|
|
151
|
-
// performs no session counting. Never executes the command.
|
|
152
|
-
function classifyCommand(policy, command, opts) {
|
|
153
|
-
const cmd = typeof command === "string" ? command : "";
|
|
154
|
-
const options = opts && typeof opts === "object" ? opts : {};
|
|
155
|
-
const limits = policy && policy.limits && typeof policy.limits === "object" ? policy.limits : {};
|
|
156
|
-
|
|
157
|
-
// 1. action-count cap.
|
|
158
|
-
if (
|
|
159
|
-
typeof options.actionCount === "number" &&
|
|
160
|
-
typeof limits.max_actions === "number" &&
|
|
161
|
-
options.actionCount >= limits.max_actions
|
|
162
|
-
) {
|
|
163
|
-
return {
|
|
164
|
-
verdict: "deny",
|
|
165
|
-
reason: `action-count cap reached (${options.actionCount}/${limits.max_actions})`,
|
|
166
|
-
matchedRule: { bucket: "limit", pattern: "limits.max_actions" },
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// 2. deny → 3. ask → 4. allow (first match wins per bucket).
|
|
171
|
-
const denyHit = firstMatch(policy && policy.deny, cmd);
|
|
172
|
-
if (denyHit) {
|
|
173
|
-
return {
|
|
174
|
-
verdict: "deny",
|
|
175
|
-
reason: `denied by policy rule: ${denyHit}`,
|
|
176
|
-
matchedRule: { bucket: "deny", pattern: denyHit },
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const askHit = firstMatch(policy && policy.ask, cmd);
|
|
181
|
-
if (askHit) {
|
|
182
|
-
return {
|
|
183
|
-
verdict: "ask",
|
|
184
|
-
reason: `requires confirmation by policy rule: ${askHit}`,
|
|
185
|
-
matchedRule: { bucket: "ask", pattern: askHit },
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const allowHit = firstMatch(policy && policy.allow, cmd);
|
|
190
|
-
if (allowHit) {
|
|
191
|
-
return {
|
|
192
|
-
verdict: "allow",
|
|
193
|
-
reason: `allowed by policy rule: ${allowHit}`,
|
|
194
|
-
matchedRule: { bucket: "allow", pattern: allowHit },
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// 5. no match → conservative ask.
|
|
199
|
-
return {
|
|
200
|
-
verdict: "ask",
|
|
201
|
-
reason: "no matching allow rule; defaulting to ask (conservative)",
|
|
202
|
-
matchedRule: null,
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
module.exports = {
|
|
207
|
-
DEFAULT_POLICY,
|
|
208
|
-
loadPolicy,
|
|
209
|
-
classifyCommand,
|
|
210
|
-
validatePolicy,
|
|
211
|
-
policyFile,
|
|
212
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { ValidationError } = require("./errors");
|
|
6
|
+
|
|
7
|
+
// Default allow/ask/deny pack (BK-240 §5), derived from the reference harness
|
|
8
|
+
// settings.json command classes. Patterns starting with "^" are treated as
|
|
9
|
+
// anchored regular expressions; all other patterns are case-sensitive
|
|
10
|
+
// substring matches against the command string. NO shell execution: this is
|
|
11
|
+
// advisory classification only.
|
|
12
|
+
const DEFAULT_POLICY = {
|
|
13
|
+
deny: [
|
|
14
|
+
"^rm -rf",
|
|
15
|
+
"^rm -fr",
|
|
16
|
+
"^sudo ",
|
|
17
|
+
"git reset --hard",
|
|
18
|
+
"git push --force",
|
|
19
|
+
"git push -f",
|
|
20
|
+
"mkfs",
|
|
21
|
+
"^dd ",
|
|
22
|
+
".env",
|
|
23
|
+
".pem",
|
|
24
|
+
"secrets/",
|
|
25
|
+
"^psql",
|
|
26
|
+
"^mysql",
|
|
27
|
+
"^mongod",
|
|
28
|
+
],
|
|
29
|
+
ask: [
|
|
30
|
+
"npm install",
|
|
31
|
+
"npm publish",
|
|
32
|
+
"npm exec",
|
|
33
|
+
"npx",
|
|
34
|
+
"git merge",
|
|
35
|
+
"git rebase",
|
|
36
|
+
"git clean -fd",
|
|
37
|
+
"git clean -fx",
|
|
38
|
+
"git clean -fdx",
|
|
39
|
+
],
|
|
40
|
+
allow: [
|
|
41
|
+
"git status",
|
|
42
|
+
"git diff",
|
|
43
|
+
"git log",
|
|
44
|
+
"git branch",
|
|
45
|
+
"git show",
|
|
46
|
+
"npm test",
|
|
47
|
+
"npm run test",
|
|
48
|
+
"npm run lint",
|
|
49
|
+
"npm run build",
|
|
50
|
+
"pytest",
|
|
51
|
+
"python -m unittest",
|
|
52
|
+
"rg ",
|
|
53
|
+
"ls ",
|
|
54
|
+
"node --check",
|
|
55
|
+
],
|
|
56
|
+
// limits.max_actions is omitted by default; callers may add it (and supply
|
|
57
|
+
// --action-count) to enable the action-count cap.
|
|
58
|
+
limits: {},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
function assertPatternArray(value, label) {
|
|
62
|
+
if (!Array.isArray(value)) {
|
|
63
|
+
throw new ValidationError(
|
|
64
|
+
`Invalid trust policy: "${label}" must be an array of string patterns.`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
value.forEach((entry, index) => {
|
|
68
|
+
if (typeof entry !== "string") {
|
|
69
|
+
throw new ValidationError(
|
|
70
|
+
`Invalid trust policy: "${label}[${index}]" must be a string pattern.`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function validatePolicy(obj) {
|
|
77
|
+
if (!obj || typeof obj !== "object" || Array.isArray(obj)) {
|
|
78
|
+
throw new ValidationError("Invalid trust policy: expected a JSON object.");
|
|
79
|
+
}
|
|
80
|
+
assertPatternArray(obj.deny, "deny");
|
|
81
|
+
assertPatternArray(obj.ask, "ask");
|
|
82
|
+
assertPatternArray(obj.allow, "allow");
|
|
83
|
+
|
|
84
|
+
if (obj.limits !== undefined && obj.limits !== null) {
|
|
85
|
+
if (typeof obj.limits !== "object" || Array.isArray(obj.limits)) {
|
|
86
|
+
throw new ValidationError('Invalid trust policy: "limits" must be an object.');
|
|
87
|
+
}
|
|
88
|
+
if (
|
|
89
|
+
obj.limits.max_actions !== undefined &&
|
|
90
|
+
typeof obj.limits.max_actions !== "number"
|
|
91
|
+
) {
|
|
92
|
+
throw new ValidationError(
|
|
93
|
+
'Invalid trust policy: "limits.max_actions" must be a number.'
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return obj;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function policyFile(projectPath) {
|
|
101
|
+
return path.join(path.resolve(projectPath || "."), ".sdtk", "trust", "policy.json");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function loadPolicy(projectPath) {
|
|
105
|
+
const file = policyFile(projectPath);
|
|
106
|
+
if (!fs.existsSync(file)) {
|
|
107
|
+
return DEFAULT_POLICY;
|
|
108
|
+
}
|
|
109
|
+
let parsed;
|
|
110
|
+
try {
|
|
111
|
+
parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
112
|
+
} catch (error) {
|
|
113
|
+
throw new ValidationError(
|
|
114
|
+
`Invalid trust policy: ${file} is not valid JSON (${error.message}).`
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return validatePolicy(parsed);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Match a single pattern against the command string. "^"-prefixed patterns are
|
|
121
|
+
// anchored regexes; everything else is a case-sensitive substring match. A
|
|
122
|
+
// malformed regex pattern is treated as a non-match so classify never crashes.
|
|
123
|
+
function matchesPattern(pattern, command) {
|
|
124
|
+
if (typeof pattern !== "string" || pattern.length === 0) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
if (pattern.startsWith("^")) {
|
|
128
|
+
try {
|
|
129
|
+
return new RegExp(pattern).test(command);
|
|
130
|
+
} catch (_error) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return command.includes(pattern);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function firstMatch(patterns, command) {
|
|
138
|
+
if (!Array.isArray(patterns)) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
for (const pattern of patterns) {
|
|
142
|
+
if (matchesPattern(pattern, command)) {
|
|
143
|
+
return pattern;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Classify a command as allow/ask/deny against a policy. Most-restrictive-wins,
|
|
150
|
+
// deterministic. Stateless: the caller supplies opts.actionCount; trust-policy
|
|
151
|
+
// performs no session counting. Never executes the command.
|
|
152
|
+
function classifyCommand(policy, command, opts) {
|
|
153
|
+
const cmd = typeof command === "string" ? command : "";
|
|
154
|
+
const options = opts && typeof opts === "object" ? opts : {};
|
|
155
|
+
const limits = policy && policy.limits && typeof policy.limits === "object" ? policy.limits : {};
|
|
156
|
+
|
|
157
|
+
// 1. action-count cap.
|
|
158
|
+
if (
|
|
159
|
+
typeof options.actionCount === "number" &&
|
|
160
|
+
typeof limits.max_actions === "number" &&
|
|
161
|
+
options.actionCount >= limits.max_actions
|
|
162
|
+
) {
|
|
163
|
+
return {
|
|
164
|
+
verdict: "deny",
|
|
165
|
+
reason: `action-count cap reached (${options.actionCount}/${limits.max_actions})`,
|
|
166
|
+
matchedRule: { bucket: "limit", pattern: "limits.max_actions" },
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// 2. deny → 3. ask → 4. allow (first match wins per bucket).
|
|
171
|
+
const denyHit = firstMatch(policy && policy.deny, cmd);
|
|
172
|
+
if (denyHit) {
|
|
173
|
+
return {
|
|
174
|
+
verdict: "deny",
|
|
175
|
+
reason: `denied by policy rule: ${denyHit}`,
|
|
176
|
+
matchedRule: { bucket: "deny", pattern: denyHit },
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const askHit = firstMatch(policy && policy.ask, cmd);
|
|
181
|
+
if (askHit) {
|
|
182
|
+
return {
|
|
183
|
+
verdict: "ask",
|
|
184
|
+
reason: `requires confirmation by policy rule: ${askHit}`,
|
|
185
|
+
matchedRule: { bucket: "ask", pattern: askHit },
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const allowHit = firstMatch(policy && policy.allow, cmd);
|
|
190
|
+
if (allowHit) {
|
|
191
|
+
return {
|
|
192
|
+
verdict: "allow",
|
|
193
|
+
reason: `allowed by policy rule: ${allowHit}`,
|
|
194
|
+
matchedRule: { bucket: "allow", pattern: allowHit },
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// 5. no match → conservative ask.
|
|
199
|
+
return {
|
|
200
|
+
verdict: "ask",
|
|
201
|
+
reason: "no matching allow rule; defaulting to ask (conservative)",
|
|
202
|
+
matchedRule: null,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
module.exports = {
|
|
207
|
+
DEFAULT_POLICY,
|
|
208
|
+
loadPolicy,
|
|
209
|
+
classifyCommand,
|
|
210
|
+
validatePolicy,
|
|
211
|
+
policyFile,
|
|
212
|
+
};
|
package/src/lib/trust-redact.js
CHANGED
|
@@ -1,35 +1,58 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const PRIVATE_TAG_PATTERN = /<private>[\s\S]*?<\/private>/gi;
|
|
4
|
-
|
|
5
|
-
const SECRET_PATTERNS = [
|
|
6
|
-
|
|
7
|
-
/
|
|
8
|
-
/
|
|
9
|
-
/(?:
|
|
10
|
-
/sk-
|
|
11
|
-
/
|
|
12
|
-
/
|
|
13
|
-
/
|
|
14
|
-
/
|
|
15
|
-
/
|
|
16
|
-
/
|
|
17
|
-
/
|
|
18
|
-
/
|
|
19
|
-
/
|
|
20
|
-
]
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const PRIVATE_TAG_PATTERN = /<private>[\s\S]*?<\/private>/gi;
|
|
4
|
+
|
|
5
|
+
const SECRET_PATTERNS = [
|
|
6
|
+
/-----BEGIN [A-Z ]*(?:PRIVATE KEY|SECRET KEY)[-A-Z ]*-----[\s\S]*?-----END [A-Z ]*(?:PRIVATE KEY|SECRET KEY)[-A-Z ]*-----/g,
|
|
7
|
+
/(?:api[_-]?key|secret|token|password|credential|auth)[\s]*[=:]\s*["']?[A-Za-z0-9_\-/.+]{12,}["']?/gi,
|
|
8
|
+
/(?:[A-Z][A-Z0-9_]{2,}(?:KEY|SECRET|TOKEN|PASSWORD|CREDENTIAL|AUTH))[\s]*=[\s]*["']?[^\s"']{8,}["']?/g,
|
|
9
|
+
/(?:Authorization\s*[:=]\s*)?Bearer\s+[A-Za-z0-9._\-+/=]{20,}/gi,
|
|
10
|
+
/sk-proj-[A-Za-z0-9\-_]{20,}/g,
|
|
11
|
+
/(?:sk|pk|rk|ak)-[A-Za-z0-9][A-Za-z0-9\-_]{19,}/g,
|
|
12
|
+
/sk-ant-[A-Za-z0-9\-_]{20,}/g,
|
|
13
|
+
/gh[pus]_[A-Za-z0-9]{36,}/g,
|
|
14
|
+
/github_pat_[A-Za-z0-9_]{22,}/g,
|
|
15
|
+
/xoxb-[A-Za-z0-9\-]+/g,
|
|
16
|
+
/AKIA[0-9A-Z]{16}/g,
|
|
17
|
+
/AIza[A-Za-z0-9\-_]{35}/g,
|
|
18
|
+
/eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g,
|
|
19
|
+
/npm_[A-Za-z0-9]{36}/g,
|
|
20
|
+
/glpat-[A-Za-z0-9\-_]{20,}/g,
|
|
21
|
+
/dop_v1_[A-Za-z0-9]{64}/g,
|
|
22
|
+
/\b[A-Za-z0-9+/=_-]{48,}\b/g,
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
function secretPatternSources() {
|
|
26
|
+
return SECRET_PATTERNS.map((source) => new RegExp(source.source, source.flags));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function containsSecretMaterial(input) {
|
|
30
|
+
if (typeof input !== "string" || input.length === 0) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
if (PRIVATE_TAG_PATTERN.test(input)) {
|
|
34
|
+
PRIVATE_TAG_PATTERN.lastIndex = 0;
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
PRIVATE_TAG_PATTERN.lastIndex = 0;
|
|
38
|
+
for (const pattern of secretPatternSources()) {
|
|
39
|
+
if (pattern.test(input)) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function redact(input) {
|
|
47
|
+
if (typeof input !== "string") {
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let result = input.replace(PRIVATE_TAG_PATTERN, "[REDACTED]");
|
|
52
|
+
for (const pattern of secretPatternSources()) {
|
|
53
|
+
result = result.replace(pattern, "[REDACTED_SECRET]");
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = { redact, SECRET_PATTERNS, containsSecretMaterial };
|