security(smell-rules): validate ScopeColumn at load time#408
Open
jamestexas wants to merge 2 commits into
Open
security(smell-rules): validate ScopeColumn at load time#408jamestexas wants to merge 2 commits into
jamestexas wants to merge 2 commits into
Conversation
External smell rules from $MACHE_SMELL_RULES_DIR are appended to the registry and their ScopeColumn value is interpolated unescaped into runSmellRule's SQL (`"AND " + rule.ScopeColumn + " = ?"`). The trust boundary is operator-controlled, so this isn't a vulnerability — but the cost of a load-time whitelist is one regex-shaped check and the value is "a typo or malicious external rule can't smuggle a `;` terminator, `--` line comment, or unexpected characters into the SQL composition path." Whitelist mirrors the character set the built-in ScopeColumn values actually use (identifiers, `.`, `,`, `(`, `)`, `'`, space) — proven by TestValidateScopeColumn_AcceptsBuiltinShapes which iterates the registry. Rejection coverage in TestValidateScopeColumn_RejectsInjectionShapes spans `;`, `--`, `/*`, `*`, `=`, backtick, double-quote, newline. End-to-end TestLoadExternalSmellRules_RejectsInjectableScopeColumn proves a malicious JSON rule never reaches runSmellRule.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Came out of a
/security-reviewpass over the recently-merged surface area (matrix-e2e harness, testfixtures registry, ADR-0019). The user asked twice in the prior session to make the SQL composition paths injection-safe; this is the one real hardening that came out of the audit.What it does
SmellRule.ScopeColumnfrom external$MACHE_SMELL_RULES_DIRJSON files is interpolated unescaped intorunSmellRule's SQL ("AND " + rule.ScopeColumn + " = ?"atcmd/smell_findings.go:44). The trust boundary is operator-controlled, so it's not a vulnerability today — but the cost of a load-time whitelist is one regex-shaped check and the value is "a typo or malicious external rule can't smuggle a;,--, or unexpected characters into the SQL composition path."Whitelist mirrors the character set the built-in
ScopeColumnvalues actually use (identifiers,.,,,(,),', space) — proven by a test that iterates the registry.Tests
TestValidateScopeColumn_AcceptsBuiltinShapes— iterates every built-in rule's ScopeColumn (13 today) and asserts each passes. Future contributors who tighten the whitelist past what real rules need will see this fail before merge.TestValidateScopeColumn_RejectsInjectionShapes— covers;,--,/*,*,=, backtick,", newline.TestLoadExternalSmellRules_RejectsInjectableScopeColumn— end-to-end: a malicious JSON rule withScopeColumn: "n.source_file; DROP TABLE nodes; --"is rejected by the loader and never reachesrunSmellRule.TestLoadExternalSmellRules_AcceptsBuiltinShapedScopeColumn— keeps the loader honest about accepting theCOALESCE(NULLIF(...))shape several built-ins use, so the hardening doesn't lock out reasonable external rules.Broader audit (clean, no other changes)
SQL surface — every
Sprintf-built query uses?placeholders for values; identifier interpolation is either constant or defended viaisSimpleIdent; the daemon path (leyline.SocketClient.Query, no placeholders) is escaped viaescapeLikePattern(cmd/serve_lsp.go:644).intinterpolations are%d(no syntactic injection).loadFiltered'sopinterpolation is fed only from a 2-value switch over vtab index types.Hosted-mode HTTP —
validateRepoURLalready rejects dash-prefix, non-HTTPS, embedded credentials;git clone --depth=1 --single-branchdoesn't recurse submodules. SSRF defenses (block loopback / link-local / RFC1918 in?repo=) are a follow-up I'll file when rsry is reachable again.Test plan
task testcmd/ — green (198s)