Skip to content

fix: tighten secrets detection coverage and add focused benchmarking#3764

Merged
jonpspri merged 9 commits intomainfrom
chore/issue-3741-secrets-detection-aws-api-keys
Mar 28, 2026
Merged

fix: tighten secrets detection coverage and add focused benchmarking#3764
jonpspri merged 9 commits intomainfrom
chore/issue-3741-secrets-detection-aws-api-keys

Conversation

@lucarlig
Copy link
Copy Markdown
Collaborator

@lucarlig lucarlig commented Mar 20, 2026

Summary

This updates secret handling so secret-like values are owned by the dedicated secrets detection plugin instead of the PII filter, strengthens provider-specific secret coverage, improves Rust plugin logging, adds a focused Rust-vs-Python benchmarking workflow for the secrets detector, and documents the broader intrinsic-shape heuristics that can still catch longer secret-like values.

What changed

  • enabled SecretsDetection in plugins/config.yaml
  • removed AWS and API-key secret handling from the PII filter in both Python and Rust so those patterns are only handled by secrets detection
  • improved secrets detection coverage with stronger provider-specific patterns, including GitHub tokens and Stripe secret keys
  • kept broader generic API-key heuristics opt-in and documented their false-positive tradeoffs, detection limits, and the fact that longer intrinsic-shape heuristics such as base64_24 can still catch assignment-style values when the value itself looks secret-like
  • preserved safe defaults when operators provide a partial enabled: map so omitted heuristics do not silently turn back on
  • added Rust-side logging for the secrets detection plugin via pyo3_log
  • improved Python fallback logging so Rust scan failures preserve full exception context
  • added a focused Locust scenario for secret detection at tests/loadtest/locustfile_secret_detection.py
  • added make load-test-secret-detection-compare and tests/loadtest/run_secret_detection_compare.sh to compare the Rust-backed and forced Python fallback paths on the same focused workload
  • added targeted gitleaks:allow annotations to intentional secret-shaped test fixtures in the Python and Rust secrets detection tests and the focused secret-detection Locust file so secret scanning stays clean without changing detector behavior
  • updated secrets detection and PII filter docs to clarify ownership, warnings, capabilities, and limits

Validation

  • uv run pytest tests/unit/plugins/test_secrets_detection.py
  • cargo test in plugins_rust/secrets_detection
  • cargo test in plugins_rust/pii_filter
  • make rust-check
  • focused gitleaks detect --no-git scans for tests/unit/plugins/test_secrets_detection.py, plugins_rust/secrets_detection/src, and tests/loadtest/locustfile_secret_detection.py
  • make test
  • live /rpc verification against the compose UI stack with the Rust plugin enabled for blocking and redaction scenarios

End-to-End Benchmark

Focused secret-detection benchmark using the new Locust scenario against the full compose stack:

  • aggregate throughput: Rust 252.32 RPS vs Python 236.70 RPS (+6.2%)
  • aggregate average latency: Rust 333.33 ms vs Python 358.22 ms (-7.5%)
  • aggregate p95 latency: Rust 520 ms vs Python 580 ms (-11.5%)
  • aggregate p99 latency: Rust 590 ms vs Python 760 ms (-28.8%)

Per-request-type improvements from the same focused run:

  • clean prompt requests: Rust 125.44 RPS vs Python 118.04 RPS
  • secret-blocked prompt requests: Rust 126.88 RPS vs Python 118.65 RPS

Closes #3741

@lucarlig lucarlig force-pushed the chore/issue-3741-secrets-detection-aws-api-keys branch 2 times, most recently from d632d0e to a3cf96f Compare March 20, 2026 13:48
@crivetimihai crivetimihai added this to the Release 1.1.0 milestone Mar 20, 2026
@crivetimihai crivetimihai added enhancement New feature or request plugins security Improves security rust Rust programming SHOULD P2: Important but not vital; high-value items that are not crucial for the immediate release labels Mar 20, 2026
@crivetimihai
Copy link
Copy Markdown
Member

Thanks @lucarlig. Good separation of concerns — moving secret patterns out of PII filter into the dedicated secrets detection plugin. Benchmark results show solid Rust improvement (~7% latency, ~29% at p99).

@lucarlig lucarlig modified the milestones: Release 1.1.0, Release 1.0.0 Mar 23, 2026
@lucarlig
Copy link
Copy Markdown
Collaborator Author

we will be using rust plugin for 1.0

@lucarlig lucarlig added the wxo wxo integration label Mar 23, 2026
@lucarlig lucarlig force-pushed the chore/issue-3741-secrets-detection-aws-api-keys branch 2 times, most recently from 5078f2f to e00c6e1 Compare March 23, 2026 10:48
@lucarlig lucarlig added MUST P1: Non-negotiable, critical requirements without which the product is non-functional or unsafe release-fix Critical bugfix required for the release and removed SHOULD P2: Important but not vital; high-value items that are not crucial for the immediate release labels Mar 23, 2026
@lucarlig lucarlig force-pushed the chore/issue-3741-secrets-detection-aws-api-keys branch from dcc2d48 to eceae89 Compare March 24, 2026 09:22
dima-zakharov
dima-zakharov previously approved these changes Mar 24, 2026
Copy link
Copy Markdown
Collaborator

@dima-zakharov dima-zakharov left a comment

Choose a reason for hiding this comment

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

Looks good

