Repository navigation
test(security): expand fuzz, SQL-injection, traversal, and privacy boundary coverage (#997) - #1092
Conversation
…undary coverage Adds five high-leverage test families covering the remaining gaps from issue #997, plus a real FTS5 escape fix the SQL-injection property turned up. Problem ------- * tests/fuzz/ existed but had no documented invocation, seed-corpus policy, or structural check that the libFuzzer wiring stays alive. * polylogue/storage/ had no static guard against future f-string SQL drift; reviewers had to remember to grep on every change. * ConversationFilter inputs (the single funnel for CLI/MCP/API user text) had no property-level injection coverage. * sanitize_path had unit tests but no Hypothesis sweep for unicode/control-byte/symlink bypasses. * Secret-leak prevention relied on review discipline; no static scan caught logger/print calls that interpolated api_key/auth_token. Solution -------- * tests/fuzz/README.md documents invocation, seed-corpus policy, and failure-promotion process. tests/unit/sources/test_fuzz_targets_executable.py asserts every documented Atheris target stays importable and the README catalog stays in sync. * tests/unit/storage/test_no_string_interpolated_sql.py parses polylogue/storage/ and flags any execute() call whose first arg is an f-string, %-format, str.format, or `+`-concat, unless the interpolated value is one of a small audited identifier-shaped names set (placeholders, table_name, schema_version, savepoint counters, ...). All currently-safe sites pass via the trusted-name mechanism; the audited-sites whitelist is empty. * tests/property/test_sql_injection_boundary.py drives a sentinel-loaded archive through ConversationFilter.contains/title/tag/provider with Hypothesis-generated injection payloads and asserts no SQL error leaks, sentinels survive, and result counts stay bounded. * tests/property/test_path_traversal_boundary.py hammers sanitize_path with traversal segments, absolute paths, NUL/control bytes, unicode tricks, and symlink parents; asserts totality, scrub-token shape, and no traversal/control-byte leakage. * tests/unit/security/test_no_secret_leak_in_logs.py walks every logger/print call in polylogue/ and flags interpolation of names like api_key, auth_token, password, Bearer-prefixed literals. * tests/unit/security/test_sentinel_env_leak.py sets a sentinel value on secret-shaped env vars and probes the CLI; asserts the value never surfaces in stdout, stderr, or default log output. Security fix (from property test) --------------------------------- The contains() property tripped on `../etc/passwd`: escape_fts5_query treated `.`, `/`, and `?` as non-special, so FTS5 raised `sqlite3.OperationalError: fts5: syntax error near "."`. Added those three characters to `_FTS5_SPECIAL`; punctuation now round-trips as a quoted literal. Updated two tests that pinned the old buggy behavior as expected: * tests/infra/adversarial_cases.py: `test?` and `?` now compile. * tests/unit/storage/test_hybrid.py: removed the `pytest.raises(sqlite3.OperationalError)` block; the same inputs are now part of the safe-queries list. CHANGELOG.md records the user-visible escape fix under Security. Pre-existing failures (not in scope) ------------------------------------ `devtools verify` shows three pre-existing unit failures on master tip c31d0d2 (verified by stashing this branch and re-running): * tests/unit/ui/test_ui_visual.py::TestGoldenMarkdownRendering::test_attachments_formatted_as_links * tests/property/test_filter_chain_laws.py::test_adding_filter_never_increases_count * tests/property/test_filter_chain_laws.py::test_filter_application_order_is_commutative These predate this branch and are unrelated to the security/test slice. Verification ------------ * `pytest tests/property/test_sql_injection_boundary.py tests/property/test_path_traversal_boundary.py tests/fuzz tests/unit/storage tests/unit/security tests/unit/sources/test_fuzz_targets_executable.py` — 835 passed. * `devtools verify --quick` — exit 0, total 20s. * `devtools verify --seed-testmon --skip-slow` — 6982 passed, 3 failed (all pre-existing on master, listed above). Ref #997 Ref #1060 Co-Authored-By: Claude <[email protected]>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (11)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 589db6e6dd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
Adds five high-leverage test families that close the remaining boundary
gaps in #997, plus a real FTS5 escape fix that the new SQL-injection
property turned up.
tests/fuzz/README.md,tests/unit/sources/test_fuzz_targets_executable.pytests/unit/storage/test_no_string_interpolated_sql.pypolylogue/storage/for unsafe interpolation, trusted-name allowlisttests/property/test_sql_injection_boundary.pyConversationFilter.contains/title/tag/provideragainst sentinel-loaded archivetests/property/test_path_traversal_boundary.pysanitize_pathwith traversal/absolute/control/unicode/symlink inputstests/unit/security/test_no_secret_leak_in_logs.py,tests/unit/security/test_sentinel_env_leak.pyProblem
tests/fuzz/shipped Atheris targets but had no documented invocation,seed-corpus policy, or guard against silent target deletion.
polylogue/storage/had no static gate against future f-string SQLdrift; reviewers had to remember to grep on every change.
ConversationFilteris the single funnel for CLI/MCP/API user text,but no property test fuzzed it with SQL/FTS injection payloads.
sanitize_pathhad unit tests but no Hypothesis sweep for unicode,control-byte, or symlink-parent bypasses.
caught a future
logger.debug("loaded token %s", api_key).Solution
tests/fuzz/README.mddocuments pytest andlibFuzzer modes, seed corpus layout (
.local/fuzz-corpus/), and thefailure-promotion workflow.
test_fuzz_targets_executable.pyassertsevery documented target stays callable and the README catalog stays in
sync; renaming or deleting a target fails the unit suite.
test_no_string_interpolated_sql.pyparsesevery
polylogue/storage/*.pyfile, flags anyexecute()/executemany()/executescript()whose first arg is an f-string,%-format,str.format, or+-concat. A small_TRUSTED_IDENTIFIER_NAMESallowlist covers the closed-set patterns(
placeholders,table_name,schema_version, savepoint counters,helper-built
where_clauses/scope_clausefragments). Allcurrently-safe sites pass via the allowlist;
_AUDITED_SITESisempty.
test_sql_injection_boundary.pyloads asmall archive with sentinel rows, then Hypothesis-fuzzes
ConversationFilter.contains/title/tag/providerwith 30 classicinjection payloads plus arbitrary unicode text (
max_examples=40).Asserts no exception leaks, sentinels survive, and result counts stay
bounded.
test_path_traversal_boundary.pyhammers
sanitize_pathwith traversal segments, absolute paths,NUL/control bytes, RTL/LTR/NBSP unicode tricks, and a real
filesystem symlink parent. Asserts totality, scrub-token shape
(
_blocked_<12hex>), and no traversal/control-byte leakage.test_no_secret_leak_in_logs.pywalks everylogger.<level>/printcall inpolylogue/and flags anypositional/kwarg or f-string interpolation that references a
secret-shaped name (api_key, auth_token, password, …) or a literal
prefix (Bearer , api_key=, token=, …).
test_sentinel_env_leak.pysets a sentinelon
POLYLOGUE_TEST_SENTINEL_TOKENand conventional secret env names,then invokes the CLI with both well-formed and malformed commands;
asserts the value never appears in stdout, stderr, or default
logger output.
Security fix turned up by the property test
The new
test_contains_never_raises_sql_errorimmediately failed on../etc/passwdwithsqlite3.OperationalError: fts5: syntax error near ".". Root cause:_FTS5_SPECIALinpolylogue/storage/search/query_support.pydid not include.,/,or
?, so path-like and?-wildcard inputs bypassed quoting andreached FTS5 as raw syntax.
Fix: added
.,/,?to the special-character regex. Punctuationnow round-trips as a quoted literal, error gone. Updated two existing
tests that pinned the buggy behavior as the contract:
tests/infra/adversarial_cases.py—test?and?now compilerather than producing FTS5 errors.
tests/unit/storage/test_hybrid.py::test_fts_search_special_characters— removed the
pytest.raises(sqlite3.OperationalError)block;punctuation queries are part of the safe-queries list.
CHANGELOG.mdrecords the user-visible fix under Security.Pre-existing failures (not in scope)
devtools verifyshows three unit failures on master tipc31d0d20,verified by stashing this branch and re-running:
tests/unit/ui/test_ui_visual.py::TestGoldenMarkdownRendering::test_attachments_formatted_as_linkstests/property/test_filter_chain_laws.py::test_adding_filter_never_increases_counttests/property/test_filter_chain_laws.py::test_filter_application_order_is_commutativeUnrelated to the security/test slice; flagged so a follow-up can pick
them up.
Verification
Ref #997
Ref #1060