dealsystem 0.0.1 → 0.2.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.
Files changed (104) hide show
  1. package/README.md +64 -2
  2. package/dist/api/errors.d.ts +25 -0
  3. package/dist/api/errors.js +38 -0
  4. package/dist/api/http.d.ts +56 -0
  5. package/dist/api/http.js +406 -0
  6. package/dist/api/legal.d.ts +9 -0
  7. package/dist/api/legal.js +20 -0
  8. package/dist/api/oauth.d.ts +35 -0
  9. package/dist/api/oauth.js +113 -0
  10. package/dist/api/types.d.ts +142 -0
  11. package/dist/api/types.js +9 -0
  12. package/dist/auth/credentials.d.ts +28 -0
  13. package/dist/auth/credentials.js +96 -0
  14. package/dist/auth/session.d.ts +10 -0
  15. package/dist/auth/session.js +46 -0
  16. package/dist/bin.d.ts +2 -0
  17. package/dist/bin.js +4 -0
  18. package/dist/check/allowlist.d.ts +9 -0
  19. package/dist/check/allowlist.js +74 -0
  20. package/dist/check/catalog.d.ts +6 -0
  21. package/dist/check/catalog.js +410 -0
  22. package/dist/check/context.d.ts +79 -0
  23. package/dist/check/context.js +230 -0
  24. package/dist/check/fileset.d.ts +19 -0
  25. package/dist/check/fileset.js +91 -0
  26. package/dist/check/format.d.ts +25 -0
  27. package/dist/check/format.js +79 -0
  28. package/dist/check/index.d.ts +8 -0
  29. package/dist/check/index.js +9 -0
  30. package/dist/check/rule.d.ts +15 -0
  31. package/dist/check/rule.js +6 -0
  32. package/dist/check/rules/a11y.d.ts +3 -0
  33. package/dist/check/rules/a11y.js +433 -0
  34. package/dist/check/rules/privacy.d.ts +9 -0
  35. package/dist/check/rules/privacy.js +437 -0
  36. package/dist/check/rules/quality.d.ts +11 -0
  37. package/dist/check/rules/quality.js +451 -0
  38. package/dist/check/rules/schedule.d.ts +2 -0
  39. package/dist/check/rules/schedule.js +30 -0
  40. package/dist/check/rules/security.d.ts +18 -0
  41. package/dist/check/rules/security.js +744 -0
  42. package/dist/check/rules/structure.d.ts +2 -0
  43. package/dist/check/rules/structure.js +399 -0
  44. package/dist/check/run.d.ts +15 -0
  45. package/dist/check/run.js +147 -0
  46. package/dist/check/sdk.d.ts +56 -0
  47. package/dist/check/sdk.js +58 -0
  48. package/dist/check/types.d.ts +116 -0
  49. package/dist/check/types.js +2 -0
  50. package/dist/check/util/code.d.ts +19 -0
  51. package/dist/check/util/code.js +113 -0
  52. package/dist/check/util/color.d.ts +10 -0
  53. package/dist/check/util/color.js +53 -0
  54. package/dist/check/util/csp.d.ts +71 -0
  55. package/dist/check/util/csp.js +229 -0
  56. package/dist/check/util/html.d.ts +31 -0
  57. package/dist/check/util/html.js +65 -0
  58. package/dist/check/util/lines.d.ts +1 -0
  59. package/dist/check/util/lines.js +2 -0
  60. package/dist/check/util/literal.d.ts +1 -0
  61. package/dist/check/util/literal.js +3 -0
  62. package/dist/check/util/svelte.d.ts +42 -0
  63. package/dist/check/util/svelte.js +109 -0
  64. package/dist/cli/context.d.ts +40 -0
  65. package/dist/cli/context.js +107 -0
  66. package/dist/cli/io.d.ts +26 -0
  67. package/dist/cli/io.js +68 -0
  68. package/dist/cli/main.d.ts +24 -0
  69. package/dist/cli/main.js +269 -0
  70. package/dist/commands/check.d.ts +4 -0
  71. package/dist/commands/check.js +54 -0
  72. package/dist/commands/deploy.d.ts +20 -0
  73. package/dist/commands/deploy.js +315 -0
  74. package/dist/commands/dev.d.ts +29 -0
  75. package/dist/commands/dev.js +149 -0
  76. package/dist/commands/image.d.ts +12 -0
  77. package/dist/commands/image.js +291 -0
  78. package/dist/commands/login.d.ts +3 -0
  79. package/dist/commands/login.js +116 -0
  80. package/dist/commands/pull.d.ts +12 -0
  81. package/dist/commands/pull.js +178 -0
  82. package/dist/commands/site.d.ts +9 -0
  83. package/dist/commands/site.js +84 -0
  84. package/dist/commands/sync.d.ts +2 -0
  85. package/dist/commands/sync.js +126 -0
  86. package/dist/index.d.ts +10 -0
  87. package/dist/index.js +10 -0
  88. package/dist/project/agentFiles.d.ts +17 -0
  89. package/dist/project/agentFiles.js +156 -0
  90. package/dist/project/agentsBlock.d.ts +2 -0
  91. package/dist/project/agentsBlock.js +14 -0
  92. package/dist/project/siteConfig.d.ts +5 -0
  93. package/dist/project/siteConfig.js +35 -0
  94. package/dist/project/snapshot.d.ts +21 -0
  95. package/dist/project/snapshot.js +125 -0
  96. package/dist/project/svelteConfig.d.ts +4 -0
  97. package/dist/project/svelteConfig.js +74 -0
  98. package/dist/project/tar.d.ts +8 -0
  99. package/dist/project/tar.js +89 -0
  100. package/dist/project/untar.d.ts +27 -0
  101. package/dist/project/untar.js +232 -0
  102. package/dist/project/uploadFiles.d.ts +17 -0
  103. package/dist/project/uploadFiles.js +55 -0
  104. package/package.json +63 -7
