@synopackageland/cli 0.53.5 → 0.53.7
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/CHANGELOG.md +15 -0
- package/dist/ctl/ai-tools.d.ts +15 -2
- package/dist/ctl/ai-tools.js +9 -2
- package/dist/ctl/cli.js +4 -3
- package/dist/ctl/generate.js +1 -1
- package/dist/ctl/operation-semantics.d.ts +51 -0
- package/dist/ctl/operation-semantics.js +85 -0
- package/dist/ctl/registry.d.ts +19 -4
- package/dist/ctl/registry.js +33 -4
- package/dist/error-registry.js +1 -0
- package/dist/spk/check-payload.js +17 -3
- package/dist/spk/rules.d.ts +1 -1
- package/dist/spk/rules.js +1 -1
- package/dist/standalone/manifest.d.ts +1 -0
- package/dist/standalone/manifest.js +4 -0
- package/dist/standalone/native-layout.js +4 -4
- package/dist/standalone/operation-registry.d.ts +8 -1
- package/dist/standalone/operation-registry.js +10 -1
- package/dist/standalone/public-ui.d.ts +49 -3
- package/dist/standalone/public-ui.js +190 -30
- package/dist/standalone/spk.js +5 -4
- package/dist/validate.js +39 -5
- package/package.json +1 -1
- package/schema/dsm-package.schema.json +9 -3
- package/schema/synopkgland-api-v2.schema.json +103 -0
- package/skills/reference/ctl.md +23 -3
- package/skills/reference/ui-vue.md +13 -6
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
export interface UiSecretIgnore {
|
|
2
2
|
file: string;
|
|
3
3
|
reason: string;
|
|
4
|
+
match?: string[];
|
|
4
5
|
}
|
|
6
|
+
/** A build-time ignore after `[hash]` resolution; `pattern` is set only for placeholder entries. */
|
|
7
|
+
export interface ResolvedUiSecretIgnore extends UiSecretIgnore {
|
|
8
|
+
pattern?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* `matches` holds the exact flagged text, for patterns that flag text. It can be a
|
|
12
|
+
* credential: print it only through showUiMatch and only for the developer's own project.
|
|
13
|
+
*/
|
|
5
14
|
export interface UiProblem {
|
|
6
15
|
file: string;
|
|
7
16
|
pattern: string;
|
|
17
|
+
matches?: string[];
|
|
8
18
|
ignored?: string;
|
|
19
|
+
ignoredBy?: string;
|
|
9
20
|
}
|
|
10
21
|
export interface PublicUiReport {
|
|
11
22
|
/** A whitespace heuristic, not a claim that source code is confidential. */
|
|
@@ -15,7 +26,16 @@ export interface PublicUiReport {
|
|
|
15
26
|
unminified: string[];
|
|
16
27
|
sourceMaps: string[];
|
|
17
28
|
}
|
|
29
|
+
/** One bundler content-hash token; it never crosses `/` and admits no other glob syntax. */
|
|
30
|
+
export declare const UI_HASH_TOKEN = "[hash]";
|
|
18
31
|
export declare function readUiSecretIgnores(value: unknown): UiSecretIgnore[];
|
|
32
|
+
/**
|
|
33
|
+
* Resolve ignores against logical UI files. A `[hash]` entry must match exactly one
|
|
34
|
+
* file. With `requireMatch`, every entry must match; ambiguity always fails.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveUiSecretIgnores(files: Iterable<string>, ignores: UiSecretIgnore[], requireMatch?: boolean): ResolvedUiSecretIgnore[];
|
|
37
|
+
/** The form recorded in build metadata: resolved exact files, never `[hash]`. */
|
|
38
|
+
export declare function storedUiSecretIgnores(ignores: ResolvedUiSecretIgnore[]): UiSecretIgnore[];
|
|
19
39
|
export declare function isUiBundle(file: string): boolean;
|
|
20
40
|
/** No format conversion or property mangling: classic globals and ESM exports stay public. */
|
|
21
41
|
export declare function minifyUi(content: string, file: string): string;
|
|
@@ -24,9 +44,35 @@ export declare function uiFiles(root: string): string[];
|
|
|
24
44
|
export declare function minifyUiTree(root: string, skip?: string[]): void;
|
|
25
45
|
export declare function uiFileProblems(file: string, input: string | Buffer): UiProblem[];
|
|
26
46
|
export declare function logicalUiFile(file: string, moduleVersion?: string): string;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
47
|
+
/**
|
|
48
|
+
* `ignores` must already be resolved to exact logical files (see resolveUiSecretIgnores).
|
|
49
|
+
* An entry with `match` exempts only hits whose text it lists; an unexempted problem
|
|
50
|
+
* keeps only its unlisted matches.
|
|
51
|
+
*/
|
|
52
|
+
export declare function applyUiIgnores(problems: UiProblem[], ignores: ResolvedUiSecretIgnore[], moduleVersion?: string): UiProblem[];
|
|
53
|
+
export interface StaleUiIgnore {
|
|
54
|
+
file: string;
|
|
55
|
+
entry: string;
|
|
56
|
+
match: string;
|
|
57
|
+
}
|
|
58
|
+
/** Listed `match` texts that no longer occur in their file, so ignore lists cannot rot. */
|
|
59
|
+
export declare function staleUiIgnores(problems: UiProblem[], ignores: ResolvedUiSecretIgnore[], moduleVersion?: string): StaleUiIgnore[];
|
|
60
|
+
/**
|
|
61
|
+
* Display form of flagged text: truncated, and redacted when it looks like a real
|
|
62
|
+
* token signature. Use only for the developer's own project (build, check).
|
|
63
|
+
*/
|
|
64
|
+
export declare function showUiMatch(text: string, limit?: number): string;
|
|
65
|
+
/** A logical file with a bundler-looking hash (Name-AbCd1234.js) becomes Name-[hash].js. */
|
|
66
|
+
export declare function suggestUiIgnoreFile(file: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* A ready-to-paste ui_secret_ignores block for reviewed false positives. Texts that
|
|
69
|
+
* look like real tokens or exceed 200 characters are left for the developer to copy.
|
|
70
|
+
*/
|
|
71
|
+
export declare function uiIgnoreSuggestion(problems: UiProblem[], moduleVersion?: string): string;
|
|
72
|
+
export declare function describeUiProblem(problem: UiProblem): string;
|
|
73
|
+
export declare function scanUiTree(root: string, ignores?: ResolvedUiSecretIgnore[], moduleVersion?: string, packed?: boolean): UiProblem[];
|
|
74
|
+
/** Returns the resolved ignores; record them with storedUiSecretIgnores. */
|
|
75
|
+
export declare function enforcePublicUi(root: string, ignores?: UiSecretIgnore[], moduleVersion?: string): ResolvedUiSecretIgnore[];
|
|
30
76
|
export declare function publicUiReport(files: Array<{
|
|
31
77
|
file: string;
|
|
32
78
|
content: string;
|
|
@@ -2,21 +2,72 @@ import { existsSync, lstatSync, readFileSync, readdirSync, rmSync, writeFileSync
|
|
|
2
2
|
import { basename, extname, join } from "node:path";
|
|
3
3
|
import { transformSync } from "esbuild";
|
|
4
4
|
import { readAllowedSecretFiles } from "../secret-files.js";
|
|
5
|
+
/** One bundler content-hash token; it never crosses `/` and admits no other glob syntax. */
|
|
6
|
+
export const UI_HASH_TOKEN = "[hash]";
|
|
7
|
+
const UI_HASH_CHARS = "[A-Za-z0-9_-]{6,64}";
|
|
8
|
+
const SOURCE_MAP_PATTERNS = ["source-map-file", "sourceMappingURL"];
|
|
9
|
+
function hashPattern(file) {
|
|
10
|
+
const at = file.indexOf(UI_HASH_TOKEN);
|
|
11
|
+
if (at < 0)
|
|
12
|
+
return undefined;
|
|
13
|
+
const quote = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
14
|
+
return new RegExp(`^${quote(file.slice(0, at))}${UI_HASH_CHARS}${quote(file.slice(at + UI_HASH_TOKEN.length))}$`);
|
|
15
|
+
}
|
|
5
16
|
export function readUiSecretIgnores(value) {
|
|
6
17
|
if (value === undefined)
|
|
7
18
|
return [];
|
|
8
|
-
const invalid = () => Object.assign(new Error("ui_secret_ignores must be an array of {file, reason}; file is an exact path relative to ui/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
typeof item
|
|
19
|
+
const invalid = () => Object.assign(new Error("ui_secret_ignores must be an array of {file, reason, match}; file is an exact path relative to ui/, optionally with one [hash] for a bundler content hash (app/chunks/Dialog-[hash].js); reason must be nonempty; match is the exact flagged text (or a list of them), required with [hash]. Module snapshot hashes are omitted (app/file.js)."), { code: "UI_SECRET_IGNORES_INVALID" });
|
|
20
|
+
const matches = (item) => item.match === undefined ? undefined : Array.isArray(item.match) ? item.match : [item.match];
|
|
21
|
+
if (!Array.isArray(value) || value.some(item => {
|
|
22
|
+
if (!item || typeof item !== "object" || Array.isArray(item) ||
|
|
23
|
+
Object.keys(item).some(key => !["file", "reason", "match"].includes(key)) || typeof item.file !== "string" ||
|
|
24
|
+
typeof item.reason !== "string" || !item.reason.trim() || /[\x00-\x1f\x7f]/.test(item.reason))
|
|
25
|
+
return true;
|
|
26
|
+
const match = matches(item);
|
|
27
|
+
// Without match, a [hash] entry would silently exempt new hits in a changed chunk.
|
|
28
|
+
if (match === undefined)
|
|
29
|
+
return item.file.includes(UI_HASH_TOKEN);
|
|
30
|
+
return !match.length || new Set(match).size !== match.length ||
|
|
31
|
+
match.some(text => typeof text !== "string" || !text || text.length > 4096);
|
|
32
|
+
}))
|
|
12
33
|
throw invalid();
|
|
34
|
+
// Replace one token with an inert character so the exact-path rules still reject
|
|
35
|
+
// any further brackets, globs, separators inside it and dot segments.
|
|
13
36
|
try {
|
|
14
|
-
readAllowedSecretFiles(value.map(item => item.file));
|
|
37
|
+
readAllowedSecretFiles(value.map(item => item.file.replace(UI_HASH_TOKEN, "")));
|
|
15
38
|
}
|
|
16
39
|
catch {
|
|
17
40
|
throw invalid();
|
|
18
41
|
}
|
|
19
|
-
return value.map(item => ({ file: item.file, reason: item.reason.trim() }));
|
|
42
|
+
return value.map(item => ({ file: item.file, reason: item.reason.trim(), ...(matches(item) ? { match: [...matches(item)] } : {}) }));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Resolve ignores against logical UI files. A `[hash]` entry must match exactly one
|
|
46
|
+
* file. With `requireMatch`, every entry must match; ambiguity always fails.
|
|
47
|
+
*/
|
|
48
|
+
export function resolveUiSecretIgnores(files, ignores, requireMatch = true) {
|
|
49
|
+
const list = [...files];
|
|
50
|
+
const present = new Set(list);
|
|
51
|
+
const resolved = [];
|
|
52
|
+
for (const ignore of ignores) {
|
|
53
|
+
const match = hashPattern(ignore.file);
|
|
54
|
+
const found = match ? list.filter(file => match.test(file)) : present.has(ignore.file) ? [ignore.file] : [];
|
|
55
|
+
if (found.length > 1)
|
|
56
|
+
throw Object.assign(new Error(`ui_secret_ignores ui/${ignore.file} matches ${found.length} files; it must match exactly one: ${found.map(file => `ui/${file}`).join(", ")}`), { code: "UI_SECRET_IGNORE_AMBIGUOUS" });
|
|
57
|
+
if (!found.length) {
|
|
58
|
+
if (requireMatch)
|
|
59
|
+
throw Object.assign(new Error(match ? `ui_secret_ignores ui/${ignore.file} matches no file` : `ui_secret_ignores file does not exist: ui/${ignore.file}`), { code: "UI_SECRET_IGNORE_MISSING" });
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
resolved.push({ ...ignore, file: found[0], ...(match ? { pattern: ignore.file } : {}) });
|
|
63
|
+
}
|
|
64
|
+
if (new Set(resolved.map(item => item.file)).size !== resolved.length)
|
|
65
|
+
throw Object.assign(new Error("ui_secret_ignores lists the same UI file more than once; keep one entry per file."), { code: "UI_SECRET_IGNORE_AMBIGUOUS" });
|
|
66
|
+
return resolved;
|
|
67
|
+
}
|
|
68
|
+
/** The form recorded in build metadata: resolved exact files, never `[hash]`. */
|
|
69
|
+
export function storedUiSecretIgnores(ignores) {
|
|
70
|
+
return ignores.map(({ file, reason, match }) => ({ file, reason, ...(match ? { match } : {}) }));
|
|
20
71
|
}
|
|
21
72
|
export function isUiBundle(file) {
|
|
22
73
|
return [".js", ".mjs", ".cjs", ".css"].includes(extname(file).toLowerCase());
|
|
@@ -105,7 +156,8 @@ const PASSWORD_CAPTIONS = new Set([
|
|
|
105
156
|
"passwort", "benutzerpasswort", "mot de passe", "mot de passe utilisateur",
|
|
106
157
|
"contraseña", "contraseña de usuario", "password utente",
|
|
107
158
|
]);
|
|
108
|
-
function
|
|
159
|
+
function credentialLiterals(content, bundle) {
|
|
160
|
+
const found = [];
|
|
109
161
|
const literals = /(?:^|[,{])\s*(?:"(password|secret)"|'(password|secret)'|(password|secret))\s*:\s*(?:"([^"\r\n]+)"|'([^'\r\n]+)'|`([^`$\r\n]+)`|(\d+(?:\.\d+)?)\b)/gi;
|
|
110
162
|
for (const match of content.matchAll(literals)) {
|
|
111
163
|
const key = match[1] ?? match[2] ?? match[3];
|
|
@@ -113,10 +165,19 @@ function credentialLiteral(content) {
|
|
|
113
165
|
const caption = value.replace(/\\(?:u([0-9a-f]{4})|x([0-9a-f]{2}))/gi, (_escape, unicode, hex) => String.fromCharCode(parseInt(unicode ?? hex, 16))).toLowerCase();
|
|
114
166
|
if (key.toLowerCase() === "password" && PASSWORD_CAPTIONS.has(caption))
|
|
115
167
|
continue;
|
|
116
|
-
|
|
168
|
+
found.push(match[0].replace(/^[,{]?\s*/, ""));
|
|
117
169
|
}
|
|
118
|
-
|
|
170
|
+
const assignments = /(?<![\w$"'`])(?:password|secret)\s*=\s*(?:"[^"\r\n]+"|'[^'\r\n]+'|`[^`$\r\n]+`|\d+(?:\.\d+)?\b)|["'`](?:password|secret)=[^"'`\s]+/gi;
|
|
171
|
+
for (const match of content.matchAll(assignments))
|
|
172
|
+
found.push(match[0]);
|
|
173
|
+
// Unquoted values in environment/config/HTML text; JS variable assignments are not literals.
|
|
174
|
+
if (!bundle)
|
|
175
|
+
for (const match of content.matchAll(/(?<![\w$])(?:password|secret)\s*=\s*[^\s"'`<>{};,]+/gi))
|
|
176
|
+
found.push(match[0]);
|
|
177
|
+
return found;
|
|
119
178
|
}
|
|
179
|
+
const unique = (items) => [...new Set(items)];
|
|
180
|
+
const allMatches = (pattern, content) => unique([...content.matchAll(new RegExp(pattern.source, pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`))].map(match => match[0]));
|
|
120
181
|
export function uiFileProblems(file, input) {
|
|
121
182
|
const executable = Buffer.isBuffer(input) && isExecutable(input);
|
|
122
183
|
const content = typeof input === "string" ? input : input.toString(executable ? "latin1" : "utf8");
|
|
@@ -128,45 +189,144 @@ export function uiFileProblems(file, input) {
|
|
|
128
189
|
found.push({ file, pattern: "source-map-file" });
|
|
129
190
|
if (SOURCE_MAP_COMMENT.test(content))
|
|
130
191
|
found.push({ file, pattern: "sourceMappingURL" });
|
|
131
|
-
for (const [pattern, match] of executable ? BINARY_SECRET_PATTERNS : SECRET_PATTERNS)
|
|
132
|
-
|
|
133
|
-
|
|
192
|
+
for (const [pattern, match] of executable ? BINARY_SECRET_PATTERNS : SECRET_PATTERNS) {
|
|
193
|
+
const matches = allMatches(match, content);
|
|
194
|
+
if (matches.length)
|
|
195
|
+
found.push({ file, pattern, matches });
|
|
196
|
+
}
|
|
134
197
|
// Source syntax has no reliable meaning in machine code or pooled constants.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (!executable && !isUiBundle(file) && /(?:^|[^\w$])(?:password|secret)\s*=\s*[^\s"'`<>{};,]+/i.test(content))
|
|
139
|
-
if (!found.some(item => item.pattern === "credential-literal"))
|
|
140
|
-
found.push({ file, pattern: "credential-literal" });
|
|
198
|
+
const literals = executable ? [] : unique(credentialLiterals(content, isUiBundle(file)));
|
|
199
|
+
if (literals.length)
|
|
200
|
+
found.push({ file, pattern: "credential-literal", matches: literals });
|
|
141
201
|
return found;
|
|
142
202
|
}
|
|
143
203
|
export function logicalUiFile(file, moduleVersion) {
|
|
144
204
|
const prefix = moduleVersion ? `app/${moduleVersion}/` : "";
|
|
145
205
|
return prefix && file.startsWith(prefix) ? `app/${file.slice(prefix.length)}` : file;
|
|
146
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* `ignores` must already be resolved to exact logical files (see resolveUiSecretIgnores).
|
|
209
|
+
* An entry with `match` exempts only hits whose text it lists; an unexempted problem
|
|
210
|
+
* keeps only its unlisted matches.
|
|
211
|
+
*/
|
|
147
212
|
export function applyUiIgnores(problems, ignores, moduleVersion) {
|
|
148
213
|
return problems.map(problem => {
|
|
149
214
|
// Source maps are never exempted by a secret-scan exception.
|
|
150
|
-
const ignore = !
|
|
215
|
+
const ignore = !SOURCE_MAP_PATTERNS.includes(problem.pattern) &&
|
|
151
216
|
ignores.find(item => item.file === logicalUiFile(problem.file, moduleVersion));
|
|
152
|
-
|
|
217
|
+
if (!ignore)
|
|
218
|
+
return problem;
|
|
219
|
+
if (ignore.match) {
|
|
220
|
+
const listed = new Set(ignore.match);
|
|
221
|
+
// A file-level hit (no text) cannot be exempted by a text match.
|
|
222
|
+
if (!problem.matches)
|
|
223
|
+
return problem;
|
|
224
|
+
const unlisted = problem.matches.filter(text => !listed.has(text));
|
|
225
|
+
if (unlisted.length)
|
|
226
|
+
return { ...problem, matches: unlisted };
|
|
227
|
+
}
|
|
228
|
+
return { ...problem, ignored: ignore.reason, ...(ignore.pattern ? { ignoredBy: ignore.pattern } : {}) };
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
/** Listed `match` texts that no longer occur in their file, so ignore lists cannot rot. */
|
|
232
|
+
export function staleUiIgnores(problems, ignores, moduleVersion) {
|
|
233
|
+
return ignores.flatMap(ignore => {
|
|
234
|
+
if (!ignore.match)
|
|
235
|
+
return [];
|
|
236
|
+
const occurring = new Set(problems.filter(problem => logicalUiFile(problem.file, moduleVersion) === ignore.file)
|
|
237
|
+
.flatMap(problem => problem.matches ?? []));
|
|
238
|
+
return ignore.match.filter(text => !occurring.has(text))
|
|
239
|
+
.map(match => ({ file: ignore.file, entry: ignore.pattern ?? ignore.file, match }));
|
|
153
240
|
});
|
|
154
241
|
}
|
|
155
|
-
|
|
156
|
-
|
|
242
|
+
/**
|
|
243
|
+
* Display form of flagged text: truncated, and redacted when it looks like a real
|
|
244
|
+
* token signature. Use only for the developer's own project (build, check).
|
|
245
|
+
*/
|
|
246
|
+
export function showUiMatch(text, limit = 80) {
|
|
247
|
+
if (BINARY_SECRET_PATTERNS.some(([, pattern]) => pattern.test(text)))
|
|
248
|
+
return `<redacted ${text.length} chars>`;
|
|
249
|
+
const quoted = JSON.stringify(text);
|
|
250
|
+
return quoted.length > limit ? `${quoted.slice(0, limit - 4)}..."` : quoted;
|
|
251
|
+
}
|
|
252
|
+
/** A logical file with a bundler-looking hash (Name-AbCd1234.js) becomes Name-[hash].js. */
|
|
253
|
+
export function suggestUiIgnoreFile(file) {
|
|
254
|
+
return file.replace(/^(.*\/)?([^/]*[-.])[A-Za-z0-9_-]{8}(\.[A-Za-z0-9]+)$/, (_all, dir = "", stem, ext) => `${dir}${stem}${UI_HASH_TOKEN}${ext}`);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* A ready-to-paste ui_secret_ignores block for reviewed false positives. Texts that
|
|
258
|
+
* look like real tokens or exceed 200 characters are left for the developer to copy.
|
|
259
|
+
*/
|
|
260
|
+
export function uiIgnoreSuggestion(problems, moduleVersion) {
|
|
261
|
+
const byFile = new Map();
|
|
262
|
+
const manual = new Set();
|
|
263
|
+
for (const problem of problems) {
|
|
264
|
+
if (SOURCE_MAP_PATTERNS.includes(problem.pattern) || !problem.matches)
|
|
265
|
+
continue;
|
|
266
|
+
const file = logicalUiFile(problem.file, moduleVersion);
|
|
267
|
+
const texts = byFile.get(file) ?? [];
|
|
268
|
+
for (const text of problem.matches) {
|
|
269
|
+
if (text.length > 200 || showUiMatch(text, Infinity).startsWith("<redacted"))
|
|
270
|
+
manual.add(file);
|
|
271
|
+
else
|
|
272
|
+
texts.push(text);
|
|
273
|
+
}
|
|
274
|
+
byFile.set(file, texts);
|
|
275
|
+
}
|
|
276
|
+
if (!byFile.size)
|
|
277
|
+
return "";
|
|
278
|
+
const lines = ["ui_secret_ignores:"];
|
|
279
|
+
for (const [file, texts] of byFile) {
|
|
280
|
+
lines.push(` - file: ${JSON.stringify(suggestUiIgnoreFile(file))}`, " reason: \"<why this is a false positive>\"", " match:");
|
|
281
|
+
for (const text of unique(texts))
|
|
282
|
+
lines.push(` - ${JSON.stringify(text)}`);
|
|
283
|
+
if (manual.has(file) || !texts.length)
|
|
284
|
+
lines.push(` # copy any other flagged text from ui/${file} after review`);
|
|
285
|
+
}
|
|
286
|
+
return lines.join("\n");
|
|
287
|
+
}
|
|
288
|
+
export function describeUiProblem(problem) {
|
|
289
|
+
const shown = (problem.matches ?? []).slice(0, 3).map(text => showUiMatch(text));
|
|
290
|
+
const more = (problem.matches?.length ?? 0) > 3 ? ` (+${problem.matches.length - 3} more)` : "";
|
|
291
|
+
return `ui/${problem.file}: ${problem.pattern}${shown.length ? ` ${shown.join(", ")}${more}` : ""}`;
|
|
292
|
+
}
|
|
293
|
+
/** Scan the files as build packs them: JS/CSS minified, so `match` texts agree with build. */
|
|
294
|
+
function packedUiProblems(file, bytes) {
|
|
295
|
+
if (!isUiBundle(file))
|
|
296
|
+
return uiFileProblems(file, bytes);
|
|
297
|
+
const raw = bytes.toString("utf8");
|
|
298
|
+
let packed;
|
|
299
|
+
try {
|
|
300
|
+
packed = minifyUi(raw, file);
|
|
301
|
+
}
|
|
302
|
+
catch {
|
|
303
|
+
return uiFileProblems(file, bytes);
|
|
304
|
+
}
|
|
305
|
+
// Minifying removes source-map comments; keep reporting them from the original.
|
|
306
|
+
const maps = SOURCE_MAP_COMMENT.test(raw) ? [{ file, pattern: "sourceMappingURL" }] : [];
|
|
307
|
+
return [...uiFileProblems(file, packed), ...maps];
|
|
308
|
+
}
|
|
309
|
+
export function scanUiTree(root, ignores = [], moduleVersion, packed = false) {
|
|
310
|
+
const problems = uiFiles(root).flatMap(file => (packed ? packedUiProblems : uiFileProblems)(file, readFileSync(join(root, file))));
|
|
157
311
|
return applyUiIgnores(problems, ignores, moduleVersion);
|
|
158
312
|
}
|
|
313
|
+
/** Returns the resolved ignores; record them with storedUiSecretIgnores. */
|
|
159
314
|
export function enforcePublicUi(root, ignores = [], moduleVersion) {
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
315
|
+
const resolved = resolveUiSecretIgnores(uiFiles(root).map(file => logicalUiFile(file, moduleVersion)), ignores);
|
|
316
|
+
const raw = scanUiTree(root, [], moduleVersion);
|
|
317
|
+
const stale = staleUiIgnores(raw, resolved, moduleVersion);
|
|
318
|
+
if (stale.length)
|
|
319
|
+
throw Object.assign(new Error(stale.map(item => `ui_secret_ignores ui/${item.entry} match ${showUiMatch(item.match)} no longer occurs in ui/${item.file}`).join("\n")), { code: "UI_SECRET_IGNORE_STALE", hint: "Remove the stale match (or the whole entry) after reviewing the file again." });
|
|
320
|
+
const problems = applyUiIgnores(raw, resolved, moduleVersion);
|
|
165
321
|
for (const problem of problems.filter(item => item.ignored))
|
|
166
|
-
console.warn(`[UI_SECRET_IGNORED] ui/${problem.file}: ${problem.pattern}; reason: ${problem.ignored}`);
|
|
322
|
+
console.warn(`[UI_SECRET_IGNORED] ui/${problem.file}: ${problem.pattern}; ${problem.ignoredBy ? `matched ui/${problem.ignoredBy}; ` : ""}reason: ${problem.ignored}`);
|
|
167
323
|
const errors = problems.filter(item => !item.ignored);
|
|
168
|
-
if (errors.length)
|
|
169
|
-
|
|
324
|
+
if (errors.length) {
|
|
325
|
+
const paste = uiIgnoreSuggestion(errors, moduleVersion);
|
|
326
|
+
throw Object.assign(new Error(errors.map(describeUiProblem).join("\n") +
|
|
327
|
+
(paste ? `\nOnly if every hit is a reviewed false positive, add to dsm-package.yaml:\n${paste}` : "")), { code: "PUBLIC_UI_UNSAFE", hint: "Files under ui/ are public. Remove credentials and source maps; only false positives may use ui_secret_ignores with a reason and match." });
|
|
328
|
+
}
|
|
329
|
+
return resolved;
|
|
170
330
|
}
|
|
171
331
|
export function publicUiReport(files) {
|
|
172
332
|
const bundles = files.filter(item => isUiBundle(item.file));
|
package/dist/standalone/spk.js
CHANGED
|
@@ -29,7 +29,7 @@ import { createReproducibleTar } from "../build-spk/reproducible-archive.js";
|
|
|
29
29
|
import { renderStandaloneScript } from "./lifecycle.js";
|
|
30
30
|
import { APP_SCRIPTS_DIR, APP_SCRIPTS_SPK_DIR } from "./app-scripts.js";
|
|
31
31
|
import { MODULE_UI_ENTRY, uiTreeDigest } from "./ui-assets.js";
|
|
32
|
-
import { enforcePublicUi, isUiBundle, logicalUiFile, minifyUi, minifyUiTree, uiFiles } from "./public-ui.js";
|
|
32
|
+
import { enforcePublicUi, isUiBundle, logicalUiFile, minifyUi, minifyUiTree, storedUiSecretIgnores, uiFiles } from "./public-ui.js";
|
|
33
33
|
import { codedMessage } from "../errors.js";
|
|
34
34
|
import { DSM_LANGS, LOCALES } from "./i18n.js";
|
|
35
35
|
import { appTitle, CGI_PAYLOAD_PATH, hasSdkWindow, renderUiConfig, renderWindowScript, windowScriptName, } from "./dsm-window.js";
|
|
@@ -285,8 +285,8 @@ export async function assembleStandaloneSpk(options) {
|
|
|
285
285
|
}
|
|
286
286
|
writeFileSync(file, JSON.stringify(ports, null, 2) + "\n");
|
|
287
287
|
}
|
|
288
|
-
enforcePublicUi(uiRoot, manifest.uiSecretIgnores, moduleVersion);
|
|
289
|
-
const ignoredUi = uiFiles(uiRoot).filter(file =>
|
|
288
|
+
const uiIgnores = enforcePublicUi(uiRoot, manifest.uiSecretIgnores, moduleVersion);
|
|
289
|
+
const ignoredUi = uiFiles(uiRoot).filter(file => uiIgnores.some(ignore => ignore.file === logicalUiFile(file, moduleVersion))).map(file => `ui/${file}`);
|
|
290
290
|
const packageTgz = join(staging, "package.tgz");
|
|
291
291
|
await createReproducibleTar(join(staging, "package"), packageTgz, {
|
|
292
292
|
rejectSecrets: true,
|
|
@@ -299,7 +299,8 @@ export async function assembleStandaloneSpk(options) {
|
|
|
299
299
|
.digest("hex");
|
|
300
300
|
writeFile(join(staging, "sdk-package.json"), JSON.stringify({
|
|
301
301
|
schema: 2,
|
|
302
|
-
|
|
302
|
+
// Record resolved exact files: older CLIs reject `[hash]` when inspecting.
|
|
303
|
+
...(uiIgnores.length ? { ui_secret_ignores: storedUiSecretIgnores(uiIgnores) } : {}),
|
|
303
304
|
...(manifest.tcpListeners ? { tcp_listeners: manifest.tcpListeners } : {}),
|
|
304
305
|
...(mobile ? { mobile: mobile.record } : {}),
|
|
305
306
|
dependencies: packageDependencies(manifest),
|
package/dist/validate.js
CHANGED
|
@@ -4,11 +4,12 @@ import { existsSync } from "node:fs";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { getErrorCode } from "./error-registry.js";
|
|
6
6
|
import { loadStandaloneManifest } from "./standalone/manifest.js";
|
|
7
|
-
import { applyUiIgnores, scanUiTree } from "./standalone/public-ui.js";
|
|
7
|
+
import { applyUiIgnores, describeUiProblem, resolveUiSecretIgnores, scanUiTree, showUiMatch, staleUiIgnores, uiFiles, uiIgnoreSuggestion } from "./standalone/public-ui.js";
|
|
8
8
|
import { hasSdkWindow } from "./standalone/dsm-window.js";
|
|
9
9
|
import { uiGuidanceWarnings } from "./standalone/ui-guidance.js";
|
|
10
10
|
import { isNativeLayout, loadNativeLayout, } from "./standalone/native-layout.js";
|
|
11
11
|
import { manifestPolicyProblem } from "./runtime/executor-policy-check.js";
|
|
12
|
+
import { descriptionFindings } from "./ctl/operation-semantics.js";
|
|
12
13
|
/** All shipped Compose and native projects use the schema-2 build path. */
|
|
13
14
|
export function validateProject(project, _options = {}) {
|
|
14
15
|
const file = "dsm-package.yaml";
|
|
@@ -46,20 +47,53 @@ export function validateProject(project, _options = {}) {
|
|
|
46
47
|
const manifest = loaded.manifest;
|
|
47
48
|
if ('ui' in manifest)
|
|
48
49
|
warnings.push(...uiGuidanceWarnings(manifest));
|
|
50
|
+
const ctl = 'ctl' in manifest ? manifest.ctl : undefined;
|
|
51
|
+
if (ctl?.enabled && ctl.registry)
|
|
52
|
+
for (const finding of descriptionFindings(ctl.commands)) {
|
|
53
|
+
const item = { code: 'CTL_DESCRIPTION_QUALITY', span: { file: ctl.registry, line: 1, column: 1 }, message: finding.message,
|
|
54
|
+
suggestion: 'Write one English sentence: what the tool does and when to use it. Set ctl.descriptions: error to block builds on this.' };
|
|
55
|
+
if (ctl.descriptions === 'error')
|
|
56
|
+
problems.push(item);
|
|
57
|
+
else
|
|
58
|
+
warnings.push({ ...item, severity: 'warning' });
|
|
59
|
+
}
|
|
49
60
|
const roots = "ui" in manifest
|
|
50
61
|
? hasSdkWindow(manifest) ? [{ dir: manifest.ui.dir, prefix: "app/" }] : []
|
|
51
62
|
: manifest.arches.map(arch => ({ dir: join(manifest.root, manifest.layout.payload.replaceAll("{arch}", arch), "ui"), prefix: "" }));
|
|
52
63
|
for (const { dir, prefix } of roots) {
|
|
53
64
|
if (!existsSync(dir))
|
|
54
65
|
continue; // A build hook may not have produced its output yet.
|
|
66
|
+
let ignores;
|
|
67
|
+
try {
|
|
68
|
+
// A build hook may not have produced every file yet; only ambiguity fails here.
|
|
69
|
+
ignores = resolveUiSecretIgnores(uiFiles(dir).map(file => prefix + file), manifest.uiSecretIgnores ?? [], false);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
const code = error.code;
|
|
73
|
+
problems.push(code === "UI_SECRET_IGNORE_AMBIGUOUS"
|
|
74
|
+
? { code, span: { file: "dsm-package.yaml", line: 1, column: 1 }, message: error.message, suggestion: "Make the ui_secret_ignores entry specific enough to match exactly one file." }
|
|
75
|
+
: { code: "PUBLIC_UI_SCAN_FAILED", span: { file: "ui/", line: 1, column: 1 }, message: "Cannot read public UI files.", suggestion: "Use only readable regular files and directories." });
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
55
78
|
try {
|
|
56
|
-
|
|
57
|
-
|
|
79
|
+
// Scan JS/CSS as build packs it (minified), so printed match texts agree with build.
|
|
80
|
+
const raw = scanUiTree(dir, [], undefined, true).map(item => ({ ...item, file: prefix + item.file }));
|
|
81
|
+
for (const stale of staleUiIgnores(raw, ignores))
|
|
82
|
+
problems.push({
|
|
83
|
+
code: "UI_SECRET_IGNORE_STALE", span: { file: "dsm-package.yaml", line: 1, column: 1 },
|
|
84
|
+
message: `ui_secret_ignores ui/${stale.entry} match ${showUiMatch(stale.match)} no longer occurs in ui/${stale.file}`,
|
|
85
|
+
suggestion: "Remove the stale match (or the whole entry) after reviewing the file again.",
|
|
86
|
+
});
|
|
87
|
+
for (const item of applyUiIgnores(raw, ignores)) {
|
|
88
|
+
const paste = item.ignored ? "" : uiIgnoreSuggestion([item]);
|
|
58
89
|
const finding = {
|
|
59
90
|
code: item.ignored ? "UI_SECRET_IGNORED" : "PUBLIC_UI_UNSAFE",
|
|
60
91
|
span: { file: `ui/${item.file}`, line: 1, column: 1 },
|
|
61
|
-
message:
|
|
62
|
-
|
|
92
|
+
message: item.ignored
|
|
93
|
+
? `${item.pattern}; ${item.ignoredBy ? `matched ui/${item.ignoredBy}; ` : ""}reason: ${item.ignored}`
|
|
94
|
+
: describeUiProblem(item).slice(`ui/${item.file}: `.length),
|
|
95
|
+
suggestion: "Files under ui/ are public. Remove credentials and source maps; false positives require ui_secret_ignores with a reason and match." +
|
|
96
|
+
(paste ? ` Only if this is a reviewed false positive, add:\n${paste}` : ""),
|
|
63
97
|
};
|
|
64
98
|
if (item.ignored)
|
|
65
99
|
warnings.push(finding);
|
package/package.json
CHANGED
|
@@ -29,15 +29,21 @@
|
|
|
29
29
|
"additionalProperties": false
|
|
30
30
|
},
|
|
31
31
|
"ui_secret_ignores": {
|
|
32
|
-
"description": "False-positive exceptions for public UI secret scanning.
|
|
32
|
+
"description": "False-positive exceptions for public UI secret scanning. file is an exact path relative to ui/ (omit a module snapshot hash: app/help.json) and may contain one [hash] for a bundler content hash ([A-Za-z0-9_-]{6,64}, within one path segment) that must match exactly one file. match lists the exact flagged texts to exempt (required with [hash]); other hits in the file still fail, and a listed text that no longer occurs fails the build. Source maps cannot be ignored.",
|
|
33
33
|
"type": "array",
|
|
34
34
|
"items": {
|
|
35
35
|
"type": "object",
|
|
36
36
|
"required": ["file", "reason"],
|
|
37
37
|
"properties": {
|
|
38
|
-
"file": {"type": "string", "minLength": 1, "pattern": "^(?![\\s\\S]*(?:^|/)\\.{1,2}(?:/|$))[^/\\\\*?\\[\\]{}:\\u0000-\\u001f\\u007f]+(?:/[^/\\\\*?\\[\\]{}:\\u0000-\\u001f\\u007f]+)*$(?![\\s\\S])"},
|
|
39
|
-
"reason": {"type": "string", "pattern": "\\S"}
|
|
38
|
+
"file": {"type": "string", "minLength": 1, "pattern": "^(?![\\s\\S]*\\[hash\\][\\s\\S]*\\[hash\\])(?![\\s\\S]*(?:^|/)\\.{1,2}(?:/|$))(?:[^/\\\\*?\\[\\]{}:\\u0000-\\u001f\\u007f]|\\[hash\\])+(?:/(?:[^/\\\\*?\\[\\]{}:\\u0000-\\u001f\\u007f]|\\[hash\\])+)*$(?![\\s\\S])"},
|
|
39
|
+
"reason": {"type": "string", "pattern": "\\S"},
|
|
40
|
+
"match": {"oneOf": [
|
|
41
|
+
{"type": "string", "minLength": 1, "maxLength": 4096},
|
|
42
|
+
{"type": "array", "minItems": 1, "uniqueItems": true, "items": {"type": "string", "minLength": 1, "maxLength": 4096}}
|
|
43
|
+
]}
|
|
40
44
|
},
|
|
45
|
+
"if": {"properties": {"file": {"pattern": "\\[hash\\]"}}},
|
|
46
|
+
"then": {"required": ["match"]},
|
|
41
47
|
"additionalProperties": false
|
|
42
48
|
}
|
|
43
49
|
},
|
|
@@ -456,6 +456,9 @@
|
|
|
456
456
|
"read",
|
|
457
457
|
"preview",
|
|
458
458
|
"draft",
|
|
459
|
+
"propose",
|
|
460
|
+
"local",
|
|
461
|
+
"one-click",
|
|
459
462
|
"human-only",
|
|
460
463
|
"hidden"
|
|
461
464
|
]
|
|
@@ -490,6 +493,106 @@
|
|
|
490
493
|
"pattern": "^/"
|
|
491
494
|
}
|
|
492
495
|
}
|
|
496
|
+
},
|
|
497
|
+
"consent": {
|
|
498
|
+
"type": "object",
|
|
499
|
+
"additionalProperties": false,
|
|
500
|
+
"minProperties": 1,
|
|
501
|
+
"maxProperties": 1,
|
|
502
|
+
"properties": {
|
|
503
|
+
"category": {
|
|
504
|
+
"type": "string",
|
|
505
|
+
"pattern": "^[a-z][a-z0-9-]{0,31}$"
|
|
506
|
+
},
|
|
507
|
+
"param": {
|
|
508
|
+
"type": "string",
|
|
509
|
+
"minLength": 2,
|
|
510
|
+
"maxLength": 128,
|
|
511
|
+
"pattern": "^/"
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
"targets": {
|
|
516
|
+
"type": "object",
|
|
517
|
+
"additionalProperties": false,
|
|
518
|
+
"required": [
|
|
519
|
+
"max"
|
|
520
|
+
],
|
|
521
|
+
"properties": {
|
|
522
|
+
"max": {
|
|
523
|
+
"type": "integer",
|
|
524
|
+
"minimum": 0,
|
|
525
|
+
"maximum": 1000
|
|
526
|
+
},
|
|
527
|
+
"traceable": {
|
|
528
|
+
"type": "boolean"
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
},
|
|
532
|
+
"risk": {
|
|
533
|
+
"enum": [
|
|
534
|
+
"low",
|
|
535
|
+
"medium",
|
|
536
|
+
"high"
|
|
537
|
+
]
|
|
538
|
+
},
|
|
539
|
+
"tier": {
|
|
540
|
+
"type": "string",
|
|
541
|
+
"pattern": "^[A-Za-z0-9][A-Za-z0-9_-]{0,15}$"
|
|
542
|
+
},
|
|
543
|
+
"undo": {
|
|
544
|
+
"type": "object",
|
|
545
|
+
"additionalProperties": false,
|
|
546
|
+
"required": [
|
|
547
|
+
"method",
|
|
548
|
+
"from",
|
|
549
|
+
"param"
|
|
550
|
+
],
|
|
551
|
+
"properties": {
|
|
552
|
+
"method": {
|
|
553
|
+
"type": "string"
|
|
554
|
+
},
|
|
555
|
+
"from": {
|
|
556
|
+
"type": "string",
|
|
557
|
+
"minLength": 2,
|
|
558
|
+
"maxLength": 128,
|
|
559
|
+
"pattern": "^/"
|
|
560
|
+
},
|
|
561
|
+
"param": {
|
|
562
|
+
"type": "string",
|
|
563
|
+
"pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$"
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
},
|
|
567
|
+
"audit": {
|
|
568
|
+
"enum": [
|
|
569
|
+
"change",
|
|
570
|
+
"sensitive-read",
|
|
571
|
+
"read",
|
|
572
|
+
"none"
|
|
573
|
+
]
|
|
574
|
+
},
|
|
575
|
+
"mcp": {
|
|
576
|
+
"enum": [
|
|
577
|
+
"exposed",
|
|
578
|
+
"hidden",
|
|
579
|
+
"human-only"
|
|
580
|
+
]
|
|
581
|
+
},
|
|
582
|
+
"labels": {
|
|
583
|
+
"type": "object",
|
|
584
|
+
"maxProperties": 16,
|
|
585
|
+
"propertyNames": {
|
|
586
|
+
"pattern": "^[a-z][a-z0-9-]{0,31}$"
|
|
587
|
+
},
|
|
588
|
+
"additionalProperties": {
|
|
589
|
+
"type": "string",
|
|
590
|
+
"maxLength": 128,
|
|
591
|
+
"pattern": "^[^\\r\\n]*$"
|
|
592
|
+
}
|
|
593
|
+
},
|
|
594
|
+
"dynamicProvider": {
|
|
595
|
+
"type": "boolean"
|
|
493
596
|
}
|
|
494
597
|
},
|
|
495
598
|
"required": [
|