Skip to content

[SPIKE]: Evaluate libinjection for broader SQL injection detection in sql_sanitizer #139

Description

@lucarlig

Summary

Investigate whether the Rust libinjection crate can provide broader, better-tested SQL injection detection for cpex-sql-sanitizer than the plugin's current custom regex and character-state heuristics.

This is a time-boxed evaluation with a go/no-go recommendation. It must not assume that every current check should be replaced.

Context

PR #133 introduced the Rust-backed SQL sanitizer from #130. Its current detection path includes:

  • configurable regexes for blocked statements;
  • custom comment stripping, literal masking, and statement splitting;
  • custom checks for DELETE/UPDATE without WHERE;
  • heuristics for likely string interpolation.

These checks address both SQL injection and organization policy. libinjection provides SQLi tokenization/fingerprinting, so it may improve injection coverage, but it may not replace explicit policy checks such as blocking DDL or WHERE-less mutations.

Investigation scope

  • Add a minimal prototype that calls libinjection::sqli from the Rust core, without committing to a production migration.
  • Compare the prototype with the current detector using:
    • all existing sql_sanitizer regression tests;
    • a representative corpus of SQLi payloads, evasions, comments/encodings, and multiple SQL dialects;
    • benign parameterized and non-parameterized SQL to measure false positives;
    • multi-statement SQL and quoted/commented edge cases.
  • Record false positives, false negatives, and cases where the two detectors disagree.
  • Determine how a libinjection detection and fingerprint would map to the existing plugin result/metadata contract without emitting raw SQL or other sensitive input.
  • Identify which current checks must remain as separate policy controls even if libinjection is adopted.
  • Benchmark detection latency and throughput against the current implementation using the existing Criterion benchmark structure.
  • Evaluate supply-chain and build implications:
    • the crate wraps the C libinjection implementation and uses build-time bindings;
    • compatibility with this repository's pure-Rust plugin requirement;
    • Linux/macOS and supported wheel/CI targets;
    • bindgen/libclang or native-toolchain requirements;
    • license compatibility, upstream maintenance, release cadence, advisories, and cargo deny/cargo audit results;
    • binary size and packaging impact.
  • Review the crate's current docs.rs build failure and determine whether it predicts a build or maintenance risk for CPEX.

Deliverables

  • A small prototype or documented build blocker.
  • A reproducible comparison corpus and results table.
  • A concise decision record recommending one of:
    1. adopt libinjection as the primary SQLi signal while retaining explicit policy checks;
    2. use libinjection as an additional signal alongside the current detector;
    3. do not adopt it, with evidence and a better alternative or follow-up direction.
  • Follow-up implementation issue(s) if adoption is recommended.

Acceptance criteria

  • The prototype is exercised from the Rust core against the comparison corpus.
  • Existing sanitizer behavior is categorized as injection detection versus policy enforcement.
  • Accuracy differences and notable false positives/negatives are documented with reproducible test cases.
  • Criterion results compare representative safe and malicious inputs.
  • CI, wheel, native-toolchain, licensing, security, maintenance, and pure-Rust-policy impacts are documented.
  • The result/metadata integration is specified and contains no raw SQL.
  • A clear go/no-go recommendation and migration scope are recorded.
  • Any production change includes focused regression tests, documentation updates, and the required plugin version bump.

References

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions