Skip to content

Commit 56afd4c

Browse files
committed
Address CodeRabbit: sanitize STDERR logs, drop IPv6 host chars
CodeRabbit review on PR #31: 1. Log injection (setup/generate.php:43,49): the pre-validation values for host/port were written straight to STDERR, so a proxyList.txt line containing a newline could forge fake log entries in downstream log aggregation. Wrap both with rawurlencode() so any control chars and newlines are escaped before being printed. 2. Misleading IPv6 support (setup/generate.php:42): the host regex allowed ':' / '[' / ']', suggesting "[::1]:8080:..." would work, but the naive explode(":", $line, 5) parser splits IPv6 literals incorrectly. Tighten the regex to "[A-Za-z0-9._-]" so IPv6-looking entries are now rejected with a clear error instead of silently malformed, matching the parser's actual capability.
1 parent d770435 commit 56afd4c

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

setup/generate.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,19 @@
3737
continue;
3838
}
3939

40-
// Validate host: hostname or IPv4/IPv6 literal. No shell/conf metachars.
40+
// Validate host: hostname or IPv4 literal. No shell/conf metachars.
41+
// IPv6 literals are not supported: the naive explode(":") parser above
42+
// cannot split "[::1]:8080:..." correctly, so ':' / '[' / ']' are rejected
43+
// to avoid giving the impression that IPv6 is accepted.
4144
if (preg_match($reject_unsafe, $proxyInfo['host']) ||
42-
!preg_match('/^[A-Za-z0-9.:\[\]_-]+$/', $proxyInfo['host'])) {
43-
fwrite(STDERR, "Skipping proxy with invalid host: " . $proxyInfo['host'] . PHP_EOL);
45+
!preg_match('/^[A-Za-z0-9._-]+$/', $proxyInfo['host'])) {
46+
fwrite(STDERR, "Skipping proxy with invalid host: " . rawurlencode($proxyInfo['host']) . PHP_EOL);
4447
continue;
4548
}
4649
// Validate port: 1-65535.
4750
if (!ctype_digit((string)$proxyInfo['port']) ||
4851
(int)$proxyInfo['port'] < 1 || (int)$proxyInfo['port'] > 65535) {
49-
fwrite(STDERR, "Skipping proxy with invalid port: " . $proxyInfo['port'] . PHP_EOL);
52+
fwrite(STDERR, "Skipping proxy with invalid port: " . rawurlencode((string)$proxyInfo['port']) . PHP_EOL);
5053
continue;
5154
}
5255
// Validate credentials: no whitespace/control chars/quotes/backslash/#.

0 commit comments

Comments
 (0)