Skip to content

docs(agents): record the dual-reading invariant, correct the EXPLAIN tx claim - #63

Merged
KARTIKrocks merged 2 commits into
mainfrom
docs/agents-redaction-invariants
Sep 24, 2026
Merged

KARTIKrocks merged 2 commits into
mainfrom
docs/agents-redaction-invariants

Conversation

@KARTIKrocks

Copy link
Copy Markdown
Owner

Summary

What does this PR change, and why?

Two gaps in the guidance file, both security-relevant.

The redaction paragraph still described Redact as handling "single-quoted string + numeric literals". It now also covers backslash escapes, Postgres dollar-quoted strings including non-ASCII tags, and hex/binary numerics, and it deliberately leaves double-quoted runs as identifiers (issue #62).

More importantly, nothing recorded that Redact and IsMultiStatement scan under more than one dialect reading, or why neither may be collapsed to a single pass. AGENTS.md already protects driver.go's optional interfaces with an explicit "do not simplify these away"; the same protection was missing here, and three separate bypasses were introduced during PR #61 by exactly that kind of simplification. The new paragraph states both fail-safe directions, names a payload each reading is blind to, and points at the two tests that pin them.

The EXPLAIN paragraph claimed every plan runs in BeginTx(ReadOnly:true) for "Postgres and MySQL". explain.go:243 is ReadOnly:!dml — MySQL and MariaDB reject every statement inside a read-only transaction (error 1792), so the --allow-dml path is read-write. That predates PR #61, but it is the fact the separator check's whole rationale depends on: an agent trusting the old wording would conclude a missed separator is harmless. Corrected, with the consequence spelled out, and the trailing "read-only tx" in the same paragraph fixed to match.

Claims verified against analyzer/redact.go and explain/explain.go.

Closes #

Type of change

  • Bug fix
  • New detection rule
  • New integration / parser
  • Feature / enhancement
  • Docs only
  • Refactor / chore

Checklist

  • make ci passes (fmt-check, vet, lint, vuln, test-race, lint-docs) across all modules
  • Added/updated tests (and, where practical, a failure-mode check)
  • Updated docs under website/docs/ with a version marker for anything new (_0.3+_, _Added in 0.3._, // 0.3+) — never website/versioned_docs/
  • Updated AGENTS.md / .sqlguard.example.yml if a convention or config key changed
  • Added an entry under ## [Unreleased] in CHANGELOG.md
  • No new third-party deps in analyzer / middleware / reporter
  • Findings stay redaction-safe (no raw literals leak into a Result)

Notes for reviewers

Anything reviewers should focus on — tricky areas, trade-offs, follow-ups.

…tx claim

Two gaps in the guidance file, both security-relevant.

The redaction paragraph still described Redact as handling "single-quoted
string + numeric literals". It now also covers backslash escapes, Postgres
dollar-quoted strings including non-ASCII tags, and hex/binary numerics, and
it deliberately leaves double-quoted runs as identifiers (issue #62).

More importantly, nothing recorded that Redact and IsMultiStatement scan
under more than one dialect reading, or why neither may be collapsed to a
single pass. AGENTS.md already protects driver.go's optional interfaces with
an explicit "do not simplify these away"; the same protection was missing
here, and three separate bypasses were introduced during PR #61 by exactly
that kind of simplification. The new paragraph states both fail-safe
directions, names a payload each reading is blind to, and points at the two
tests that pin them.

The EXPLAIN paragraph claimed every plan runs in BeginTx(ReadOnly:true) for
"Postgres and MySQL". explain.go:243 is ReadOnly:!dml — MySQL and MariaDB
reject every statement inside a read-only transaction (error 1792), so the
--allow-dml path is read-write. That predates PR #61, but it is the fact the
separator check's whole rationale depends on: an agent trusting the old
wording would conclude a missed separator is harmless. Corrected, with the
consequence spelled out, and the trailing "read-only tx" in the same
paragraph fixed to match.

Claims verified against analyzer/redact.go and explain/explain.go.
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Repository: KARTIKrocks/sqlguard/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 439065d3-6379-4c5a-ae20-3d117c3ab933


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no outstanding finding or new actionable issue remains.

Summary

The PR documents the distinct dialect readings used by redaction and multi-statement detection, corrects the EXPLAIN transaction guidance, and adds corresponding reviewer rules. No new actionable issue was identified.

Reviews (2) · Last reviewed commit: "docs: correct the ambiguity axes, teach ..."

Comment thread AGENTS.md Outdated
…ariant

AGENTS.md said both Redact and IsMultiStatement scan under multiple readings
of both the backslash and the "$$" question. They do not: literalSpans calls
scanDollarQuoted unconditionally, so both of Redact's passes recognise dollar
quotes and differ only on backslash escapes, while blankLiterals' flag is
dollarQuotes and IsMultiStatement never honors backslash escapes at all. Each
function scans twice over a *different* axis. The text now says which, and
why Redact needs no second "$$" reading: honoring one can only add a redact
span, so that ambiguity has no leak direction.

The bot configs had a scope blind spot that matches where the bugs actually
landed. Both .greptile/config.json and .coderabbit.yaml protect the
multi-statement guard under explain/**, but IsMultiStatement lives in
analyzer/redact.go and its blanker in analyzer/fallback.go — all three
bypasses in PR #61 were edits to analyzer/, outside the scope of the rule
meant to catch them. Added a dual-reading-lexer rule scoped to those two
files, extended the coderabbit analyzer/** instructions to match, and wrote
the three bugs up as a worked example in .greptile/rules.md, which exists for
exactly that.

Worth noting both bot configs already documented BeginTx(ReadOnly: !dml)
correctly — AGENTS.md was the only file that had it wrong, which the previous
commit fixed.
@KARTIKrocks
KARTIKrocks merged commit fdcbac4 into main Sep 24, 2026
27 checks passed
@KARTIKrocks
KARTIKrocks deleted the docs/agents-redaction-invariants branch September 24, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant