Skip to content

Commit 4a3f702

Browse files
committed
Add rule validation to catch invalid patterns before container startup
- convert-rule.mjs: catch errors and output clean message to stderr instead of exposing QuickJS stack traces - setup/main.mjs: validate rules via buildRules() so invalid patterns are reported as ::error:: annotations in GitHub Actions before attempting to start the container
1 parent c717dc1 commit 4a3f702

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

docker/files/tools/convert-rule.mjs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import * as std from "std";
77
import { buildRules } from "./lib/rules.mjs";
88

99
const input = std.in.readAsString();
10-
const regexRules = buildRules(input);
11-
if (regexRules.length > 0) {
12-
std.out.puts(regexRules.join("\n") + "\n");
10+
11+
try {
12+
const regexRules = buildRules(input);
13+
if (regexRules.length > 0) {
14+
std.out.puts(regexRules.join("\n") + "\n");
15+
}
16+
} catch (e) {
17+
std.err.puts(`${e.message}\n`);
18+
std.exit(1);
1319
}

setup/main.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { appendFileSync } from "node:fs";
33
import { join, dirname } from "node:path";
44
import { fileURLToPath } from "node:url";
55
import { buildLegacyRules } from "./lib/legacy-rules.mjs";
6+
import { buildRules } from "../docker/files/tools/lib/rules.mjs";
67

78
const __dirname = dirname(fileURLToPath(import.meta.url));
89
const composeFile = join(__dirname, "compose.yml");
@@ -123,10 +124,13 @@ function resolveImageTag(repository, { versionInput, actionRef }) {
123124
* @returns {{ httpsRules: string[], httpRules: string[], ipRules: string[] }}
124125
*/
125126
function buildACLRules({ httpsRulesInput, httpRulesInput, ipRulesInput, httpsDomainsInput, httpDomainsInput, httpsPortsInput, httpPortsInput }) {
126-
// New-style rules: pass through as-is (wildcard format)
127+
// New-style rules: pass through as-is (wildcard format), validate by converting to regex
127128
const httpsRules = httpsRulesInput?.trim().split(/\s+/).filter(Boolean) ?? [];
128129
const httpRules = httpRulesInput?.trim().split(/\s+/).filter(Boolean) ?? [];
129130
const ipRules = ipRulesInput?.trim().split(/\s+/).filter(Boolean) ?? [];
131+
buildRules(httpsRulesInput);
132+
buildRules(httpRulesInput);
133+
buildRules(ipRulesInput);
130134

131135
// Legacy rules (converted to wildcard format)
132136
const httpsLegacy = buildLegacyRules({

0 commit comments

Comments
 (0)