wp-shakedown 0.0.0-stage → 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 (116) hide show
  1. package/LICENSE +340 -0
  2. package/README.md +74 -2
  3. package/dist/baseline.d.ts +6 -0
  4. package/dist/baseline.js +41 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +296 -0
  7. package/dist/diff.d.ts +8 -0
  8. package/dist/diff.js +26 -0
  9. package/dist/engines/config.d.ts +3 -0
  10. package/dist/engines/config.js +134 -0
  11. package/dist/engines/custom.d.ts +10 -0
  12. package/dist/engines/custom.js +286 -0
  13. package/dist/engines/eslint.d.ts +8 -0
  14. package/dist/engines/eslint.js +96 -0
  15. package/dist/engines/index.d.ts +2 -0
  16. package/dist/engines/index.js +14 -0
  17. package/dist/engines/integrity.d.ts +2 -0
  18. package/dist/engines/integrity.js +108 -0
  19. package/dist/engines/php-compat.d.ts +2 -0
  20. package/dist/engines/php-compat.js +26 -0
  21. package/dist/engines/php-lint.d.ts +6 -0
  22. package/dist/engines/php-lint.js +42 -0
  23. package/dist/engines/phpstan.d.ts +11 -0
  24. package/dist/engines/phpstan.js +103 -0
  25. package/dist/engines/stylelint.d.ts +4 -0
  26. package/dist/engines/stylelint.js +63 -0
  27. package/dist/engines/theme-check.d.ts +7 -0
  28. package/dist/engines/theme-check.js +109 -0
  29. package/dist/engines/theme-review.d.ts +24 -0
  30. package/dist/engines/theme-review.js +378 -0
  31. package/dist/engines/updates.d.ts +6 -0
  32. package/dist/engines/updates.js +78 -0
  33. package/dist/engines/vulnerabilities.d.ts +22 -0
  34. package/dist/engines/vulnerabilities.js +128 -0
  35. package/dist/engines/wp-json.d.ts +18 -0
  36. package/dist/engines/wp-json.js +134 -0
  37. package/dist/engines/wpcs.d.ts +7 -0
  38. package/dist/engines/wpcs.js +60 -0
  39. package/dist/exec.d.ts +12 -0
  40. package/dist/exec.js +19 -0
  41. package/dist/fingerprint.d.ts +10 -0
  42. package/dist/fingerprint.js +29 -0
  43. package/dist/health/install.d.ts +16 -0
  44. package/dist/health/install.js +68 -0
  45. package/dist/home.d.ts +2 -0
  46. package/dist/home.js +6 -0
  47. package/dist/hub.d.ts +32 -0
  48. package/dist/hub.js +99 -0
  49. package/dist/index.d.ts +42 -0
  50. package/dist/index.js +36 -0
  51. package/dist/js/files.d.ts +4 -0
  52. package/dist/js/files.js +47 -0
  53. package/dist/js/tools.d.ts +3 -0
  54. package/dist/js/tools.js +67 -0
  55. package/dist/mcp/server.d.ts +9 -0
  56. package/dist/mcp/server.js +91 -0
  57. package/dist/mcp/tools.d.ts +26 -0
  58. package/dist/mcp/tools.js +163 -0
  59. package/dist/net.d.ts +18 -0
  60. package/dist/net.js +68 -0
  61. package/dist/php/files.d.ts +3 -0
  62. package/dist/php/files.js +53 -0
  63. package/dist/php/php.d.ts +4 -0
  64. package/dist/php/php.js +25 -0
  65. package/dist/php/phpcs.d.ts +25 -0
  66. package/dist/php/phpcs.js +55 -0
  67. package/dist/php/tools.d.ts +3 -0
  68. package/dist/php/tools.js +66 -0
  69. package/dist/profiles.d.ts +4 -0
  70. package/dist/profiles.js +41 -0
  71. package/dist/progress.d.ts +3 -0
  72. package/dist/progress.js +13 -0
  73. package/dist/projects.d.ts +36 -0
  74. package/dist/projects.js +91 -0
  75. package/dist/report/escape.d.ts +1 -0
  76. package/dist/report/escape.js +4 -0
  77. package/dist/report/html.d.ts +2 -0
  78. package/dist/report/html.js +100 -0
  79. package/dist/report/json.d.ts +2 -0
  80. package/dist/report/json.js +3 -0
  81. package/dist/report/markdown.d.ts +5 -0
  82. package/dist/report/markdown.js +92 -0
  83. package/dist/report/sarif.d.ts +2 -0
  84. package/dist/report/sarif.js +44 -0
  85. package/dist/report/write.d.ts +9 -0
  86. package/dist/report/write.js +48 -0
  87. package/dist/runner.d.ts +14 -0
  88. package/dist/runner.js +166 -0
  89. package/dist/session.d.ts +22 -0
  90. package/dist/session.js +39 -0
  91. package/dist/target.d.ts +5 -0
  92. package/dist/target.js +114 -0
  93. package/dist/types.d.ts +165 -0
  94. package/dist/types.js +6 -0
  95. package/dist/ui/server.d.ts +13 -0
  96. package/dist/ui/server.js +458 -0
  97. package/dist/version.d.ts +1 -0
  98. package/dist/version.js +3 -0
  99. package/dist/versions.d.ts +9 -0
  100. package/dist/versions.js +35 -0
  101. package/js-tools/eslint.config.mjs +19 -0
  102. package/js-tools/package-lock.json +7004 -0
  103. package/js-tools/package.json +13 -0
  104. package/js-tools/stylelint.config.mjs +4 -0
  105. package/package.json +58 -4
  106. package/php-tools/composer.json +68 -0
  107. package/php-tools/composer.lock +889 -0
  108. package/php-tools/theme-check.php +239 -0
  109. package/ui/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  110. package/ui/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  111. package/ui/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  112. package/ui/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  113. package/ui/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  114. package/ui/dist/assets/index-DXwdz_Wu.css +2 -0
  115. package/ui/dist/assets/index-V8IOqxHa.js +54 -0
  116. package/ui/dist/index.html +14 -0