@@ -0,0 +1,744 @@
1
+ // SEC-*: Secrets, private Umgebungsvariablen, {@html}, API-Zugriffe, CSP, eval, eigene Formulare, Einbettungen.
2
+ import ts from 'typescript';
3
+ import { routeOfSource } from '../context.js';
4
+ import { outputRule, sourceRule } from '../rule.js';
5
+ import { buildCspDirectives, externalUrl, resolveEmbedSource, scriptSourceProblem, } from '@dealsystem/site/config';
6
+ import { excerpt, findAll, isSvelteFile } from '../util/code.js';
7
+ import { COMPONENT, CSP_MODULE, DEALSYSTEM_CSP_FN, MARKER, SDK_PACKAGE } from '../sdk.js';
8
+ import { lineOf } from '../util/html.js';
9
+ import { cspAllows, cspForm, cspLooserThan, cspSourceList, declaredExternal, isValidDealsystemCall, metaCsp, SITE_API_SOURCE, sourceCsp, tighteningSeverity, unquote, } from '../util/csp.js';
10
+ import { getAttr } from '../util/svelte.js';
11
+ import { isOpaque, isPlainObject } from '../util/literal.js';
12
+ // ------------------------------------------------------------------ SEC-001
13
+ /** Erkennungsmuster für Zugangsschlüssel (Teilmenge dessen, was gitleaks auf dem Build-Host prüft). */
14
+ export const SECRET_PATTERNS = [
15
+ { name: 'DealSystem-API-Schlüssel', pattern: /\bdm_live_[0-9a-zA-Z]{16,}/g },
16
+ { name: 'DealSystem-Admin-Schlüssel', pattern: /\bdm_admin_[0-9a-zA-Z]{8,}/g },
17
+ { name: 'DealSystem-Client-Secret', pattern: /\bdm_cs_[0-9a-zA-Z]{8,}/g },
18
+ { name: 'DealSystem-Seiten-Schlüssel', pattern: /\bdms_site_[0-9A-Za-z]{8}_[A-Za-z0-9_-]{16,}/g },
19
+ { name: 'privater Schlüssel', pattern: /-----BEGIN (?:[A-Z0-9]+ )*PRIVATE KEY(?: BLOCK)?-----/g },
20
+ { name: 'AWS-Zugangsschlüssel', pattern: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g },
21
+ { name: 'Stripe-Schlüssel', pattern: /\b(?:sk|rk)_live_[0-9a-zA-Z]{20,}/g },
22
+ { name: 'GitHub-Token', pattern: /\b(?:gh[pousr]_[A-Za-z0-9]{36,}|github_pat_[A-Za-z0-9_]{40,})/g },
23
+ { name: 'Slack-Token', pattern: /\bxox[abprs]-[A-Za-z0-9-]{10,}/g },
24
+ { name: 'Google-API-Schlüssel', pattern: /\bAIza[0-9A-Za-z_-]{35}\b/g },
25
+ {
26
+ name: 'OpenAI-Schlüssel',
27
+ pattern: /\bsk-(?:proj-[A-Za-z0-9_-]{40,}|[A-Za-z0-9]{20}T3BlbkFJ[A-Za-z0-9]{20})/g,
28
+ },
29
+ { name: 'Anthropic-Schlüssel', pattern: /\bsk-ant-[A-Za-z0-9_-]{20,}/g },
30
+ { name: 'SendGrid-Schlüssel', pattern: /\bSG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}\b/g },
31
+ { name: 'Mailchimp-Schlüssel', pattern: /\b[0-9a-f]{32}-us[0-9]{1,2}\b/g },
32
+ ];
33
+ function mask(secret) {
34
+ return `${secret.slice(0, Math.min(10, Math.floor(secret.length / 2)))}…`;
35
+ }
36
+ function scanSecrets(ctx, paths) {
37
+ const out = [];
38
+ for (const path of paths) {
39
+ const text = ctx.text(path);
40
+ if (!text)
41
+ continue;
42
+ for (const { name, pattern } of SECRET_PATTERNS) {
43
+ for (const m of findAll(text, pattern, ctx.lines(path))) {
44
+ out.push({
45
+ file: path,
46
+ line: m.line,
47
+ column: m.column,
48
+ message: `In \`${path}:${m.line}\` steht ein Zugangsschlüssel (${name}, \`${mask(m.text)}\`).`,
49
+ });
50
+ }
51
+ }
52
+ }
53
+ return out;
54
+ }
55
+ const sec001Source = sourceRule('SEC-001', (ctx) =>
56
+ // Das Lockfile enthält nur Prüfsummen; Registry-Herkunft prüft DEP-002.
57
+ scanSecrets(ctx, ctx.textFiles((p) => p !== 'package-lock.json', true)));
58
+ const sec001Output = outputRule('SEC-001', (ctx) => scanSecrets(ctx, ctx.textFiles(() => true, true)));
59
+ // ------------------------------------------------------------------ SEC-002
60
+ const PRIVATE_ENV = /\$env\/(?:static|dynamic)\/private/g;
61
+ const sec002 = sourceRule('SEC-002', (ctx) => {
62
+ const out = [];
63
+ for (const path of ctx.paths()) {
64
+ const base = path.split('/').pop() ?? '';
65
+ if (base.startsWith('.env') && base !== '.env.example') {
66
+ out.push({
67
+ file: path,
68
+ message: `\`${path}\` darf nicht hochgeladen werden.`,
69
+ fix: 'Lösche die Datei. Eine statische Seite braucht keine Umgebungsvariablen mit Secrets.',
70
+ });
71
+ }
72
+ }
73
+ for (const path of ctx.codeFiles()) {
74
+ for (const m of findAll(ctx.code(path), PRIVATE_ENV, ctx.lines(path))) {
75
+ out.push({
76
+ file: path,
77
+ line: m.line,
78
+ column: m.column,
79
+ message: `\`${path}\` importiert \`${m.text}\`.`,
80
+ });
81
+ }
82
+ }
83
+ return out;
84
+ });
85
+ // ------------------------------------------------------------------ SEC-003
86
+ const sec003 = sourceRule('SEC-003', (ctx) => {
87
+ const out = [];
88
+ for (const path of ctx.svelteFiles()) {
89
+ const ast = ctx.svelte(path);
90
+ for (const tag of ast?.htmlTags ?? []) {
91
+ out.push(ctx.at(path, tag.start, `\`{@html …}\` in \`${path}\` ist nicht erlaubt (Gefahr von Cross-Site-Scripting).`));
92
+ }
93
+ }
94
+ return out;
95
+ });
96
+ // ------------------------------------------------------------------ SEC-004
97
+ const API_PATH = /['"`][^'"`\n]*\/api\/(?:site|v1|internal)\/[^'"`\n]*['"`]?/g;
98
+ const sec004 = sourceRule('SEC-004', (ctx) => {
99
+ const out = [];
100
+ for (const path of ctx.codeFiles()) {
101
+ for (const m of findAll(ctx.code(path), API_PATH, ctx.lines(path))) {
102
+ out.push({
103
+ file: path,
104
+ line: m.line,
105
+ column: m.column,
106
+ message: `\`${path}\` spricht die DealSystem-API direkt an (\`${excerpt(m.text, 60)}\`).`,
107
+ });
108
+ }
109
+ }
110
+ return out;
111
+ });
112
+ // ------------------------------------------------------------------ SEC-005
113
+ const LOOSE_SCRIPT_SOURCES = ['unsafe-inline', 'unsafe-hashes', '*', 'data:', 'http:', 'https:', 'blob:'];
114
+ /**
115
+ * Fremde Hosts, die die feste CSP der Altform (Starter bis SDK 0.1) nennen darf: Google Tag und Meta Pixel (nur
116
+ * über `<Tracking>`), die Site-API und OpenStreetMap (`<MapEmbed>`). Ab Regelsatz 3 kommen weitere Hosts nur über
117
+ * `external` in dealsystem.config.ts und `dealsystemCsp()`.
118
+ */
119
+ export const CSP_ALLOWED_HOSTS = [
120
+ 'app.dealsystem.io',
121
+ '*.dealsystem.io',
122
+ 'www.googletagmanager.com',
123
+ '*.google-analytics.com',
124
+ '*.analytics.google.com',
125
+ 'connect.facebook.net',
126
+ 'www.facebook.com',
127
+ 'www.openstreetmap.org',
128
+ ];
129
+ const HOST_CHECKED_DIRECTIVES = [
130
+ 'default-src',
131
+ 'script-src',
132
+ 'connect-src',
133
+ 'frame-src',
134
+ 'img-src',
135
+ 'style-src',
136
+ 'font-src',
137
+ 'media-src',
138
+ ];
139
+ function cspHost(source) {
140
+ const m = /^(?:https:\/\/)?((?:\*\.)?[a-z0-9.-]+\.[a-z]{2,})(?::\d+)?(?:\/.*)?$/i.exec(source);
141
+ return m?.[1]?.toLowerCase() ?? null;
142
+ }
143
+ function isAllowedCspHost(host) {
144
+ // `*.x` deckt `a.x` und `*.x`, nicht aber `x` selbst.
145
+ return CSP_ALLOWED_HOSTS.some((h) => h === host || (h.startsWith('*.') && host.endsWith(h.slice(1))));
146
+ }
147
+ const FIX_CSP = "Schreibe in svelte.config.js `csp: dealsystemCsp()` mit `import { dealsystemCsp } from '@dealsystem/site/csp'` (oder `npx dealsystem sync --fix-config`) und trage fremde Hosts unter `external` in dealsystem.config.ts ein (extern.md).";
148
+ /** Probleme in `external` (dealsystem.config.ts): Sie bestimmen die Sicherheitsregeln, daher SEC-005. */
149
+ function externalConfigFindings(ctx) {
150
+ return ctx
151
+ .siteConfig()
152
+ .problems.filter((p) => p.kind === 'external')
153
+ .map((p) => ({
154
+ file: 'dealsystem.config.ts',
155
+ line: p.line,
156
+ message: `${p.path}: ${p.message}`,
157
+ fix: p.fix ?? 'Korrigiere den Eintrag unter `external` in dealsystem.config.ts. Anleitung: extern.md.',
158
+ }));
159
+ }
160
+ const sec005 = sourceRule('SEC-005', (ctx) => {
161
+ const out = externalConfigFindings(ctx);
162
+ const form = cspForm(ctx);
163
+ if (!form)
164
+ return out; // STR-001 meldet die fehlende Datei.
165
+ const { path, mod } = form;
166
+ const problem = (message, line, fix) => ({
167
+ file: path,
168
+ line: line ?? null,
169
+ message,
170
+ ...(fix ? { fix } : {}),
171
+ });
172
+ if (form.kind === 'dealsystem') {
173
+ if ((form.call.args?.length ?? 0) > 0) {
174
+ out.push(problem('`dealsystemCsp()` nimmt keine Argumente. Fremde Hosts gehören unter `external` in dealsystem.config.ts.', form.call.line));
175
+ }
176
+ if (!isValidDealsystemCall(form) && mod.imports.get(DEALSYSTEM_CSP_FN) !== CSP_MODULE) {
177
+ out.push(problem(`\`${DEALSYSTEM_CSP_FN}\` kommt nicht aus \`${CSP_MODULE}\`.`, form.call.line, `Schreibe \`import { dealsystemCsp } from '${CSP_MODULE}'\`.`));
178
+ }
179
+ // Neben der Konfiguration darf svelte.config.js nichts ausführen: Eine nachträgliche Änderung der CSP
180
+ // (`config.kit.csp.directives[…].push(…)`) oder ein Ordnerwechsel sähe die statische Prüfung sonst nicht.
181
+ for (const stmt of mod.source.statements) {
182
+ const ok = ts.isImportDeclaration(stmt) ||
183
+ ts.isVariableStatement(stmt) ||
184
+ ts.isExportAssignment(stmt) ||
185
+ ts.isFunctionDeclaration(stmt) ||
186
+ ts.isTypeAliasDeclaration(stmt) ||
187
+ ts.isInterfaceDeclaration(stmt) ||
188
+ ts.isEmptyStatement(stmt);
189
+ if (!ok) {
190
+ out.push(problem(`svelte.config.js führt eigenen Code aus (\`${excerpt(stmt.getText(mod.source), 60)}\`). Neben der Konfiguration ist nichts erlaubt.`, mod.lines.at(stmt.getStart(mod.source)).line, 'Entferne die Anweisung oder stelle die Datei mit `npx dealsystem sync --fix-config` wieder her.'));
191
+ }
192
+ }
193
+ return out;
194
+ }
195
+ if (form.kind === 'other') {
196
+ if (isOpaque(form.csp)) {
197
+ out.push(problem(`\`kit.csp\` ist \`${form.csp.text.slice(0, 60)}\`. Erlaubt ist nur \`dealsystemCsp()\` oder die feste Liste des Starters.`, form.csp.line, FIX_CSP));
198
+ }
199
+ else
200
+ out.push(problem('In svelte.config.js fehlt `kit.csp` (Content-Security-Policy).', null, FIX_CSP));
201
+ return out;
202
+ }
203
+ // Altform: feste Liste wie im Starter bis SDK 0.1. Bleibt gültig, öffnet aber keine fremden Hosts.
204
+ const csp = form.csp;
205
+ if (csp.mode !== 'hash') {
206
+ out.push(problem(`\`kit.csp.mode\` muss \`'hash'\` sein, ist \`${isOpaque(csp.mode) ? csp.mode.text : String(csp.mode)}\`.`));
207
+ return out;
208
+ }
209
+ const directives = csp.directives;
210
+ if (!isPlainObject(directives)) {
211
+ out.push(problem('`kit.csp.directives` fehlt oder ist kein festes Objekt.'));
212
+ return out;
213
+ }
214
+ const list = (v) => cspSourceList(mod, v)?.map(unquote) ?? null;
215
+ for (const [name, value] of Object.entries(directives)) {
216
+ const values = list(value);
217
+ if (values === null) {
218
+ out.push(problem(`\`kit.csp.directives['${name}']\` muss eine feste Liste sein.`));
219
+ continue;
220
+ }
221
+ if (values.includes('unsafe-eval') || values.includes('wasm-unsafe-eval')) {
222
+ out.push(problem(`\`${name}\` erlaubt \`unsafe-eval\`.`));
223
+ }
224
+ if (!HOST_CHECKED_DIRECTIVES.includes(name))
225
+ continue;
226
+ for (const source of values) {
227
+ const host = cspHost(source);
228
+ if (host && !isAllowedCspHost(host)) {
229
+ out.push(problem(`\`${name}\` erlaubt den fremden Host \`${source}\`.`, null, FIX_CSP));
230
+ }
231
+ }
232
+ }
233
+ const scriptKey = directives['script-src'] !== undefined ? 'script-src' : 'default-src';
234
+ const script = list(directives[scriptKey] ?? null);
235
+ if (!script) {
236
+ out.push(problem('In `kit.csp.directives` fehlt `script-src`.'));
237
+ }
238
+ else {
239
+ for (const loose of LOOSE_SCRIPT_SOURCES) {
240
+ if (script.includes(loose))
241
+ out.push(problem(`\`${scriptKey}\` ist gelockert: \`${loose}\`.`));
242
+ }
243
+ }
244
+ if (declaredExternal(ctx).length > 0) {
245
+ out.push(problem('dealsystem.config.ts nennt fremde Dienste unter `external`, aber svelte.config.js hat noch die feste Liste. Die Dienste blieben gesperrt.', null, "Schreibe `csp: dealsystemCsp()` mit `import { dealsystemCsp } from '@dealsystem/site/csp'` oder führe `npx dealsystem sync --fix-config` aus."));
246
+ }
247
+ return out;
248
+ });
249
+ // ------------------------------------------------------------------ SEC-006
250
+ const DYNAMIC_CODE = [
251
+ { pattern: /\beval\s*\(/g, label: 'eval()' },
252
+ { pattern: /\bnew\s+Function\s*\(/g, label: 'new Function()' },
253
+ { pattern: /\b(?:setTimeout|setInterval)\s*\(\s*['"`]/g, label: 'setTimeout/setInterval mit Zeichenkette' },
254
+ { pattern: /\.setAttribute\s*\(\s*['"`]on[a-z]+['"`]/g, label: 'Event-Handler als Attribut' },
255
+ // Regelsatz 3: ohne `wasm-unsafe-eval` läuft keine WebAssembly (sperrt die gängigen Krypto-Miner).
256
+ {
257
+ pattern: /\bWebAssembly\.(?:instantiate|instantiateStreaming|compile|compileStreaming|Module|Instance)\b/g,
258
+ label: 'WebAssembly',
259
+ tightened: true,
260
+ },
261
+ { pattern: /['"`]wasm-unsafe-eval['"`]/g, label: '`wasm-unsafe-eval`', tightened: true },
262
+ ];
263
+ const INLINE_HANDLER_HTML = /<[a-z][^>]*\son[a-z]+\s*=\s*["'][^"']*["']/gi;
264
+ /** Datenblöcke führen nichts aus und unterliegen nicht `script-src` (z. B. strukturierte Daten für Google). */
265
+ const DATA_SCRIPT_TYPES = ['application/ld+json', 'application/json', 'importmap'];
266
+ const INLINE_SCRIPT_HTML = /<script\b([^>]*)>/gi;
267
+ const INLINE_FIX = 'Lege den Code als Datei in `static/scripts/` ab und lade sie mit `<ExternalScript id="…" src="/scripts/datei.js" />` (extern.md), oder schreibe ihn als Svelte-Code in die Komponente.';
268
+ const sec006 = sourceRule('SEC-006', (ctx) => {
269
+ const out = [];
270
+ const tightened = tighteningSeverity(ctx);
271
+ for (const path of ctx.codeFiles()) {
272
+ for (const { pattern, label, tightened: isNew } of DYNAMIC_CODE) {
273
+ for (const m of findAll(ctx.code(path), pattern, ctx.lines(path))) {
274
+ out.push({
275
+ file: path,
276
+ line: m.line,
277
+ column: m.column,
278
+ message: `\`${path}\` nutzt ${label}.`,
279
+ ...(isNew ? { severity: tightened } : {}),
280
+ });
281
+ }
282
+ }
283
+ if (isSvelteFile(path)) {
284
+ for (const el of ctx.svelte(path)?.elements ?? []) {
285
+ if (el.kind !== 'element')
286
+ continue;
287
+ for (const attr of el.attributes) {
288
+ if (attr.kind === 'attribute' && /^on[a-z]+$/.test(attr.name) && typeof attr.value === 'string') {
289
+ out.push(ctx.at(path, attr.start, `\`<${el.name} ${attr.name}="…">\` ist ein Inline-Event-Handler als Zeichenkette.`, `Schreibe \`${attr.name}={() => …}\` statt einer Zeichenkette.`));
290
+ }
291
+ }
292
+ // Inline-Skript im Markup (z. B. in `<svelte:head>`): Die CSP der Seite sperrt es ohnehin.
293
+ if (el.name.toLowerCase() === 'script' && !getAttr(el, 'src')) {
294
+ const type = getAttr(el, 'type')?.value;
295
+ if (typeof type === 'string' && DATA_SCRIPT_TYPES.includes(type.trim().toLowerCase()))
296
+ continue;
297
+ out.push({
298
+ ...ctx.at(path, el.start, `\`${path}\` enthält ein Inline-Skript (\`<script>\` ohne \`src\`).`, INLINE_FIX),
299
+ severity: tightened,
300
+ });
301
+ }
302
+ }
303
+ }
304
+ }
305
+ for (const path of ctx.htmlFiles()) {
306
+ const code = ctx.code(path);
307
+ for (const m of findAll(code, INLINE_HANDLER_HTML, ctx.lines(path))) {
308
+ out.push({
309
+ file: path,
310
+ line: m.line,
311
+ column: m.column,
312
+ message: `\`${path}\` enthält einen Inline-Event-Handler.`,
313
+ });
314
+ }
315
+ for (const m of code.matchAll(INLINE_SCRIPT_HTML)) {
316
+ const attrs = m[1] ?? '';
317
+ if (/\bsrc\s*=/i.test(attrs))
318
+ continue;
319
+ const type = /\btype\s*=\s*["']?([^"'\s>]+)/i.exec(attrs)?.[1]?.toLowerCase();
320
+ if (type && DATA_SCRIPT_TYPES.includes(type))
321
+ continue;
322
+ out.push({
323
+ ...ctx.at(path, m.index, `\`${path}\` enthält ein Inline-Skript (\`<script>\` ohne \`src\`).`, INLINE_FIX),
324
+ severity: tightened,
325
+ });
326
+ }
327
+ // Inhaltsblock des SDK auch nicht in eigenen HTML-Dateien (`src/app.html`, `static/`).
328
+ for (const m of code.matchAll(/<[a-z]+\b[^>]*\bid\s*=\s*["']?ds-content\b[^>]*>/gi)) {
329
+ out.push(ctx.at(path, m.index, `\`${path}\` enthält den Inhaltsblock \`ds-content\` des SDK.`, CONTENT_BLOCK_FIX));
330
+ }
331
+ }
332
+ out.push(...contentBlockOwnership(ctx));
333
+ return out;
334
+ });
335
+ // Inhaltsblock `ds-content` (Patchen statt Bauen): Ihn schreibt nur `<SiteHead>` aus dem SDK. Ein eigener
336
+ // Block oder Code, der ihn liest oder schreibt, würde beim Patchen alte und neue Texte mischen.
337
+ // Regelsatz 3: Fehler (in feature/p2-content-block zunächst Warnung). Es gibt keinen legitimen Grund dafür.
338
+ const CONTENT_BLOCK_ID = /(['"`])ds-content\1/g;
339
+ const CONTENT_BLOCK_FIX = 'Lass den Block weg: `<SiteHead>` im Haupt-Layout schreibt ihn. Texte aus dem CRM gehören in `<Text>`, `<RichText>` oder `<MediaImage key>`.';
340
+ function contentBlockOwnership(ctx) {
341
+ const out = [];
342
+ const fix = CONTENT_BLOCK_FIX;
343
+ for (const path of ctx.codeFiles()) {
344
+ const reported = new Set();
345
+ if (isSvelteFile(path)) {
346
+ for (const el of ctx.svelte(path)?.elements ?? []) {
347
+ if (el.kind !== 'element')
348
+ continue;
349
+ const id = el.attributes.find((a) => a.kind === 'attribute' && a.name === 'id');
350
+ if (id?.value !== 'ds-content')
351
+ continue;
352
+ const finding = ctx.at(path, id.start, `\`<${el.name} id="ds-content">\` ist der Inhaltsblock des SDK.`, fix);
353
+ reported.add(finding.line ?? -1);
354
+ out.push(finding);
355
+ }
356
+ }
357
+ for (const m of findAll(ctx.code(path), CONTENT_BLOCK_ID, ctx.lines(path))) {
358
+ if (reported.has(m.line))
359
+ continue;
360
+ out.push({
361
+ file: path,
362
+ line: m.line,
363
+ column: m.column,
364
+ message: `\`${path}\` nennt den Inhaltsblock \`ds-content\` des SDK.`,
365
+ fix,
366
+ });
367
+ }
368
+ }
369
+ return out;
370
+ }
371
+ // ------------------------------------------------------------------ SEC-007
372
+ // Regelsatz 3: Ein eigenes `<form>` ist erlaubt (Enter zum Absenden, native Validierung, Semantik für
373
+ // Vorleseprogramme), solange es nichts selbst abschickt: Das Absenden läuft im Code über `createLeadClient()`.
374
+ // Zweite Schranke: `form-action 'self'` in der CSP.
375
+ const FORM_FIX = 'Lass `action` weg (oder `action="#"`), schreib `<form onsubmit={senden}>` und schick die Daten in `senden` mit `createLeadClient()` ab; oder nimm `<LeadForm funnel="…" />`. Formulardaten gehen nur über DealSystem in dein CRM.';
376
+ /** Ob `action` auf dieselbe Seite zeigt: leer, `#…`, `.` oder der Pfad der Seite selbst. */
377
+ export function isSamePageAction(value, route) {
378
+ const v = value.trim();
379
+ if (v === '' || v.startsWith('#') || v === '.' || v === './')
380
+ return true;
381
+ if (route === null || !v.startsWith('/') || v.startsWith('//'))
382
+ return false;
383
+ const path = v.split(/[?#]/)[0].replace(/\/+$/, '') || '/';
384
+ return path === (route.replace(/\/+$/, '') || '/');
385
+ }
386
+ /** Probleme eines `<form>` (oder eines Knopfs mit `formaction`). */
387
+ function formProblems(form, route, what) {
388
+ const problems = [];
389
+ const method = typeof form.method === 'string' ? form.method.trim().toLowerCase() : form.method;
390
+ if (form.action !== undefined) {
391
+ if (form.action === null)
392
+ problems.push(`${what}: \`action\` ist ein Ausdruck; wohin das Formular geht, lässt sich nicht prüfen.`);
393
+ else if (!isSamePageAction(form.action, route))
394
+ problems.push(`${what} schickt an \`${excerpt(form.action, 60)}\`, eine andere Adresse.`);
395
+ if (method === 'post' || method === null)
396
+ problems.push(`${what} hat \`method="post"\` mit \`action\`.`);
397
+ }
398
+ if (form.target !== undefined) {
399
+ const t = typeof form.target === 'string' ? form.target.trim().toLowerCase() : null;
400
+ if (t !== '_self' && t !== '')
401
+ problems.push(`${what} öffnet das Ergebnis in einem anderen Fenster (\`target\`).`);
402
+ }
403
+ return problems;
404
+ }
405
+ const attrValue = (el, name) => {
406
+ const a = getAttr(el, name);
407
+ if (!a)
408
+ return undefined;
409
+ return a.value === true ? '' : a.value;
410
+ };
411
+ /** `name="wert"` aus einem HTML-Tag; `undefined`, wenn das Attribut fehlt. */
412
+ function htmlAttr(tag, name) {
413
+ const m = new RegExp(`\\s${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, 'i').exec(tag);
414
+ if (!m)
415
+ return new RegExp(`\\s${name}(?=[\\s>/])`, 'i').test(tag) ? '' : undefined;
416
+ return m[1] ?? m[2] ?? m[3] ?? '';
417
+ }
418
+ const sec007 = sourceRule('SEC-007', (ctx) => {
419
+ const out = [];
420
+ for (const path of ctx.svelteFiles()) {
421
+ const route = /^src\/routes\/(?:.*\/)?\+page\.svelte$/.test(path) ? routeOfSource(path) : null;
422
+ for (const el of ctx.svelte(path)?.elements ?? []) {
423
+ if (el.kind !== 'element')
424
+ continue;
425
+ // Knöpfe und Eingaben können das Ziel des Formulars überschreiben.
426
+ if (getAttr(el, 'formaction') || getAttr(el, 'formtarget') || getAttr(el, 'formmethod')) {
427
+ const problems = formProblems({
428
+ action: attrValue(el, 'formaction'),
429
+ method: attrValue(el, 'formmethod'),
430
+ target: attrValue(el, 'formtarget'),
431
+ }, route, `\`<${el.name} formaction>\` in \`${path}\``);
432
+ for (const message of problems)
433
+ out.push(ctx.at(path, el.start, message, FORM_FIX));
434
+ }
435
+ if (el.name !== 'form')
436
+ continue;
437
+ const what = `Das \`<form>\` in \`${path}\``;
438
+ if (el.attributes.some((a) => a.kind === 'spread')) {
439
+ out.push(ctx.at(path, el.start, `${what} hat \`{...}\`; ob es eine \`action\` bekommt, lässt sich nicht prüfen.`, 'Schreibe die Attribute des `<form>` einzeln aus, ohne `{...}`.'));
440
+ continue;
441
+ }
442
+ const method = attrValue(el, 'method');
443
+ if (typeof method === 'string' && method.trim().toLowerCase() === 'dialog')
444
+ continue;
445
+ const problems = formProblems({ action: attrValue(el, 'action'), method, target: attrValue(el, 'target') }, route, what);
446
+ for (const message of problems)
447
+ out.push(ctx.at(path, el.start, message, FORM_FIX));
448
+ if (!getAttr(el, 'onsubmit')) {
449
+ out.push(ctx.at(path, el.start, `${what} hat kein \`onsubmit\`. Beim Absenden lädt die Seite neu, und die Eingaben stehen in der Adresse.`, FORM_FIX));
450
+ }
451
+ }
452
+ }
453
+ for (const path of ctx.htmlFiles()) {
454
+ const code = ctx.code(path);
455
+ for (const m of code.matchAll(/<form\b[^>]*>/gi)) {
456
+ const tag = m[0];
457
+ if ((htmlAttr(tag, 'method') ?? '').trim().toLowerCase() === 'dialog')
458
+ continue;
459
+ const problems = formProblems({ action: htmlAttr(tag, 'action'), method: htmlAttr(tag, 'method'), target: htmlAttr(tag, 'target') }, null, `Das \`<form>\` in \`${path}\``);
460
+ for (const message of problems)
461
+ out.push({ ...ctx.at(path, m.index, message), fix: FORM_FIX });
462
+ }
463
+ for (const m of code.matchAll(/<[a-z]+\b[^>]*\bform(?:action|target|method)\s*=[^>]*>/gi)) {
464
+ const tag = m[0];
465
+ const problems = formProblems({
466
+ action: htmlAttr(tag, 'formaction'),
467
+ method: htmlAttr(tag, 'formmethod'),
468
+ target: htmlAttr(tag, 'formtarget'),
469
+ }, null, `\`formaction\` in \`${path}\``);
470
+ for (const message of problems)
471
+ out.push({ ...ctx.at(path, m.index, message), fix: FORM_FIX });
472
+ }
473
+ }
474
+ return out;
475
+ });
476
+ // ------------------------------------------------------------------ SEC-008
477
+ /** Herkunft der Karte, die `<MapEmbed>` aus dem SDK einbettet. Muss zu packages/site passen. */
478
+ export const MAP_EMBED_ORIGIN = 'https://www.openstreetmap.org';
479
+ /** Welche CSP-Direktive über das Laden eines Elements entscheidet. */
480
+ const EMBED_DIRECTIVE = {
481
+ iframe: 'frame-src',
482
+ frame: 'frame-src',
483
+ embed: 'frame-src',
484
+ object: 'frame-src',
485
+ script: 'script-src',
486
+ };
487
+ function blockedMessage(tag, url, directive) {
488
+ return (`\`<${tag}>\` lädt \`${excerpt(url.href, 80)}\`, aber die Sicherheitsregeln der Seite (\`${directive}\`) ` +
489
+ `erlauben \`${url.host}\` nicht. Der Browser blockiert den Inhalt, auch nach der Einwilligung.`);
490
+ }
491
+ function blockedFix(tag) {
492
+ return tag === 'script'
493
+ ? 'Trage den Dienst unter `external` in dealsystem.config.ts ein (mit Host unter `script`) und lade das Skript mit `<ExternalScript id="…" src="…" />`. Anleitung: extern.md. Lockere nicht die Regeln in svelte.config.js.'
494
+ : 'Trage den Dienst unter `external` in dealsystem.config.ts ein (YouTube: `{ preset: \'youtube\' }`) und bette ihn mit `<Embed id="…" src="…" title="…" />` ein. Anleitung: extern.md. Lockere nicht die Regeln in svelte.config.js.';
495
+ }
496
+ const RAW_EMBED_FIX = {
497
+ script: 'Lade Skripte nur mit `<ExternalScript id="…" src="…" />` aus `@dealsystem/site`: Es wartet auf die Einwilligung und lädt nach einem Widerruf neu. Anleitung: extern.md.',
498
+ frame: 'Bette fremde Inhalte nur mit `<Embed id="…" src="…" title="…" />` aus `@dealsystem/site` ein: Es zeigt vor der Einwilligung einen Platzhalter. Anleitung: extern.md.',
499
+ };
500
+ function staticAttr(el, name) {
501
+ const attr = getAttr(el, name);
502
+ return attr && typeof attr.value === 'string' ? attr.value : null;
503
+ }
504
+ /** Prüft `<Embed>` und `<ExternalScript>` mit festen Angaben gegen Deklaration und CSP. */
505
+ function componentFindings(ctx, path, el, csp, kind) {
506
+ const isEmbed = el.name === COMPONENT.embed;
507
+ const id = staticAttr(el, 'id');
508
+ const src = staticAttr(el, 'src');
509
+ if (id === null)
510
+ return []; // Ausdruck: Das SDK prüft beim Build selbst.
511
+ const entry = declaredExternal(ctx).find((e) => e.id === id);
512
+ const tag = `<${el.name} id="${id}">`;
513
+ if (!entry) {
514
+ return [
515
+ ctx.at(path, el.start, `\`${tag}\` in \`${path}\`: "${id}" steht nicht unter \`external\` in dealsystem.config.ts. Ohne Deklaration lässt die Seite den Dienst nicht zu.`, isEmbed
516
+ ? `Trage den Dienst ein, z. B. \`external: { ${id}: { preset: 'youtube' } }\` (Vorlagen: youtube, vimeo, google-maps, calendly). Anleitung: extern.md.`
517
+ : `Trage den Dienst mit \`category\`, \`provider\`, \`purpose\`, \`privacyUrl\` und dem Host unter \`script\` ein, z. B. \`external: { ${id}: { category: 'marketing', …, script: ['https://js.anbieter.de'] } }\`. Anleitung: extern.md.`),
518
+ ];
519
+ }
520
+ if (src === null)
521
+ return [];
522
+ if (isEmbed) {
523
+ const resolved = resolveEmbedSource(entry, src);
524
+ if (!resolved.ok)
525
+ return [ctx.at(path, el.start, `\`${tag}\` in \`${path}\`: ${resolved.message}`)];
526
+ const url = new URL(resolved.src);
527
+ if (kind === 'legacy' && !cspAllows(csp, 'frame-src', url))
528
+ return [ctx.at(path, el.start, blockedMessage(el.name, url, 'frame-src'), blockedFix('iframe'))];
529
+ return [];
530
+ }
531
+ const problem = scriptSourceProblem(entry, src);
532
+ if (problem) {
533
+ return [
534
+ ctx.at(path, el.start, `\`${tag}\` in \`${path}\`: ${problem}`, `Trage den Host unter \`external.${id}.script\` in dealsystem.config.ts ein (nur \`https://host\`, ohne Pfad) oder lege die Datei unter \`static/\` ab.`),
535
+ ];
536
+ }
537
+ const url = externalUrl(src);
538
+ if (url && kind === 'legacy' && !cspAllows(csp, 'script-src', url))
539
+ return [ctx.at(path, el.start, blockedMessage(el.name, url, 'script-src'), blockedFix('script'))];
540
+ return [];
541
+ }
542
+ const sec008Source = sourceRule('SEC-008', (ctx) => {
543
+ const found = sourceCsp(ctx);
544
+ if (!found)
545
+ return []; // SEC-005 meldet die fehlende oder unlesbare CSP.
546
+ const out = [];
547
+ const tightened = tighteningSeverity(ctx);
548
+ // Formular und Captcha sprechen die Site-API an. Welche Adresse das ist, steht erst beim Build fest
549
+ // (PUBLIC_DEALSYSTEM_API): Eine fest eingetragene Adresse passt nur für eine Umgebung.
550
+ const connect = found.csp['connect-src'] ?? found.csp['default-src'];
551
+ if (connect && !connect.includes(SITE_API_SOURCE) && !connect.some((s) => unquote(s) === '*')) {
552
+ out.push({
553
+ file: found.path,
554
+ message: '`connect-src` in svelte.config.js nennt die Adresse der Site-API nicht über `siteApiOrigin()`. Wird die Seite für eine andere Umgebung erzeugt, blockiert der Browser Formular und Captcha.',
555
+ fix: "Schreibe in svelte.config.js `csp: dealsystemCsp()` mit `import { dealsystemCsp } from '@dealsystem/site/csp'`, oder führe `npx dealsystem sync --fix-config` aus.",
556
+ });
557
+ }
558
+ for (const path of ctx.svelteFiles()) {
559
+ const ast = ctx.svelte(path);
560
+ if (!ast)
561
+ continue;
562
+ const usesSdk = ctx.code(path).includes(SDK_PACKAGE);
563
+ for (const el of ast.elements) {
564
+ if (el.kind === 'component') {
565
+ if (!usesSdk)
566
+ continue;
567
+ // `<MapEmbed>` bettet OpenStreetMap ein: Die Vorlage der CSP erlaubt das, eine ältere oder veränderte nicht.
568
+ if (el.name === COMPONENT.map && !cspAllows(found.csp, 'frame-src', new URL(MAP_EMBED_ORIGIN))) {
569
+ out.push(ctx.at(path, el.start, `\`<${COMPONENT.map}>\` bettet eine Karte von \`${MAP_EMBED_ORIGIN}\` ein, aber \`frame-src\` in svelte.config.js erlaubt das nicht. Die Karte bliebe leer.`, 'Führe `npx dealsystem sync --fix-config` aus: Die Vorlage von svelte.config.js erlaubt die Karte.'));
570
+ }
571
+ if (el.name === COMPONENT.embed || el.name === COMPONENT.externalScript) {
572
+ out.push(...componentFindings(ctx, path, el, found.csp, found.kind));
573
+ }
574
+ continue;
575
+ }
576
+ const tag = el.name.toLowerCase();
577
+ const directive = EMBED_DIRECTIVE[tag];
578
+ if (!directive)
579
+ continue;
580
+ const value = staticAttr(el, tag === 'object' ? 'data' : 'src');
581
+ const url = externalUrl(value);
582
+ if (url && !cspAllows(found.csp, directive, url)) {
583
+ out.push(ctx.at(path, el.start, blockedMessage(tag, url, directive), blockedFix(tag)));
584
+ }
585
+ else if (url || (tag === 'script' && value !== null)) {
586
+ // Regelsatz 3: fremde Rahmen und jedes Skript nur über die Bausteine des SDK.
587
+ out.push({
588
+ ...ctx.at(path, el.start, `\`<${tag}>\` in \`${path}\` lädt \`${excerpt(value ?? '', 80)}\` ohne Baustein des SDK.`, RAW_EMBED_FIX[tag === 'script' ? 'script' : 'frame']),
589
+ severity: tightened,
590
+ });
591
+ }
592
+ }
593
+ }
594
+ return out;
595
+ });
596
+ /** Adressen, die eine fertige Seite lädt oder nach der Einwilligung laden wird, mit Direktive. */
597
+ function pageLoads(doc) {
598
+ const out = [];
599
+ for (const el of doc.elements) {
600
+ const direct = EMBED_DIRECTIVE[el.tag];
601
+ if (direct) {
602
+ const url = externalUrl(el.attrs[el.tag === 'object' ? 'data' : 'src']);
603
+ if (url)
604
+ out.push({ el, url, directive: direct, tag: el.tag });
605
+ }
606
+ // Platzhalter von `<Embed>` und Marker von `<ExternalScript>`: Laden erst nach der Einwilligung.
607
+ const marked = MARKER.embed in el.attrs ? 'frame-src' : MARKER.externalScript in el.attrs ? 'script-src' : null;
608
+ const src = el.attrs[MARKER.src];
609
+ if (marked && src) {
610
+ const url = externalUrl(src);
611
+ if (url)
612
+ out.push({ el, url, directive: marked, tag: marked === 'frame-src' ? 'Embed' : 'ExternalScript' });
613
+ }
614
+ }
615
+ return out;
616
+ }
617
+ const sec008Output = outputRule('SEC-008', (ctx) => {
618
+ const out = [];
619
+ const api = externalUrl(ctx.options.apiUrl);
620
+ // Unbekannte Deklaration (Build-Host, älteres SDK ohne `external` im Manifest): gegen die Basis, nur als Warnung.
621
+ const known = ctx.expectedCsp(api?.origin ?? SITE_API_SOURCE);
622
+ const expected = known?.csp ?? buildCspDirectives([], api?.origin ?? SITE_API_SOURCE, { googleAds: true });
623
+ const looserSeverity = known?.strict ? 'error' : 'warning';
624
+ let apiReported = false;
625
+ for (const path of ctx.pages()) {
626
+ const doc = ctx.html(path);
627
+ const meta = doc.elements.find((el) => el.tag === 'meta' && el.attrs['http-equiv']?.toLowerCase() === 'content-security-policy');
628
+ if (!meta?.attrs.content)
629
+ continue;
630
+ const csp = metaCsp(meta.attrs.content);
631
+ // Die fertige Seite darf nicht mehr erlauben, als Basis und Deklaration ergeben.
632
+ const looser = cspLooserThan(csp, expected, api?.origin ?? null, known?.strict ?? false);
633
+ if (looser.length > 0) {
634
+ out.push({
635
+ file: path,
636
+ line: lineOf(doc, meta),
637
+ message: `Die Sicherheitsregeln der fertigen Seite weichen von dealsystem.config.ts ab: ${looser.join(' ')}`,
638
+ severity: looserSeverity,
639
+ fix: 'Schreibe in svelte.config.js nur `csp: dealsystemCsp()` und ändere die Regeln nirgends sonst. Fremde Hosts gehören unter `external` in dealsystem.config.ts (extern.md); `npx dealsystem sync --fix-config` stellt svelte.config.js wieder her.',
640
+ });
641
+ }
642
+ // Die Seite schickt Formular und Captcha an die Site-API: Die CSP der fertigen Seite muss sie erlauben.
643
+ if (api && !apiReported && !cspAllows(csp, 'connect-src', api)) {
644
+ apiReported = true;
645
+ out.push({
646
+ file: path,
647
+ line: lineOf(doc, meta),
648
+ message: `Die Sicherheitsregeln der fertigen Seite (\`connect-src\`) erlauben die Site-API \`${api.origin}\` nicht. Der Browser blockiert Formular und Captcha.`,
649
+ fix: 'Schreibe in svelte.config.js `csp: dealsystemCsp()` (`npx dealsystem sync --fix-config`) und erzeuge die Seite neu, mit derselben `PUBLIC_DEALSYSTEM_API` wie beim Hochladen.',
650
+ });
651
+ }
652
+ for (const load of pageLoads(doc)) {
653
+ if (!cspAllows(csp, load.directive, load.url)) {
654
+ out.push({
655
+ file: path,
656
+ line: lineOf(doc, load.el),
657
+ message: blockedMessage(load.tag, load.url, load.directive),
658
+ fix: blockedFix(load.directive === 'script-src' ? 'script' : 'iframe'),
659
+ });
660
+ }
661
+ }
662
+ }
663
+ return out;
664
+ });
665
+ // ------------------------------------------------------------------ SEC-009
666
+ const PASSWORD_FIX = 'Entferne das Passwortfeld. Eine Seite auf DealSystem hat keine Anmeldung; ein Passwortfeld wirkt wie eine nachgebaute Login-Seite und kann die Seite sperren lassen.';
667
+ // Neu in Regelsatz 3: Fehler für Seiten mit `dealsystemCsp()`, Warnung für die Altform (unveränderte Live-Seiten).
668
+ const sec009Source = sourceRule('SEC-009', (ctx) => {
669
+ const out = [];
670
+ const severity = tighteningSeverity(ctx);
671
+ for (const path of ctx.svelteFiles()) {
672
+ for (const el of ctx.svelte(path)?.elements ?? []) {
673
+ if (el.kind === 'element' &&
674
+ el.name === 'input' &&
675
+ staticAttr(el, 'type')?.trim().toLowerCase() === 'password')
676
+ out.push({
677
+ ...ctx.at(path, el.start, `\`${path}\` enthält ein Passwortfeld.`, PASSWORD_FIX),
678
+ severity,
679
+ });
680
+ }
681
+ }
682
+ for (const path of ctx.htmlFiles()) {
683
+ for (const m of ctx.code(path).matchAll(/<input\b[^>]*\btype\s*=\s*["']?password\b/gi))
684
+ out.push({
685
+ ...ctx.at(path, m.index, `\`${path}\` enthält ein Passwortfeld.`),
686
+ fix: PASSWORD_FIX,
687
+ severity,
688
+ });
689
+ }
690
+ return out;
691
+ });
692
+ const sec009Output = outputRule('SEC-009', (ctx) => {
693
+ const out = [];
694
+ const severity = ctx.declared?.strict ? 'error' : 'warning';
695
+ for (const path of ctx.pages()) {
696
+ const doc = ctx.html(path);
697
+ for (const el of doc.elements) {
698
+ if (el.tag === 'input' && el.attrs.type?.trim().toLowerCase() === 'password')
699
+ out.push({
700
+ file: path,
701
+ line: lineOf(doc, el),
702
+ message: `\`${path}\` enthält ein Passwortfeld.`,
703
+ fix: PASSWORD_FIX,
704
+ severity,
705
+ });
706
+ }
707
+ }
708
+ return out;
709
+ });
710
+ // ------------------------------------------------------------------ SEC-011
711
+ /**
712
+ * Eigene Skripte auf einer Seite, die nur unter dem Standard-Host (`<name>.dealsystem.site`) läuft, solange die
713
+ * Domain nicht auf der Public Suffix List steht: Ein Skript könnte Cookies für alle Seiten setzen. Nur der
714
+ * Build-Host kennt die Hosts der Seite (`CheckOptions.hosting`); lokal bleibt die Regel still.
715
+ */
716
+ const sec011 = outputRule('SEC-011', (ctx) => {
717
+ const hosting = ctx.options.hosting;
718
+ if (!hosting?.standardHostOnly || hosting.sitesDomainOnPsl)
719
+ return [];
720
+ const pages = ctx
721
+ .pages()
722
+ .filter((p) => ctx.html(p).elements.some((el) => MARKER.externalScript in el.attrs));
723
+ if (pages.length === 0)
724
+ return [];
725
+ return [
726
+ {
727
+ file: pages[0],
728
+ message: `\`<ExternalScript>\` läuft hier nur unter der Adresse von DealSystem (${pages.length === 1 ? 'eine Seite' : `${pages.length} Seiten`}). Eigene Skripte gehen dort noch nicht, weil sich Seiten verschiedener Kunden diese Adresse teilen.`,
729
+ fix: 'Verbinde eine eigene Domain (Eigene Website → Domains) oder nimm `<ExternalScript>` heraus. Videos über `<Embed>` und Tracking über `<Tracking />` gehen auch ohne eigene Domain.',
730
+ },
731
+ ];
732
+ });
733
+ export const securitySourceRules = [
734
+ sec001Source,
735
+ sec002,
736
+ sec003,
737
+ sec004,
738
+ sec005,
739
+ sec006,
740
+ sec007,
741
+ sec008Source,
742
+ sec009Source,
743
+ ];
744
+ export const securityOutputRules = [sec001Output, sec008Output, sec009Output, sec011];