Skip to content

test(security): expand fuzz, SQL-injection, traversal, and privacy boundary coverage (#997) - #1092

Merged
Sinity merged 1 commit into
masterfrom
feature/test/security-and-boundary-coverage
May 16, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/test/security-and-boundary-coverage

Conversation

@Sinity

@Sinity Sinity commented May 16, 2026

Copy link
Copy Markdown
Owner

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.

Family Files Mechanism
Fuzz campaign promotion tests/fuzz/README.md, tests/unit/sources/test_fuzz_targets_executable.py docs + structural import + libFuzzer-wiring check
SQL/FTS injection (static) tests/unit/storage/test_no_string_interpolated_sql.py AST scan of polylogue/storage/ for unsafe interpolation, trusted-name allowlist
SQL/FTS injection (runtime) tests/property/test_sql_injection_boundary.py Hypothesis fuzz of ConversationFilter.contains/title/tag/provider against sentinel-loaded archive
Path traversal (runtime) tests/property/test_path_traversal_boundary.py Hypothesis fuzz of sanitize_path with traversal/absolute/control/unicode/symlink inputs
Privacy / secret leak tests/unit/security/test_no_secret_leak_in_logs.py, tests/unit/security/test_sentinel_env_leak.py AST scan of logger/print calls + runtime sentinel env var probed against CLI

Problem

  • 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 SQL
    drift; reviewers had to remember to grep on every change.
  • ConversationFilter is the single funnel for CLI/MCP/API user text,
    but no property test fuzzed it with SQL/FTS injection payloads.
  • sanitize_path had unit tests but no Hypothesis sweep for unicode,
    control-byte, or symlink-parent bypasses.
  • Secret leak prevention relied entirely on review discipline; nothing
    caught a future logger.debug("loaded token %s", api_key).

Solution

  • Fuzz targets — tests/fuzz/README.md documents pytest and
    libFuzzer modes, seed corpus layout (.local/fuzz-corpus/), and the
    failure-promotion workflow. test_fuzz_targets_executable.py asserts
    every documented target stays callable and the README catalog stays in
    sync; renaming or deleting a target fails the unit suite.
  • SQL injection static — test_no_string_interpolated_sql.py parses
    every polylogue/storage/*.py file, flags any execute() /
    executemany() / executescript() whose first arg is an f-string,
    %-format, str.format, or +-concat. A small
    _TRUSTED_IDENTIFIER_NAMES allowlist covers the closed-set patterns
    (placeholders, table_name, schema_version, savepoint counters,
    helper-built where_clauses/scope_clause fragments). All
    currently-safe sites pass via the allowlist; _AUDITED_SITES is
    empty.
  • SQL injection runtime — test_sql_injection_boundary.py loads a
    small archive with sentinel rows, then Hypothesis-fuzzes
    ConversationFilter.contains/title/tag/provider with 30 classic
    injection payloads plus arbitrary unicode text (max_examples=40).
    Asserts no exception leaks, sentinels survive, and result counts stay
    bounded.
  • Path traversal runtime — test_path_traversal_boundary.py
    hammers sanitize_path with 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.
  • Secret leak static — test_no_secret_leak_in_logs.py walks every
    logger.<level> / print call in polylogue/ and flags any
    positional/kwarg or f-string interpolation that references a
    secret-shaped name (api_key, auth_token, password, …) or a literal
    prefix (Bearer , api_key=, token=, …).
  • Secret leak runtime — test_sentinel_env_leak.py sets a sentinel
    on POLYLOGUE_TEST_SENTINEL_TOKEN and 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_error immediately failed on
../etc/passwd with sqlite3.OperationalError: fts5: syntax error near ".". Root cause: _FTS5_SPECIAL in
polylogue/storage/search/query_support.py did not include ., /,
or ?, so path-like and ?-wildcard inputs bypassed quoting and
reached FTS5 as raw syntax.

Fix: added ., /, ? to the special-character regex. Punctuation
now 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 compile
    rather 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.md records the user-visible fix under Security.

Pre-existing failures (not in scope)

devtools verify shows three unit failures on master tip c31d0d20,
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

Unrelated to the security/test slice; flagged so a follow-up can pick
them up.

Verification

nix develop -c pytest tests/unit/security tests/property tests/unit/storage \
  tests/unit/sources -v -k "fuzz or injection or traversal or secret or leak"
# 153 passed in 11s

nix develop -c 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 in 16s

nix develop -c devtools verify --quick
# exit_code: 0, total_duration_s: 20.05

nix develop -c devtools verify --seed-testmon --skip-slow
# 6982 passed, 3 failed (all pre-existing on master, listed above)

Ref #997
Ref #1060

…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]>
@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 43 minutes and 13 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 09b87d47-c771-4d38-a205-213e15eb2c14

📥 Commits

Reviewing files that changed from the base of the PR and between c31d0d2 and 589db6e.

📒 Files selected for processing (11)
  • CHANGELOG.md
  • polylogue/storage/search/query_support.py
  • tests/fuzz/README.md
  • tests/infra/adversarial_cases.py
  • tests/property/test_path_traversal_boundary.py
  • tests/property/test_sql_injection_boundary.py
  • tests/unit/security/test_no_secret_leak_in_logs.py
  • tests/unit/security/test_sentinel_env_leak.py
  • tests/unit/sources/test_fuzz_targets_executable.py
  • tests/unit/storage/test_hybrid.py
  • tests/unit/storage/test_no_string_interpolated_sql.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/test/security-and-boundary-coverage

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 and usage tips.

@Sinity
Sinity merged commit bfe1494 into master May 16, 2026
3 checks passed
@Sinity
Sinity deleted the feature/test/security-and-boundary-coverage branch May 16, 2026 15:16

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@Sinity

Sinity commented Sep 30, 2026

Copy link
Copy Markdown
Owner Author

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.

@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

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.

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