fix(analytics): replace the control-character class with a code-point scan (no-control-regex)
CI (SIAX Cloud) / quality (push) Successful in 45s
CI (SIAX Cloud) / integration (push) Successful in 34s
CI (SIAX Cloud) / security (push) Successful in 19s
Security Scan (SIAX Cloud) / security (push) Successful in 17s
CI (SIAX Cloud) / quality (pull_request) Successful in 45s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 27s
CI (SIAX Cloud) / security (pull_request) Successful in 37s
CI (SIAX Cloud) / integration (pull_request) Successful in 45s
CI (SIAX Cloud) / quality (push) Successful in 45s
CI (SIAX Cloud) / integration (push) Successful in 34s
CI (SIAX Cloud) / security (push) Successful in 19s
Security Scan (SIAX Cloud) / security (push) Successful in 17s
CI (SIAX Cloud) / quality (pull_request) Successful in 45s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 27s
CI (SIAX Cloud) / security (pull_request) Successful in 37s
CI (SIAX Cloud) / integration (pull_request) Successful in 45s
The ASCII-only check used a regex character class of control characters. It tripped eslint's no-control-regex, which the repo's quality gate enforces — and the rule has a point: such a class is unreadable and is exactly the kind of expression a reviewer nods at without checking. Same behaviour, written as an explicit scan naming the permitted set. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -377,13 +377,21 @@ export function guardAnalystStatement(sql: string, opts: StatementGuardOptions):
|
||||
// Homoglyphs, zero-width joiners and RTL overrides stop being expressible
|
||||
// against the keyword scan. Values are unaffected: they live in literals,
|
||||
// which have already been removed at this point.
|
||||
const nonAscii = /[^\x09\x0a\x0d\x20-\x7e]/.exec(stripped);
|
||||
if (nonAscii) {
|
||||
deny(
|
||||
`statement contains a non-ASCII character (U+${nonAscii[0].codePointAt(0)?.toString(16).padStart(4, '0')}) outside a string literal`,
|
||||
);
|
||||
// Written as a code-point scan rather than a character class: a regex of
|
||||
// control characters is unreadable, trips `no-control-regex`, and is the
|
||||
// kind of expression a reviewer nods at without checking. Permitted: tab,
|
||||
// LF, CR and printable ASCII. Everything else, NUL included, is refused.
|
||||
for (let i = 0; i < stripped.length; i += 1) {
|
||||
const code = stripped.charCodeAt(i);
|
||||
const printable = code >= 0x20 && code <= 0x7e;
|
||||
const allowedWhitespace = code === 0x09 || code === 0x0a || code === 0x0d;
|
||||
if (!printable && !allowedWhitespace) {
|
||||
deny(
|
||||
`statement contains a disallowed character (U+${code.toString(16).toUpperCase().padStart(4, '0')}) ` +
|
||||
`outside a string literal`,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (stripped.includes('\0')) deny('statement contains a NUL byte');
|
||||
|
||||
// ── exactly one statement ──────────────────────────────────────────────
|
||||
const withoutTrailingSemi = stripped.replace(/;\s*$/, '');
|
||||
|
||||
Reference in New Issue
Block a user