package/dist/cli.js ADDED
@@ -0,0 +1,296 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from 'node:child_process';
3
+ import { statSync } from 'node:fs';
4
+ import path from 'node:path';
5
+ import { parseArgs } from 'node:util';
6
+ import { engines } from './engines/index.js';
7
+ import { profiles } from './profiles.js';
8
+ import { hubExitCode, hubLines, projectTable, runMany } from './hub.js';
9
+ import { addProject, listProjects, removeProject } from './projects.js';
10
+ import { progressLine } from './progress.js';
11
+ import { noEngineLine, summaryLine } from './report/markdown.js';
12
+ import { exitCode } from './runner.js';
13
+ import { runSession } from './session.js';
14
+ import { startMcp } from './mcp/server.js';
15
+ import { startUi } from './ui/server.js';
16
+ import { VERSION } from './version.js';
17
+ const profileList = `${profiles.slice(0, -1).map((p) => p.id).join(', ')} or ${profiles[profiles.length - 1].id}`;
18
+ const HELP = `wp-shakedown ${VERSION}
19
+
20
+ Usage:
21
+ wp-shakedown run <path>... [options]
22
+ wp-shakedown run --all [options]
23
+ wp-shakedown add <path>...
24
+ wp-shakedown remove <project>...
25
+ wp-shakedown list
26
+ wp-shakedown ui [path] [options]
27
+ wp-shakedown mcp
28
+
29
+ Options:
30
+ --type <kind> Treat the path as a theme, plugin or install
31
+ --engine <id> Run only this engine. Repeat for more than one
32
+ --profile <id> Run the engines for one gate: ${profileList}
33
+ --depth <level> How thorough the run is: quick, standard or deep. The default is standard
34
+ --experimental Also run the experimental engines
35
+ --out <dir> Write the report here
36
+ --baseline <file> Use this baseline file
37
+ --fail-on <level> Exit 1 at this severity: error, warning, info or never
38
+ --all Run every project on the list
39
+ --jobs <n> How many projects run at once. The default is 3
40
+ --port <n> Port for the ui command. The default is a free port
41
+ --no-open Do not open the browser
42
+ -h, --help Show this help
43
+ -v, --version Show the version
44
+
45
+ Exit codes: 0 clean, 1 findings at or above --fail-on, 2 the run itself failed.
46
+ `;
47
+ function add(paths) {
48
+ if (paths.length === 0) {
49
+ console.error('wp-shakedown: Give a folder to add, for example: wp-shakedown add ./my-theme');
50
+ return 2;
51
+ }
52
+ const labels = { theme: 'theme', plugin: 'plugin', install: 'WordPress folder', url: 'site URL' };
53
+ let code = 0;
54
+ for (const p of paths) {
55
+ try {
56
+ const { project, added } = addProject(p);
57
+ console.log(added ? `Added the ${labels[project.kind]} "${project.name}".` : `"${project.name}" is already on the list.`);
58
+ }
59
+ catch (err) {
60
+ console.error(`wp-shakedown: ${err instanceof Error ? err.message : String(err)}`);
61
+ code = 2;
62
+ }
63
+ }
64
+ return code;
65
+ }
66
+ function remove(keys) {
67
+ if (keys.length === 0) {
68
+ console.error('wp-shakedown: Name a project to remove. wp-shakedown list shows them.');
69
+ return 2;
70
+ }
71
+ let code = 0;
72
+ for (const k of keys) {
73
+ if (removeProject(k))
74
+ console.log(`Removed "${k}". Its reports stay.`);
75
+ else {
76
+ console.error(`wp-shakedown: No project fits "${k}".`);
77
+ code = 2;
78
+ }
79
+ }
80
+ return code;
81
+ }
82
+ function list() {
83
+ const projects = listProjects();
84
+ console.log(projects.length === 0 ? 'No projects yet. Add one with: wp-shakedown add <path>' : projectTable(projects));
85
+ return 0;
86
+ }
87
+ async function runHub(inputs, jobs, f) {
88
+ const ac = new AbortController();
89
+ const onSigint = () => ac.abort();
90
+ process.once('SIGINT', onSigint);
91
+ const live = process.stderr.isTTY;
92
+ let drawn = 0;
93
+ let timer;
94
+ const draw = (rows) => {
95
+ timer = undefined;
96
+ const lines = hubLines(rows, process.stderr.columns || 80);
97
+ process.stderr.write((drawn ? `\x1b[${drawn}A` : '') + lines.map((l) => `\x1b[2K${l}\n`).join(''));
98
+ drawn = lines.length;
99
+ };
100
+ let latest = [];
101
+ const rows = await runMany(inputs, {
102
+ jobs,
103
+ session: {
104
+ engines,
105
+ signal: ac.signal,
106
+ ...(f.type ? { type: f.type } : {}),
107
+ ...(f.only ? { only: f.only } : {}),
108
+ ...(f.profile ? { profile: f.profile } : {}),
109
+ ...(f.experimental ? { experimental: true } : {}),
110
+ ...(f.depth ? { depth: f.depth } : {}),
111
+ },
112
+ onChange: (all, row, event) => {
113
+ latest = all;
114
+ if (live)
115
+ timer ??= setTimeout(() => draw(latest), 100);
116
+ else if (event) {
117
+ const line = progressLine(event);
118
+ if (line)
119
+ console.error(`[${row.name}] ${line}`);
120
+ }
121
+ else if (row.state === 'failed')
122
+ console.error(`[${row.name}] failed: ${row.error}`);
123
+ },
124
+ });
125
+ process.off('SIGINT', onSigint);
126
+ if (live) {
127
+ if (timer)
128
+ clearTimeout(timer);
129
+ draw(rows);
130
+ }
131
+ for (const r of rows) {
132
+ console.log(r.state === 'done' ? `${r.name}: ${summaryLine(r.result)} Report: ${r.reportFile}` : `${r.name}: failed: ${r.error}`);
133
+ }
134
+ return hubExitCode(rows, f.failOn);
135
+ }
136
+ function openBrowser(url) {
137
+ const [cmd, args] = process.platform === 'darwin' ? ['open', [url]] : process.platform === 'win32' ? ['cmd', ['/c', 'start', '""', url]] : ['xdg-open', [url]];
138
+ try {
139
+ const child = spawn(cmd, args, { detached: true, stdio: 'ignore' });
140
+ child.on('error', () => { });
141
+ child.unref();
142
+ }
143
+ catch {
144
+ // The URL is printed, so a missing opener costs nothing.
145
+ }
146
+ }
147
+ async function ui(input, portText, noOpen) {
148
+ let port;
149
+ if (portText !== undefined) {
150
+ port = Number(portText);
151
+ if (!/^\d+$/.test(portText) || port > 65535)
152
+ throw new Error('--port must be a number from 0 to 65535.');
153
+ }
154
+ const startDir = path.resolve(input ?? process.cwd());
155
+ if (!statSync(startDir, { throwIfNoEntry: false })?.isDirectory())
156
+ throw new Error(`"${input}" is not a folder.`);
157
+ if (input !== undefined) {
158
+ try {
159
+ addProject(startDir);
160
+ }
161
+ catch {
162
+ // A folder that is not a theme, a plugin or a WordPress folder is only the place to start browsing.
163
+ }
164
+ }
165
+ const server = await startUi({ engines, startDir, ...(port !== undefined ? { port } : {}) });
166
+ // Listen for the signal before printing the address. Whoever reads that line may send the signal at once.
167
+ const stopped = new Promise((resolve) => {
168
+ process.once('SIGINT', resolve);
169
+ process.once('SIGTERM', resolve);
170
+ });
171
+ console.log(`wp-shakedown is running at ${server.url}`);
172
+ console.log('Press Ctrl+C to stop.');
173
+ if (!noOpen)
174
+ openBrowser(server.url);
175
+ await stopped;
176
+ await server.close();
177
+ return 0;
178
+ }
179
+ async function main(argv) {
180
+ try {
181
+ const { values, positionals } = parseArgs({
182
+ args: argv,
183
+ allowPositionals: true,
184
+ options: {
185
+ type: { type: 'string' },
186
+ engine: { type: 'string', multiple: true },
187
+ profile: { type: 'string' },
188
+ depth: { type: 'string' },
189
+ experimental: { type: 'boolean' },
190
+ out: { type: 'string' },
191
+ baseline: { type: 'string' },
192
+ 'fail-on': { type: 'string' },
193
+ all: { type: 'boolean' },
194
+ jobs: { type: 'string' },
195
+ port: { type: 'string' },
196
+ 'no-open': { type: 'boolean' },
197
+ help: { type: 'boolean', short: 'h' },
198
+ version: { type: 'boolean', short: 'v' },
199
+ },
200
+ });
201
+ if (values.version) {
202
+ console.log(VERSION);
203
+ return 0;
204
+ }
205
+ if (values.help || positionals.length === 0) {
206
+ process.stdout.write(HELP);
207
+ return 0;
208
+ }
209
+ const [command, input] = positionals;
210
+ if (command === 'add')
211
+ return add(positionals.slice(1));
212
+ if (command === 'remove')
213
+ return remove(positionals.slice(1));
214
+ if (command === 'list')
215
+ return list();
216
+ if (command === 'mcp') {
217
+ await startMcp({ engines, input: process.stdin, output: process.stdout }).closed;
218
+ return 0;
219
+ }
220
+ if (command === 'ui')
221
+ return await ui(input, values.port, values['no-open'] ?? false);
222
+ if (command !== 'run')
223
+ throw new Error(`Unknown command "${command}". Run wp-shakedown --help.`);
224
+ const paths = positionals.slice(1);
225
+ const all = values.all ?? false;
226
+ if (all && paths.length > 0)
227
+ throw new Error('Use --all or paths, not both.');
228
+ if (!all && paths.length === 0)
229
+ throw new Error('Give a folder to test, for example: wp-shakedown run ./my-theme');
230
+ let jobs = 3;
231
+ if (values.jobs !== undefined) {
232
+ jobs = Number(values.jobs);
233
+ if (!/^\d+$/.test(values.jobs) || jobs < 1 || jobs > 8)
234
+ throw new Error('--jobs must be a number from 1 to 8.');
235
+ }
236
+ const many = all || paths.length > 1;
237
+ if (many && values.out)
238
+ throw new Error('--out works with one path.');
239
+ if (many && values.baseline)
240
+ throw new Error('--baseline works with one path.');
241
+ const type = values.type;
242
+ if (type !== undefined && type !== 'theme' && type !== 'plugin' && type !== 'install') {
243
+ throw new Error('--type must be theme, plugin or install.');
244
+ }
245
+ const depth = values.depth;
246
+ if (depth !== undefined && depth !== 'quick' && depth !== 'standard' && depth !== 'deep') {
247
+ throw new Error('--depth must be quick, standard or deep.');
248
+ }
249
+ const failOn = values['fail-on'] ?? 'error';
250
+ if (failOn !== 'error' && failOn !== 'warning' && failOn !== 'info' && failOn !== 'never') {
251
+ throw new Error('--fail-on must be error, warning, info or never.');
252
+ }
253
+ if (many) {
254
+ // The same folder twice would write one report folder from two runs.
255
+ const targets = all ? listProjects().filter((p) => p.kind).map((p) => p.path) : [...new Set(paths.map((p) => path.resolve(p)))];
256
+ if (targets.length === 0)
257
+ throw new Error('No projects yet. Add one with: wp-shakedown add <path>');
258
+ return await runHub(targets, jobs, {
259
+ ...(type ? { type } : {}),
260
+ ...(values.engine ? { only: values.engine } : {}),
261
+ ...(values.profile ? { profile: values.profile } : {}),
262
+ ...(depth ? { depth } : {}),
263
+ ...(values.experimental ? { experimental: true } : {}),
264
+ failOn: failOn,
265
+ });
266
+ }
267
+ const { result, diff, files } = await runSession({
268
+ input: input,
269
+ ...(type ? { type } : {}),
270
+ ...(values.engine ? { only: values.engine } : {}),
271
+ ...(values.profile ? { profile: values.profile } : {}),
272
+ ...(depth ? { depth } : {}),
273
+ ...(values.experimental ? { experimental: true } : {}),
274
+ ...(values.out ? { out: values.out } : {}),
275
+ ...(values.baseline ? { baselineFile: values.baseline } : {}),
276
+ engines,
277
+ onEvent: (e) => {
278
+ const line = progressLine(e);
279
+ if (line)
280
+ console.error(line);
281
+ },
282
+ });
283
+ console.log(summaryLine(result));
284
+ if (result.engines.length === 0)
285
+ console.log(noEngineLine(result));
286
+ if (diff)
287
+ console.log(`${diff.fixed.length} fixed, ${diff.added.length} new, ${diff.open.length} still open.`);
288
+ console.log(`Report: ${files[0]}`);
289
+ return exitCode(result, failOn);
290
+ }
291
+ catch (err) {
292
+ console.error(`wp-shakedown: ${err instanceof Error ? err.message : String(err)}`);
293
+ return 2;
294
+ }
295
+ }
296
+ process.exitCode = await main(process.argv.slice(2));
package/dist/diff.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { RunDiff, RunResult } from './types.ts';
2
+ /**
3
+ * Compares only what the same engine checked in both runs. A run with --engine,
4
+ * or one where an engine was skipped, would otherwise report the findings of
5
+ * every engine that did not run as fixed. The same goes for an engine that ran
6
+ * another variant of its tool, such as Theme Check under the envato profile.
7
+ */
8
+ export declare function diffRuns(previous: RunResult, current: RunResult): RunDiff;
package/dist/diff.js ADDED
@@ -0,0 +1,26 @@
1
+ const key = (engine, unit) => `${engine}\n${unit ?? ''}`;
2
+ /** What ran well, with the variant of the tool it ran. */
3
+ const ranOk = (r) => new Map(r.engines.filter((e) => e.status === 'ok').map((e) => [key(e.engine, e.unit), e.variant ?? '']));
4
+ /**
5
+ * Compares only what the same engine checked in both runs. A run with --engine,
6
+ * or one where an engine was skipped, would otherwise report the findings of
7
+ * every engine that did not run as fixed. The same goes for an engine that ran
8
+ * another variant of its tool, such as Theme Check under the envato profile.
9
+ */
10
+ export function diffRuns(previous, current) {
11
+ const before = ranOk(previous);
12
+ const now = ranOk(current);
13
+ const compared = (f) => {
14
+ const k = key(f.engine, f.unit);
15
+ return !f.suppressed && before.has(k) && before.get(k) === now.get(k);
16
+ };
17
+ const prev = previous.findings.filter(compared);
18
+ const cur = current.findings.filter(compared);
19
+ const prevIds = new Set(prev.map((f) => f.id));
20
+ const curIds = new Set(cur.map((f) => f.id));
21
+ return {
22
+ fixed: prev.filter((f) => !curIds.has(f.id)),
23
+ added: cur.filter((f) => !prevIds.has(f.id)),
24
+ open: cur.filter((f) => prevIds.has(f.id)),
25
+ };
26
+ }
@@ -0,0 +1,3 @@
1
+ import type { Engine, RawFinding } from '../types.ts';
2
+ export declare function configFindings(text: string): RawFinding[];
3
+ export declare const config: Engine;
@@ -0,0 +1,134 @@
1
+ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ /** Removes PHP comments and leaves quoted strings alone, so a salt with // or # in it stays whole. */
4
+ function stripComments(text) {
5
+ let out = '';
6
+ for (let i = 0; i < text.length; i++) {
7
+ const c = text[i];
8
+ if (c === "'" || c === '"') {
9
+ let j = i + 1;
10
+ while (j < text.length && text[j] !== c)
11
+ j += text[j] === '\\' ? 2 : 1;
12
+ out += text.slice(i, j + 1);
13
+ i = j;
14
+ }
15
+ else if (c === '#' || (c === '/' && text[i + 1] === '/')) {
16
+ while (i < text.length && text[i] !== '\n')
17
+ i++;
18
+ out += '\n';
19
+ }
20
+ else if (c === '/' && text[i + 1] === '*') {
21
+ const end = text.indexOf('*/', i + 2);
22
+ i = end < 0 ? text.length : end + 1;
23
+ out += ' ';
24
+ }
25
+ else
26
+ out += c;
27
+ }
28
+ return out;
29
+ }
30
+ const SALTS = ['AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'NONCE_KEY', 'AUTH_SALT', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT'];
31
+ const FILE = { file: 'wp-config.php' };
32
+ export function configFindings(text) {
33
+ const code = stripComments(text);
34
+ const define = (name) => new RegExp(`define\\(\\s*['"]${name}['"]\\s*,\\s*(.+?)\\s*\\)\\s*;`, 's').exec(code)?.[1];
35
+ const isOn = (v) => v !== undefined && /^(true|1)$/i.test(v);
36
+ const out = [];
37
+ if (isOn(define('WP_DEBUG'))) {
38
+ out.push({ rule: 'config.debug', severity: 'warning', category: 'security', message: 'WP_DEBUG is on.', hint: 'Turn it off on a live site. Error output can reveal paths and code.', location: FILE });
39
+ }
40
+ const weak = SALTS.some((k) => {
41
+ const v = define(k);
42
+ if (v === undefined)
43
+ return true;
44
+ const m = /^(['"])([\s\S]*)\1$/.exec(v);
45
+ return !!m && (m[2] === 'put your unique phrase here' || m[2].length < 32);
46
+ });
47
+ if (weak) {
48
+ out.push({
49
+ rule: 'config.salts', severity: 'error', category: 'security', message: 'The secret keys in wp-config.php are missing, short or still the default.',
50
+ hint: 'Generate new ones at https://api.wordpress.org/secret-key/1.1/salt/ and paste them in.', location: FILE,
51
+ });
52
+ }
53
+ if (!isOn(define('DISALLOW_FILE_EDIT'))) {
54
+ out.push({
55
+ rule: 'config.file-edit', severity: 'info', category: 'security', message: 'The theme and plugin editor in the dashboard is on.',
56
+ hint: "Add define( 'DISALLOW_FILE_EDIT', true ); to wp-config.php.", location: FILE,
57
+ });
58
+ }
59
+ return out;
60
+ }
61
+ const names = (dir) => {
62
+ try {
63
+ return readdirSync(dir, { withFileTypes: true }).filter((e) => e.isFile()).map((e) => e.name).sort();
64
+ }
65
+ catch {
66
+ return [];
67
+ }
68
+ };
69
+ function uploadsPhp(root, dir, out) {
70
+ let entries;
71
+ try {
72
+ entries = readdirSync(path.join(root, dir), { withFileTypes: true });
73
+ }
74
+ catch {
75
+ return;
76
+ }
77
+ for (const e of entries.sort((a, b) => (a.name < b.name ? -1 : 1))) {
78
+ const rel = `${dir}/${e.name}`;
79
+ if (e.isDirectory())
80
+ uploadsPhp(root, rel, out);
81
+ else if (e.isFile() && /\.(php|phtml|phar)$/i.test(e.name)) {
82
+ if (e.name.toLowerCase() === 'index.php' && statSync(path.join(root, rel)).size < 100)
83
+ continue;
84
+ out.push(rel);
85
+ }
86
+ }
87
+ }
88
+ export const config = {
89
+ id: 'config',
90
+ title: 'Configuration and risky files',
91
+ kinds: ['install'],
92
+ depth: 'quick',
93
+ async run({ target, note }) {
94
+ const root = target.path;
95
+ const out = [];
96
+ const cfg = path.join(root, 'wp-config.php');
97
+ if (!existsSync(cfg)) {
98
+ note('No wp-config.php in this folder. Its settings were not checked.');
99
+ }
100
+ else {
101
+ out.push(...configFindings(readFileSync(cfg, 'utf8')));
102
+ if (process.platform !== 'win32' && statSync(cfg).mode & 0o002) {
103
+ out.push({ rule: 'config.writable', severity: 'error', category: 'security', message: 'Every user on the machine can write to wp-config.php.', hint: 'Set its mode to 640 or 600.', location: FILE });
104
+ }
105
+ }
106
+ const dump = /\.sql(\.gz|\.zip)?$/i;
107
+ const add = (rule, severity, message, hint, file) => out.push({ rule, severity, category: 'security', message, hint, location: { file } });
108
+ for (const n of names(root)) {
109
+ if (/^wp-config.*\.(bak|old|save|orig|txt|swp)$|^wp-config\.php~$/i.test(n))
110
+ add('leftover.config-copy', 'error', 'A copy of wp-config.php that a web server can send as plain text.', 'Delete it or move it out of the web folder.', n);
111
+ else if (dump.test(n))
112
+ add('leftover.dump', 'error', 'A database dump in a web folder.', 'Delete it or move it out of the web folder.', n);
113
+ else if (/^(phpinfo|info|adminer|installer|installer-backup)\.php$/i.test(n))
114
+ add('leftover.tool', 'warning', 'A setup or debug tool left in the web folder.', 'Delete it.', n);
115
+ else if (n === '.env')
116
+ add('leftover.env', 'warning', 'An .env file in the web folder.', 'Move it above the web folder or block it in the server config.', n);
117
+ }
118
+ for (const n of names(path.join(root, 'wp-content'))) {
119
+ if (dump.test(n))
120
+ add('leftover.dump', 'error', 'A database dump in a web folder.', 'Delete it or move it out of the web folder.', `wp-content/${n}`);
121
+ }
122
+ if (existsSync(path.join(root, 'wp-content', 'debug.log'))) {
123
+ add('leftover.debug-log', 'warning', 'wp-content/debug.log is readable from the web unless the server blocks it.', 'Delete it and turn off WP_DEBUG_LOG, or move the log.', 'wp-content/debug.log');
124
+ }
125
+ const php = [];
126
+ uploadsPhp(root, 'wp-content/uploads', php);
127
+ for (const file of php.slice(0, 50)) {
128
+ add('uploads.php', 'error', 'A PHP file in the uploads folder.', 'Uploads should hold media only. Check the file: malware often hides here.', file);
129
+ }
130
+ if (php.length > 50)
131
+ note(`${php.length} PHP files are in the uploads folder. The report lists the first 50.`);
132
+ return out;
133
+ },
134
+ };
@@ -0,0 +1,10 @@
1
+ import type { Engine, Target } from '../types.ts';
2
+ /** Turns a glob into a RegExp that matches a POSIX relative path. Supports **, *, ? and {a,b}. */
3
+ export declare function globToRegExp(glob: string): RegExp;
4
+ /** The files of the target as POSIX paths relative to its folder. */
5
+ export declare function walk(target: Target): {
6
+ root: string;
7
+ files: string[];
8
+ };
9
+ /** The checks in <home>/checks as engines. With a target, only the checks whose `paths` fit it. */
10
+ export declare function customEngines(target?: Target): Engine[];