@cosmicdrift/kumiko-guards 0.413.1 → 0.415.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 +15 -9
- package/package.json +4 -4
- package/src/_lib/agent-docs-api-nodes.ts +9 -2
- package/src/_lib/agent-docs-api-render.ts +31 -10
- package/src/_lib/agent-docs-api.ts +13 -9
- package/src/_lib/agent-docs-feature-imports.ts +12 -1
- package/src/_lib/baseline-compare.ts +1 -2
- package/src/_lib/doc-status.ts +8 -4
- package/src/_lib/dockerfile.ts +28 -5
- package/src/_lib/escaped-literal.ts +26 -0
- package/src/_lib/npm-registry.ts +2 -2
- package/src/_lib/run-slots.ts +4 -6
- package/src/_lib/security-audit.ts +22 -6
- package/src/_lib/test-es-raw-writes.ts +5 -3
- package/src/changes.json +51 -0
- package/src/check-security.ts +4 -3
- package/src/guard-app-dockerfile.ts +29 -12
- package/src/guard-ignore-tag-reason.ts +18 -4
- package/src/guard-internal-subpath-imports.ts +35 -25
- package/src/guard-rls-session-settings.ts +48 -6
- package/src/guard-schema-cli-features.ts +22 -1
- package/src/guard-security-plugin-suppression.ts +368 -0
- package/src/guard-test-es-row-writes.ts +2 -1
- package/src/guard-unsafe-array-param.ts +4 -7
- package/src/pre-push.sh +46 -6
- package/src/run-guards.ts +2 -28
- package/src/run-repo-checks.ts +0 -6
- package/src/run-steps-parallel.ts +4 -4
- package/src/run-ui-guards.ts +1 -15
- package/src/_lib/german-test-title.ts +0 -94
- package/src/_lib/primitives-access.ts +0 -23
- package/src/check-predicates.ts +0 -244
- package/src/guard-admin-api.ts +0 -138
- package/src/guard-direct-fetch.ts +0 -161
- package/src/guard-error-reasons.ts +0 -210
- package/src/guard-event-store-writes.ts +0 -124
- package/src/guard-i18n-locale-terminology.ts +0 -134
- package/src/guard-no-custom-primitives.ts +0 -193
- package/src/guard-no-date-api.ts +0 -183
- package/src/guard-no-direct-fs.ts +0 -346
- package/src/guard-no-direct-process-env.ts +0 -127
- package/src/guard-no-inline-styles.ts +0 -64
- package/src/guard-no-raw-hooks.ts +0 -80
- package/src/guard-no-temporal-polyfill-import.ts +0 -131
- package/src/guard-primitives-discipline.ts +0 -357
- package/src/guard-raw-classname.ts +0 -117
- package/src/guard-raw-interactive-elements.ts +0 -164
- package/src/guard-restricted-symbols.ts +0 -155
- package/src/guard-silent-skip.ts +0 -186
- package/src/guard-test-es-fixtures.ts +0 -85
- package/src/guard-test-title.ts +0 -159
- package/src/guard-thin-wrappers.ts +0 -471
- package/src/guard-unsafe-json-parse.ts +0 -87
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Security-Plugin-Suppression Guard: `// biome-ignore lint/plugin: <reason>` must not silence the security Biome plugins
|
|
4
|
+
* (admin API, event-store literal writes, restricted event-store symbols, direct fs, server-side direct fetch).
|
|
5
|
+
* The category `lint/plugin` covers every plugin, so a three-word reason would pass the ignore-tag-reason guard and still switch off
|
|
6
|
+
* an SSRF, path-traversal or event-store check. The guard re-runs Biome over the files that carry such a comment, in a temp copy
|
|
7
|
+
* with those comments neutralised and only the security plugins (taken from the preset, `includes` untouched) enabled.
|
|
8
|
+
* Every remaining diagnostic is a suppressed security finding. Exceptions live in the reviewed
|
|
9
|
+
* `.kumiko-security-plugin-suppression-baseline.json`; without it the guard fails closed. UI plugins (raw-ui, raw-hooks, ...)
|
|
10
|
+
* and browser-side fetch stay suppressible.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
14
|
+
import { tmpdir } from "node:os";
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
import { isPlainObject } from "@cosmicdrift/kumiko-types/type-guards";
|
|
17
|
+
import type { SourceFile } from "ts-morph";
|
|
18
|
+
import { scanCommentTrivia } from "./_lib/comment-trivia";
|
|
19
|
+
import {
|
|
20
|
+
ALL_REPO_KINDS,
|
|
21
|
+
type AstGuard,
|
|
22
|
+
baselineRatchet,
|
|
23
|
+
buildSharedProject,
|
|
24
|
+
filesForGuard,
|
|
25
|
+
findRepoRootFor,
|
|
26
|
+
type GuardViolation,
|
|
27
|
+
isLocalFinding,
|
|
28
|
+
relFromRepoRoot,
|
|
29
|
+
runStandalone,
|
|
30
|
+
type ScanSpec,
|
|
31
|
+
} from "./_lib/guard-kit";
|
|
32
|
+
import { type RepoRoot, resolveRepoRoots } from "./_lib/roots";
|
|
33
|
+
|
|
34
|
+
const ROOT = process.cwd();
|
|
35
|
+
const GUARD_NAME = "security-plugin-suppression";
|
|
36
|
+
|
|
37
|
+
const SCAN: ScanSpec = {
|
|
38
|
+
scope: "source+tests",
|
|
39
|
+
kinds: ALL_REPO_KINDS,
|
|
40
|
+
extensions: ["ts", "tsx"],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const EXCLUDE = /(\.d\.(ts|tsx)$|\/dist\/)/;
|
|
44
|
+
|
|
45
|
+
const SECURITY_PLUGIN_NAMES: ReadonlySet<string> = new Set([
|
|
46
|
+
"admin-api",
|
|
47
|
+
"es-literal-writes",
|
|
48
|
+
"es-literal-writes-tests",
|
|
49
|
+
"restricted-event-store-symbols",
|
|
50
|
+
"no-direct-fs",
|
|
51
|
+
"no-direct-fetch",
|
|
52
|
+
]);
|
|
53
|
+
// no-direct-fetch has a second preset entry for browser code, which is no SSRF path.
|
|
54
|
+
const BROWSER_ONLY_INCLUDE = "**/web/**/*.tsx";
|
|
55
|
+
|
|
56
|
+
const PLUGIN_SUPPRESSION_RE = /biome-ignore(?:-all|-start)?\s+lint\/plugin\S*/;
|
|
57
|
+
// Same length as the original, so line and column numbers of the diagnostics stay valid.
|
|
58
|
+
const NEUTRALIZE_RE = /biome-ignore(?=(?:-all|-start)?\s+lint\/plugin)/g;
|
|
59
|
+
const NEUTRALIZED = "biome_ignore";
|
|
60
|
+
|
|
61
|
+
const PRESET_REPO_PATH = "packages/framework/presets/biome-rules.json";
|
|
62
|
+
const PRESET_PACKAGE_PATH = "@cosmicdrift/kumiko-framework/biome-rules";
|
|
63
|
+
|
|
64
|
+
type PresetPlugin = {
|
|
65
|
+
readonly path: string;
|
|
66
|
+
readonly resolutionKind?: string;
|
|
67
|
+
readonly includes?: readonly string[];
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
type PluginFinding = { readonly count: number; readonly firstLine: number };
|
|
71
|
+
|
|
72
|
+
export type SecurityPluginScan = {
|
|
73
|
+
readonly findings: Readonly<Record<string, PluginFinding>>;
|
|
74
|
+
readonly failures: readonly string[];
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export function hasPluginSuppression(fullText: string): boolean {
|
|
78
|
+
if (!fullText.includes("lint/plugin")) return false;
|
|
79
|
+
return scanCommentTrivia(fullText).some((comment) => PLUGIN_SUPPRESSION_RE.test(comment.text));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function neutralizePluginSuppressions(fullText: string): string {
|
|
83
|
+
let result = "";
|
|
84
|
+
let copiedUpTo = 0;
|
|
85
|
+
for (const comment of scanCommentTrivia(fullText)) {
|
|
86
|
+
const neutralized = comment.text.replace(NEUTRALIZE_RE, NEUTRALIZED);
|
|
87
|
+
if (neutralized === comment.text) continue;
|
|
88
|
+
result += fullText.slice(copiedUpTo, comment.start) + neutralized;
|
|
89
|
+
copiedUpTo = comment.start + comment.text.length;
|
|
90
|
+
}
|
|
91
|
+
return result + fullText.slice(copiedUpTo);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function isPresetPlugin(value: unknown): value is PresetPlugin {
|
|
95
|
+
return (
|
|
96
|
+
typeof value === "object" &&
|
|
97
|
+
value !== null &&
|
|
98
|
+
"path" in value &&
|
|
99
|
+
typeof value.path === "string" &&
|
|
100
|
+
(!("includes" in value) ||
|
|
101
|
+
(Array.isArray(value.includes) && value.includes.every((item) => typeof item === "string")))
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function resolvePresetPath(repoRoot: string): string | undefined {
|
|
106
|
+
const inRepo = path.join(repoRoot, PRESET_REPO_PATH);
|
|
107
|
+
if (existsSync(inRepo)) return inRepo;
|
|
108
|
+
try {
|
|
109
|
+
return Bun.resolveSync(PRESET_PACKAGE_PATH, repoRoot);
|
|
110
|
+
} catch {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function resolveBiomeBin(repoRoot: string): string | undefined {
|
|
116
|
+
try {
|
|
117
|
+
return path.join(
|
|
118
|
+
path.dirname(Bun.resolveSync("@biomejs/biome/package.json", repoRoot)),
|
|
119
|
+
"bin",
|
|
120
|
+
"biome",
|
|
121
|
+
);
|
|
122
|
+
} catch {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function pluginName(pluginPath: string): string {
|
|
128
|
+
return path.basename(pluginPath, ".grit");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function securityPluginEntries(presetPath: string): PresetPlugin[] | string {
|
|
132
|
+
let parsed: unknown;
|
|
133
|
+
try {
|
|
134
|
+
parsed = JSON.parse(readFileSync(presetPath, "utf-8"));
|
|
135
|
+
} catch (error) {
|
|
136
|
+
return `cannot read Biome preset ${presetPath}: ${error instanceof Error ? error.message : String(error)}`;
|
|
137
|
+
}
|
|
138
|
+
const plugins =
|
|
139
|
+
typeof parsed === "object" && parsed !== null && "plugins" in parsed
|
|
140
|
+
? parsed.plugins
|
|
141
|
+
: undefined;
|
|
142
|
+
if (!Array.isArray(plugins) || !plugins.every(isPresetPlugin)) {
|
|
143
|
+
return `Biome preset ${presetPath} has no valid "plugins" list`;
|
|
144
|
+
}
|
|
145
|
+
const baseDir = path.dirname(presetPath);
|
|
146
|
+
const entries = plugins
|
|
147
|
+
.filter((entry) => SECURITY_PLUGIN_NAMES.has(pluginName(entry.path)))
|
|
148
|
+
.filter((entry) => !(entry.includes ?? []).includes(BROWSER_ONLY_INCLUDE))
|
|
149
|
+
.map((entry) => ({ ...entry, path: path.resolve(baseDir, entry.path) }));
|
|
150
|
+
const found = new Set(entries.map((entry) => pluginName(entry.path)));
|
|
151
|
+
const missing = [...SECURITY_PLUGIN_NAMES].filter((name) => !found.has(name));
|
|
152
|
+
return missing.length > 0
|
|
153
|
+
? `Biome preset ${presetPath} lacks security plugin(s): ${missing.join(", ")}`
|
|
154
|
+
: entries;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
type BiomeDiagnostic = {
|
|
158
|
+
readonly severity: string;
|
|
159
|
+
readonly category: string;
|
|
160
|
+
readonly message: string;
|
|
161
|
+
readonly path: string | undefined;
|
|
162
|
+
readonly line: number;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export function parseBiomeDiagnostics(stdout: string): BiomeDiagnostic[] | undefined {
|
|
166
|
+
const jsonLine = stdout.split("\n").find((line) => line.startsWith("{"));
|
|
167
|
+
if (jsonLine === undefined) return undefined;
|
|
168
|
+
let parsed: unknown;
|
|
169
|
+
try {
|
|
170
|
+
parsed = JSON.parse(jsonLine);
|
|
171
|
+
} catch {
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
const raw = isPlainObject(parsed) ? parsed["diagnostics"] : undefined;
|
|
175
|
+
if (!Array.isArray(raw)) return undefined;
|
|
176
|
+
const diagnostics: BiomeDiagnostic[] = [];
|
|
177
|
+
for (const item of raw) {
|
|
178
|
+
const diagnostic = toBiomeDiagnostic(item);
|
|
179
|
+
if (diagnostic === undefined) return undefined;
|
|
180
|
+
diagnostics.push(diagnostic);
|
|
181
|
+
}
|
|
182
|
+
return diagnostics;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function diagnosticLocation(location: unknown): { path: string | undefined; line: number } {
|
|
186
|
+
if (!isPlainObject(location)) return { path: undefined, line: 1 };
|
|
187
|
+
const { path: locPath, start } = location;
|
|
188
|
+
const line = isPlainObject(start) && typeof start["line"] === "number" ? start["line"] : 1;
|
|
189
|
+
return { path: typeof locPath === "string" ? locPath : undefined, line };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function toBiomeDiagnostic(item: unknown): BiomeDiagnostic | undefined {
|
|
193
|
+
if (!isPlainObject(item)) return undefined;
|
|
194
|
+
const { severity, category, message, location } = item;
|
|
195
|
+
if (typeof severity !== "string" || typeof category !== "string") return undefined;
|
|
196
|
+
return {
|
|
197
|
+
severity,
|
|
198
|
+
category,
|
|
199
|
+
message: typeof message === "string" ? message : "",
|
|
200
|
+
...diagnosticLocation(location),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function runBiomeInTempRepo(
|
|
205
|
+
biomeBin: string,
|
|
206
|
+
tempDir: string,
|
|
207
|
+
plugins: readonly PresetPlugin[],
|
|
208
|
+
): { diagnostics: BiomeDiagnostic[] } | { failure: string } {
|
|
209
|
+
writeFileSync(
|
|
210
|
+
path.join(tempDir, "biome.json"),
|
|
211
|
+
JSON.stringify({
|
|
212
|
+
root: true,
|
|
213
|
+
vcs: { enabled: false },
|
|
214
|
+
formatter: { enabled: false },
|
|
215
|
+
assist: { enabled: false },
|
|
216
|
+
linter: { enabled: true, rules: { preset: "none" } },
|
|
217
|
+
plugins,
|
|
218
|
+
}),
|
|
219
|
+
);
|
|
220
|
+
const proc = Bun.spawnSync(
|
|
221
|
+
["bun", biomeBin, "lint", "--reporter=json", "--max-diagnostics=none", "."],
|
|
222
|
+
{ cwd: tempDir, stdout: "pipe", stderr: "pipe" },
|
|
223
|
+
);
|
|
224
|
+
const diagnostics = parseBiomeDiagnostics(proc.stdout.toString());
|
|
225
|
+
// Exit 1 is Biome's "diagnostics found"; anything else, or an unreadable answer, is a crash.
|
|
226
|
+
if (diagnostics === undefined || (proc.exitCode !== 0 && proc.exitCode !== 1)) {
|
|
227
|
+
return {
|
|
228
|
+
failure: `Biome did not answer with a readable lint report (exit ${proc.exitCode}): ${proc.stderr.toString().trim().slice(0, 300)}`,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
const broken = diagnostics.find((d) => d.severity === "error" && d.category !== "plugin");
|
|
232
|
+
if (broken !== undefined) {
|
|
233
|
+
return { failure: `Biome reported a non-plugin error (${broken.category}): ${broken.message}` };
|
|
234
|
+
}
|
|
235
|
+
return { diagnostics: diagnostics.filter((d) => d.category === "plugin") };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export function scanSecurityPluginSuppressions(
|
|
239
|
+
repoRoot: string,
|
|
240
|
+
filesByRelPath: ReadonlyMap<string, string>,
|
|
241
|
+
): SecurityPluginScan {
|
|
242
|
+
const suppressed = new Map([...filesByRelPath].filter(([, text]) => hasPluginSuppression(text)));
|
|
243
|
+
if (suppressed.size === 0) return { findings: {}, failures: [] };
|
|
244
|
+
const presetPath = resolvePresetPath(repoRoot);
|
|
245
|
+
const biomeBin = resolveBiomeBin(repoRoot);
|
|
246
|
+
if (presetPath === undefined || biomeBin === undefined) {
|
|
247
|
+
return {
|
|
248
|
+
findings: {},
|
|
249
|
+
failures: [
|
|
250
|
+
`cannot resolve Biome preset/binary from ${repoRoot} to check plugin suppressions`,
|
|
251
|
+
],
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
const plugins = securityPluginEntries(presetPath);
|
|
255
|
+
if (typeof plugins === "string") return { findings: {}, failures: [plugins] };
|
|
256
|
+
|
|
257
|
+
const tempDir = mkdtempSync(path.join(tmpdir(), "kumiko-security-plugin-suppression-"));
|
|
258
|
+
try {
|
|
259
|
+
for (const [rel, text] of suppressed) {
|
|
260
|
+
const target = path.join(tempDir, rel);
|
|
261
|
+
mkdirSync(path.dirname(target), { recursive: true });
|
|
262
|
+
writeFileSync(target, neutralizePluginSuppressions(text));
|
|
263
|
+
}
|
|
264
|
+
const result = runBiomeInTempRepo(biomeBin, tempDir, plugins);
|
|
265
|
+
if ("failure" in result) return { findings: {}, failures: [result.failure] };
|
|
266
|
+
const findings: Record<string, PluginFinding> = {};
|
|
267
|
+
for (const diagnostic of result.diagnostics) {
|
|
268
|
+
if (diagnostic.path === undefined) continue;
|
|
269
|
+
const previous = findings[diagnostic.path];
|
|
270
|
+
findings[diagnostic.path] = {
|
|
271
|
+
count: (previous?.count ?? 0) + 1,
|
|
272
|
+
firstLine: previous?.firstLine ?? diagnostic.line,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
return { findings, failures: [] };
|
|
276
|
+
} catch (error) {
|
|
277
|
+
return {
|
|
278
|
+
findings: {},
|
|
279
|
+
failures: [
|
|
280
|
+
`security plugin scan crashed: ${error instanceof Error ? error.message : String(error)}`,
|
|
281
|
+
],
|
|
282
|
+
};
|
|
283
|
+
} finally {
|
|
284
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function scanRepo(
|
|
289
|
+
files: readonly SourceFile[],
|
|
290
|
+
roots: readonly RepoRoot[],
|
|
291
|
+
): { counts: Record<string, number>; firstLine: Record<string, number>; failures: string[] } {
|
|
292
|
+
const byRoot = new Map<string, Map<string, string>>();
|
|
293
|
+
for (const sf of files) {
|
|
294
|
+
const filePath = sf.getFilePath();
|
|
295
|
+
if (EXCLUDE.test(filePath)) continue;
|
|
296
|
+
const root = findRepoRootFor(filePath, roots);
|
|
297
|
+
if (root === undefined) continue;
|
|
298
|
+
const rel = relFromRepoRoot(filePath, roots);
|
|
299
|
+
if (!isLocalFinding({ file: rel })) continue;
|
|
300
|
+
const bucket = byRoot.get(root.absPath) ?? new Map<string, string>();
|
|
301
|
+
bucket.set(rel, sf.getFullText());
|
|
302
|
+
byRoot.set(root.absPath, bucket);
|
|
303
|
+
}
|
|
304
|
+
const counts: Record<string, number> = {};
|
|
305
|
+
const firstLine: Record<string, number> = {};
|
|
306
|
+
const failures: string[] = [];
|
|
307
|
+
for (const [repoRoot, bucket] of byRoot) {
|
|
308
|
+
const scan = scanSecurityPluginSuppressions(repoRoot, bucket);
|
|
309
|
+
failures.push(...scan.failures);
|
|
310
|
+
for (const [file, finding] of Object.entries(scan.findings)) {
|
|
311
|
+
counts[file] = finding.count;
|
|
312
|
+
firstLine[file] = finding.firstLine;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return { counts, firstLine, failures };
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function suppressionBaselineFor(baselineRoot: string) {
|
|
319
|
+
return baselineRatchet({
|
|
320
|
+
file: path.join(baselineRoot, ".kumiko-security-plugin-suppression-baseline.json"),
|
|
321
|
+
formatVersion: 1,
|
|
322
|
+
unit: "suppressed security plugin finding(s)",
|
|
323
|
+
failClosed: true,
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const REMEDIATION =
|
|
328
|
+
"A biome-ignore on lint/plugin cannot silence the security plugins (egress/SSRF, direct fs, event-store writes, admin API). Fix the call: egress(policy), FileStorageProvider, the event-store API. An unavoidable exception needs a reviewed baseline entry.";
|
|
329
|
+
|
|
330
|
+
export function createGuard(options: { readonly baselineRoot?: string } = {}): AstGuard {
|
|
331
|
+
const suppressionBaseline = suppressionBaselineFor(options.baselineRoot ?? ROOT);
|
|
332
|
+
return {
|
|
333
|
+
name: GUARD_NAME,
|
|
334
|
+
scan: SCAN,
|
|
335
|
+
hint: `reviewed exceptions only: \`kumiko-guards guards --write-baseline --guard=${GUARD_NAME}\``,
|
|
336
|
+
run: (files, roots = resolveRepoRoots()) => {
|
|
337
|
+
const { counts, firstLine, failures } = scanRepo(files, roots);
|
|
338
|
+
const failureViolations: GuardViolation[] = failures.map((message) => ({
|
|
339
|
+
file: ".",
|
|
340
|
+
line: 1,
|
|
341
|
+
message: `security plugin scan failed closed: ${message}`,
|
|
342
|
+
}));
|
|
343
|
+
return {
|
|
344
|
+
violations: [
|
|
345
|
+
...failureViolations,
|
|
346
|
+
...suppressionBaseline.check(counts, REMEDIATION, {
|
|
347
|
+
formatDriftRemediation: `Run \`kumiko-guards guards --write-baseline --guard=${GUARD_NAME}\` once.`,
|
|
348
|
+
resolveLine: (file) => firstLine[file] ?? 1,
|
|
349
|
+
}),
|
|
350
|
+
],
|
|
351
|
+
};
|
|
352
|
+
},
|
|
353
|
+
writeBaseline: (files, roots = resolveRepoRoots()) => {
|
|
354
|
+
suppressionBaseline.write(scanRepo(files, roots).counts);
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export const guard: AstGuard = createGuard();
|
|
360
|
+
|
|
361
|
+
if (import.meta.main) {
|
|
362
|
+
if (process.argv.slice(2).includes("--write-baseline")) {
|
|
363
|
+
const project = buildSharedProject([guard]);
|
|
364
|
+
guard.writeBaseline?.(filesForGuard(project, guard));
|
|
365
|
+
process.exit(0);
|
|
366
|
+
}
|
|
367
|
+
runStandalone(guard);
|
|
368
|
+
}
|
|
@@ -28,8 +28,9 @@ const SCAN: ScanSpec = { scope: "tests", extensions: ["ts"], kinds: ["framework"
|
|
|
28
28
|
const ALLOWLIST: readonly RegExp[] = [
|
|
29
29
|
// Home of the helpers.
|
|
30
30
|
/^packages\/testing\/src\//,
|
|
31
|
-
// The guard's own fixtures.
|
|
31
|
+
// The guard's own fixtures and the Biome plugin fixtures of the same rule.
|
|
32
32
|
/^packages\/guards\/src\/__tests__\//,
|
|
33
|
+
/^packages\/framework\/src\/presets\/__tests__\//,
|
|
33
34
|
// Simulates event-less legacy rows for the backfill.
|
|
34
35
|
/^packages\/bundled-features\/src\/user-data-rights\/__tests__\/read-users-rebuild-survives-lifecycle\.integration\.test\.ts$/,
|
|
35
36
|
// Stands in for the handover move, which itself writes directly.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
/**
|
|
3
|
-
* Warns when a `.unsafe(sql, [...])` parameter list holds a JS array
|
|
3
|
+
* Warns when a `.unsafe(sql, [...])` parameter list holds a JS array literal.
|
|
4
4
|
*
|
|
5
5
|
* Bun.SQL binds a JS array parameter as "a,b" on Linux, so `ANY($n)` fails with a
|
|
6
6
|
* malformed array literal in CI while the same call passes on macOS. Pass
|
|
7
7
|
* `toPostgresArrayLiteral(values)` (from `@cosmicdrift/kumiko-framework/db`) and cast the
|
|
8
8
|
* placeholder (`$1::text[]`).
|
|
9
9
|
*
|
|
10
|
-
* Heuristic without type info: only array literals
|
|
10
|
+
* Heuristic without type info: only array literals directly inside the
|
|
11
11
|
* parameter-list literal are reported; array-typed variables pass unnoticed. Warning only.
|
|
12
12
|
*/
|
|
13
13
|
|
|
@@ -40,6 +40,8 @@ function unwrapExpression(node: Node): Node {
|
|
|
40
40
|
while (
|
|
41
41
|
Node.isAsExpression(current) ||
|
|
42
42
|
Node.isSatisfiesExpression(current) ||
|
|
43
|
+
Node.isNonNullExpression(current) ||
|
|
44
|
+
Node.isTypeAssertion(current) ||
|
|
43
45
|
Node.isParenthesizedExpression(current)
|
|
44
46
|
) {
|
|
45
47
|
current = current.getExpression();
|
|
@@ -63,11 +65,6 @@ export function findUnsafeArrayParams(sf: SourceFile): UnsafeArrayParamFinding[]
|
|
|
63
65
|
line: element.getStartLineNumber(),
|
|
64
66
|
message: `array literal as an unsafe() parameter binds as "a,b" on Linux; ${FIX_HINT}`,
|
|
65
67
|
});
|
|
66
|
-
} else if (Node.isSpreadElement(element)) {
|
|
67
|
-
findings.push({
|
|
68
|
-
line: element.getStartLineNumber(),
|
|
69
|
-
message: `spread in the unsafe() parameter list; if it feeds ANY($n), ${FIX_HINT}`,
|
|
70
|
-
});
|
|
71
68
|
}
|
|
72
69
|
}
|
|
73
70
|
}
|
package/src/pre-push.sh
CHANGED
|
@@ -90,20 +90,54 @@ has_ui_roots() {
|
|
|
90
90
|
' "$REPO_ROOT/kumiko.json") >/dev/null 2>&1
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
# Re-entry from the wrapping check-wt.sh
|
|
94
|
-
#
|
|
95
|
-
#
|
|
96
|
-
#
|
|
93
|
+
# Re-entry from the wrapping check-wt.sh needs three proofs, so a freely
|
|
94
|
+
# exported variable can neither skip the tracked check-wt.sh nor the pre-flight
|
|
95
|
+
# steps below: the hook records its PID in KUMIKO_CHECK_WT_OWNER and a random
|
|
96
|
+
# nonce in KUMIKO_CHECK_WT_NONCE plus a 0600 file in the git common dir; the
|
|
97
|
+
# owner must be an ancestor (or this very process, when check-wt.sh exec'd the
|
|
98
|
+
# hook) and an ancestor must be running check-wt.sh.
|
|
99
|
+
prepush_nonce_file() {
|
|
100
|
+
printf '%s/kumiko-prepush-%s' "$GIT_COMMON_DIR" "$1"
|
|
101
|
+
}
|
|
102
|
+
|
|
97
103
|
is_reentry_from_check_wt() {
|
|
98
104
|
reentry_pid=$$
|
|
99
105
|
case "${KUMIKO_CHECK_WT_OWNER:-}" in '' | *[!0-9]*) return 1 ;; esac
|
|
106
|
+
case "${KUMIKO_CHECK_WT_NONCE:-}" in '' | *[!0-9a-f]*) return 1 ;; esac
|
|
107
|
+
stored_nonce=""
|
|
108
|
+
IFS= read -r stored_nonce < "$(prepush_nonce_file "$KUMIKO_CHECK_WT_OWNER")" 2>/dev/null || return 1
|
|
109
|
+
[ "$stored_nonce" = "$KUMIKO_CHECK_WT_NONCE" ] || return 1
|
|
100
110
|
while [ -n "$reentry_pid" ] && [ "$reentry_pid" -gt 1 ]; do
|
|
101
|
-
[ "$reentry_pid" = "$KUMIKO_CHECK_WT_OWNER" ]
|
|
111
|
+
if [ "$reentry_pid" = "$KUMIKO_CHECK_WT_OWNER" ]; then
|
|
112
|
+
# An exec'd check-wt.sh has become this hook, so its command line no longer names the script.
|
|
113
|
+
[ "$reentry_pid" = "$$" ] && return 0
|
|
114
|
+
owner_command=$(ps -o command= -p "$reentry_pid" 2>/dev/null)
|
|
115
|
+
case "$owner_command" in *scripts/check-wt.sh*) return 0 ;; esac
|
|
116
|
+
return 1
|
|
117
|
+
fi
|
|
102
118
|
reentry_pid=$(ps -o ppid= -p "$reentry_pid" 2>/dev/null | tr -d ' ')
|
|
103
119
|
done
|
|
104
120
|
return 1
|
|
105
121
|
}
|
|
106
122
|
|
|
123
|
+
# Nonce files of finished runs are not removed by the exec'd check-wt.sh, so
|
|
124
|
+
# each outer run sweeps the ones whose PID is gone.
|
|
125
|
+
sweep_stale_prepush_nonces() {
|
|
126
|
+
for stale_file in "$GIT_COMMON_DIR"/kumiko-prepush-*; do
|
|
127
|
+
[ -e "$stale_file" ] || continue
|
|
128
|
+
stale_pid=${stale_file##*-}
|
|
129
|
+
case "$stale_pid" in '' | *[!0-9]*) continue ;; esac
|
|
130
|
+
kill -0 "$stale_pid" 2>/dev/null || rm -f "$stale_file"
|
|
131
|
+
done
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
write_prepush_nonce() {
|
|
135
|
+
new_nonce=$(od -An -N16 -tx1 /dev/urandom | tr -d ' \n')
|
|
136
|
+
case "$new_nonce" in '' | *[!0-9a-f]*) return 1 ;; esac
|
|
137
|
+
(umask 077 && printf '%s\n' "$new_nonce" > "$(prepush_nonce_file "$$")") || return 1
|
|
138
|
+
printf '%s' "$new_nonce"
|
|
139
|
+
}
|
|
140
|
+
|
|
107
141
|
CHECK_WT_REENTRY=0
|
|
108
142
|
if is_reentry_from_check_wt; then
|
|
109
143
|
CHECK_WT_REENTRY=1
|
|
@@ -192,7 +226,13 @@ if [ "$CHECK_WT_REENTRY" = 0 ] \
|
|
|
192
226
|
&& git -C "$REPO_ROOT" ls-files --error-unmatch scripts/check-wt.sh >/dev/null 2>&1 \
|
|
193
227
|
&& [ -x "$REPO_ROOT/scripts/check-wt.sh" ]; then
|
|
194
228
|
echo "[pre-push] worktree detected — worktree check (see scripts/check-wt.sh)…"
|
|
195
|
-
|
|
229
|
+
sweep_stale_prepush_nonces
|
|
230
|
+
# Without a recorded nonce the delegated run could not be recognised as re-entry and would loop.
|
|
231
|
+
if ! CHECK_WT_NONCE=$(write_prepush_nonce); then
|
|
232
|
+
echo "[pre-push] FATAL: could not write the re-entry nonce file in '$GIT_COMMON_DIR' — refusing push" >&2
|
|
233
|
+
exit 1
|
|
234
|
+
fi
|
|
235
|
+
cd "$REPO_ROOT" && KUMIKO_CHECK_WT_OWNER=$$ KUMIKO_CHECK_WT_NONCE=$CHECK_WT_NONCE exec "$REPO_ROOT/scripts/check-wt.sh"
|
|
196
236
|
fi
|
|
197
237
|
|
|
198
238
|
# The repo that ships kumiko-guards runs its checked-out cli.ts, so a push checks
|
package/src/run-guards.ts
CHANGED
|
@@ -22,80 +22,54 @@ import { acquireGuardRunSlot } from "./_lib/run-slots";
|
|
|
22
22
|
import { writeSecurityBaselines } from "./_lib/security-baseline-cli";
|
|
23
23
|
import { guard as asCasts } from "./check-as-casts";
|
|
24
24
|
import { guard as complexity } from "./check-complexity";
|
|
25
|
-
import { guard as predicateExtraction } from "./check-predicates";
|
|
26
|
-
import { guard as adminApi } from "./guard-admin-api";
|
|
27
25
|
import { guard as appFeatureStructure } from "./guard-app-feature-structure";
|
|
28
26
|
import { guard as commentIssueRefOnly } from "./guard-comment-issue-ref-only";
|
|
29
27
|
import { guard as crossFeatureImports } from "./guard-cross-feature-imports";
|
|
30
28
|
import { guard as directEntityWrites } from "./guard-direct-entity-writes";
|
|
31
|
-
import { guard as directFetch } from "./guard-direct-fetch";
|
|
32
|
-
import { guard as errorReasons } from "./guard-error-reasons";
|
|
33
|
-
import { guard as eventStoreWrites } from "./guard-event-store-writes";
|
|
34
29
|
import { guard as fakeTests } from "./guard-fake-tests";
|
|
35
30
|
import { guard as fileSize } from "./guard-file-size";
|
|
36
31
|
import { guard as htmlEscape } from "./guard-html-escape";
|
|
37
32
|
import { guard as i18nKeys } from "./guard-i18n-keys";
|
|
38
33
|
import { guard as i18nLocaleMount } from "./guard-i18n-locale-mount";
|
|
39
|
-
import { guard as i18nLocaleTerminology } from "./guard-i18n-locale-terminology";
|
|
40
34
|
import { guard as ignoreTagReason } from "./guard-ignore-tag-reason";
|
|
41
35
|
import { guard as importExtensions } from "./guard-import-extensions";
|
|
42
36
|
import { guard as internalSubpathImports } from "./guard-internal-subpath-imports";
|
|
43
37
|
import { guard as libTestCoverage } from "./guard-lib-test-coverage";
|
|
44
|
-
import { guard as noDateApi } from "./guard-no-date-api";
|
|
45
|
-
import { guard as noDirectFs } from "./guard-no-direct-fs";
|
|
46
38
|
import { guard as noLogicInViews } from "./guard-no-logic-in-views";
|
|
47
|
-
import { guard as noTemporalPolyfillImport } from "./guard-no-temporal-polyfill-import";
|
|
48
|
-
import { guard as restrictedSymbols } from "./guard-restricted-symbols";
|
|
49
39
|
import { guard as rlsSessionSettings } from "./guard-rls-session-settings";
|
|
50
40
|
import { guard as screenConventions } from "./guard-screen-conventions";
|
|
51
|
-
import { guard as
|
|
41
|
+
import { guard as securityPluginSuppression } from "./guard-security-plugin-suppression";
|
|
52
42
|
import { guard as tenantEscalation } from "./guard-tenant-escalation";
|
|
53
|
-
import { guard as testEsFixtures } from "./guard-test-es-fixtures";
|
|
54
43
|
import { guard as testEsRowWrites } from "./guard-test-es-row-writes";
|
|
55
44
|
import { guard as testTemplateDrift } from "./guard-test-template-drift";
|
|
56
45
|
import { guard as testTimeouts } from "./guard-test-timeouts";
|
|
57
|
-
import { guard as testTitle } from "./guard-test-title";
|
|
58
|
-
import { guard as unsafeJsonParse } from "./guard-unsafe-json-parse";
|
|
59
46
|
import { guard as writeHandlerQns } from "./guard-write-handler-qns";
|
|
60
47
|
|
|
61
48
|
export const GUARDS = [
|
|
62
|
-
adminApi,
|
|
63
49
|
directEntityWrites,
|
|
64
|
-
directFetch,
|
|
65
|
-
noDirectFs,
|
|
66
50
|
tenantEscalation,
|
|
67
|
-
unsafeJsonParse,
|
|
68
|
-
silentSkip,
|
|
69
51
|
htmlEscape,
|
|
70
52
|
importExtensions,
|
|
71
53
|
crossFeatureImports,
|
|
72
|
-
noDateApi,
|
|
73
|
-
noTemporalPolyfillImport,
|
|
74
|
-
restrictedSymbols,
|
|
75
54
|
internalSubpathImports,
|
|
76
55
|
rlsSessionSettings,
|
|
77
56
|
fakeTests,
|
|
78
57
|
noLogicInViews,
|
|
79
|
-
errorReasons,
|
|
80
58
|
i18nKeys,
|
|
81
59
|
i18nLocaleMount,
|
|
82
|
-
i18nLocaleTerminology,
|
|
83
60
|
complexity,
|
|
84
|
-
predicateExtraction,
|
|
85
61
|
screenConventions,
|
|
86
62
|
writeHandlerQns,
|
|
87
63
|
asCasts,
|
|
88
|
-
eventStoreWrites,
|
|
89
64
|
appFeatureStructure,
|
|
90
65
|
libTestCoverage,
|
|
91
66
|
testTimeouts,
|
|
92
|
-
testEsFixtures,
|
|
93
67
|
testEsRowWrites,
|
|
94
68
|
testTemplateDrift,
|
|
95
69
|
fileSize,
|
|
96
70
|
commentIssueRefOnly,
|
|
97
|
-
testTitle,
|
|
98
71
|
ignoreTagReason,
|
|
72
|
+
securityPluginSuppression,
|
|
99
73
|
];
|
|
100
74
|
|
|
101
75
|
export const GUARD_FLAGS = [
|
package/src/run-repo-checks.ts
CHANGED
|
@@ -13,22 +13,16 @@ import { check as appDockerfile } from "./guard-app-dockerfile";
|
|
|
13
13
|
import { check as docStatus } from "./guard-doc-status";
|
|
14
14
|
import { check as featureIntegrationTests } from "./guard-feature-integration-tests";
|
|
15
15
|
import { check as guardsDocDrift } from "./guard-guards-doc-drift";
|
|
16
|
-
import { check as noDirectProcessEnv } from "./guard-no-direct-process-env";
|
|
17
|
-
import { check as primitivesDiscipline } from "./guard-primitives-discipline";
|
|
18
16
|
import { check as rawSql } from "./guard-raw-sql";
|
|
19
17
|
import { check as rendererBoundaries } from "./guard-renderer-boundaries";
|
|
20
18
|
import { check as schemaCliFeatures } from "./guard-schema-cli-features";
|
|
21
19
|
import { check as testStackDrift } from "./guard-test-stack-drift";
|
|
22
|
-
import { check as thinWrappers } from "./guard-thin-wrappers";
|
|
23
20
|
import { check as unsafeArrayParam } from "./guard-unsafe-array-param";
|
|
24
21
|
import { check as upgradeState } from "./guard-upgrade-state";
|
|
25
22
|
|
|
26
23
|
export const REPO_CHECKS = [
|
|
27
24
|
rawSql,
|
|
28
|
-
noDirectProcessEnv,
|
|
29
25
|
rendererBoundaries,
|
|
30
|
-
primitivesDiscipline,
|
|
31
|
-
thinWrappers,
|
|
32
26
|
secretLiterals,
|
|
33
27
|
featureIntegrationTests,
|
|
34
28
|
testStackDrift,
|
|
@@ -35,10 +35,10 @@ export function parseStepArgs(argv: readonly string[]): ParsedArgs {
|
|
|
35
35
|
return { failPrefix, lanes };
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
const MIN_POOL =
|
|
38
|
+
// The pool follows the free capacity (cores minus 1-min load). The floor stays small
|
|
39
|
+
// because the test lane already fans out into its own workers; several pushes at once
|
|
40
|
+
// must not each claim four more lanes on a saturated machine.
|
|
41
|
+
const MIN_POOL = 2;
|
|
42
42
|
|
|
43
43
|
export function resolvePoolSize(
|
|
44
44
|
override: string | undefined,
|
package/src/run-ui-guards.ts
CHANGED
|
@@ -9,24 +9,10 @@ import {
|
|
|
9
9
|
runGuards,
|
|
10
10
|
} from "./_lib/guard-kit";
|
|
11
11
|
import { guard as i18nUiStrings } from "./guard-i18n-ui-strings";
|
|
12
|
-
import { guard as noCustomPrimitives } from "./guard-no-custom-primitives";
|
|
13
12
|
import { guard as noFramedExtensionSections } from "./guard-no-framed-extension-sections";
|
|
14
|
-
import { guard as noInlineStyles } from "./guard-no-inline-styles";
|
|
15
|
-
import { guard as noRawHooks } from "./guard-no-raw-hooks";
|
|
16
|
-
import { guard as rawClassname } from "./guard-raw-classname";
|
|
17
|
-
import { guard as rawInteractiveElements } from "./guard-raw-interactive-elements";
|
|
18
13
|
import { guard as tailwindScanSurface } from "./guard-tailwind-scan-surface";
|
|
19
14
|
|
|
20
|
-
export const UI_GUARDS = [
|
|
21
|
-
rawClassname,
|
|
22
|
-
noInlineStyles,
|
|
23
|
-
noCustomPrimitives,
|
|
24
|
-
noFramedExtensionSections,
|
|
25
|
-
noRawHooks,
|
|
26
|
-
tailwindScanSurface,
|
|
27
|
-
rawInteractiveElements,
|
|
28
|
-
i18nUiStrings,
|
|
29
|
-
];
|
|
15
|
+
export const UI_GUARDS = [noFramedExtensionSections, tailwindScanSurface, i18nUiStrings];
|
|
30
16
|
|
|
31
17
|
// No flags today — the array stays so an unknown flag still fails loud
|
|
32
18
|
// instead of silently doing nothing, and so a future flag has one place to land.
|