@lucarlig lucarlig force-pushed the chore/issue-3741-secrets-detection-aws-api-keys branch from eceae89 to ae63d74 Compare March 24, 2026 13:45
@lucarlig lucarlig requested a review from Lang-Akshay March 25, 2026 10:34
@lucarlig lucarlig force-pushed the chore/issue-3741-secrets-detection-aws-api-keys branch 5 times, most recently from f610059 to 38ccb4f Compare March 25, 2026 14:25
@lucarlig lucarlig requested a review from dima-zakharov March 26, 2026 09:12
dima-zakharov
dima-zakharov previously approved these changes Mar 26, 2026
Copy link
Copy Markdown
Collaborator

@dima-zakharov dima-zakharov left a comment

Choose a reason for hiding this comment

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

all blocking issues resolved. Broad heuristics like generic_api_key_assignment are properly disabled by default with clear warnings when enabled.
Recommendation
Ready to merge

@lucarlig lucarlig removed the release-fix Critical bugfix required for the release label Mar 26, 2026
@lucarlig
Copy link
Copy Markdown
Collaborator Author

lucarlig commented Mar 26, 2026

removed release-fix label blocked by #3860 and #3840

@lucarlig lucarlig force-pushed the chore/issue-3741-secrets-detection-aws-api-keys branch from 38ccb4f to 1e7fc30 Compare March 27, 2026 14:51
@jonpspri jonpspri force-pushed the chore/issue-3741-secrets-detection-aws-api-keys branch from 2cfeca1 to cd6bde9 Compare March 28, 2026 19:33
jonpspri
jonpspri previously approved these changes Mar 28, 2026
Copy link
Copy Markdown
Collaborator

@jonpspri jonpspri left a comment

Choose a reason for hiding this comment

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

Review Summary

Clean separation of concerns — secret-style credential detection (AWS keys, API keys) is properly moved from the PII filter into the dedicated secrets_detection plugin. New provider-specific patterns (GitHub tokens, Stripe secret keys, generic API key assignment) are well-tested with both positive and negative cases across Python and Rust.

Key Positives

  • Secure defaults: is_enabled() now defaults to false (was true), and all broad heuristic patterns (jwt_like, hex_secret_32, base64_24, generic_api_key_assignment) default to disabled in code — matching the documented opt-in behavior. Production config.yaml explicitly enables the ones needed.
  • Config merging: The _merge_enabled_patterns field validator prevents partial YAML configs from silently enabling broad heuristics.
  • Python/Rust parity: All 11 patterns and their defaults are in sync across both implementations.
  • Test coverage: 221 Python tests and 59 Rust secrets_detection tests pass, covering new patterns, config edge cases, Rust log bridge, fallback exception logging, and broad-pattern warnings.
  • Rust logging: pyo3-log bridge gives operators visibility into Rust-side scan behavior without separate log infrastructure.

Minor Notes (non-blocking)

  • The e2e test changes (test_mcp_session_isolation.py, test_mcp_access_matrix.py, mcp_test_helpers.py, fuzz/conftest.py) are tangential to secrets detection — consider splitting in future PRs for cleaner history.
  • Linters (ruff, bandit, cargo test, bash -n) all clean on changed files.

@jonpspri jonpspri force-pushed the chore/issue-3741-secrets-detection-aws-api-keys branch from cd6bde9 to 301cd05 Compare March 28, 2026 20:01
lucarlig and others added 9 commits March 28, 2026 20:10
Signed-off-by: lucarlig <luca.carlig@ibm.com>
Signed-off-by: lucarlig <luca.carlig@ibm.com>
Signed-off-by: lucarlig <luca.carlig@ibm.com>
Signed-off-by: lucarlig <luca.carlig@ibm.com>
Signed-off-by: lucarlig <luca.carlig@ibm.com>
Signed-off-by: lucarlig <luca.carlig@ibm.com>
Signed-off-by: lucarlig <luca.carlig@ibm.com>
The detection and redaction paths in the Python secrets plugin used
different defaults for unknown patterns (False vs True), which could
cause redaction of patterns that were never detected.  Extract an
is_enabled() method on both the Python and Rust config classes so the
safe default (disabled) is defined in exactly one place.

Also commits config.yaml changes that align with the code:
- remove stale detect_aws_keys / detect_api_keys from PII filter config
- set SecretsDetection mode to disabled (opt-in, not enforced by default)
- default unknown patterns to disabled in Rust scanner

Signed-off-by: Jonathan Springer <jps@s390x.com>
CLAUDE.md and DEVELOPING.md only listed Python linters in their
"before committing" sections. Add make rust-check so developers
and AI agents run clippy -D warnings before pushing Rust changes.

Signed-off-by: Jonathan Springer <jps@s390x.com>
@jonpspri jonpspri force-pushed the chore/issue-3741-secrets-detection-aws-api-keys branch from 301cd05 to 8ad9c32 Compare March 28, 2026 20:29
@jonpspri jonpspri merged commit fc2b75e into main Mar 28, 2026
34 checks passed
@jonpspri jonpspri deleted the chore/issue-3741-secrets-detection-aws-api-keys branch March 28, 2026 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request MUST P1: Non-negotiable, critical requirements without which the product is non-functional or unsafe plugins rust Rust programming security Improves security wxo wxo integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TESTING][PLUGINS]: Validate and harden secrets detection plugin

4 participants