Skip to main content

Rust-backed secrets detection plugin for MCP Gateway

Project description

Secrets Detection (Rust)

Rust-backed secrets detection and redaction for ContextForge and MCP Gateway.

Features

  • Detects likely credentials in prompt arguments, tool inputs, tool outputs, and resource content
  • Built-in detectors for AWS keys, Google API keys, GitHub tokens, Stripe keys, Slack tokens, and private key blocks
  • Optional broad detectors for generic API key assignments, JWT-like strings, long hex strings, and base64-like secrets
  • Blocking, redaction, or metadata-only reporting modes
  • Recursive scanning for nested dicts, lists, tuples, Pydantic-style objects, __dict__, and __slots__
  • Sanitized outward metadata that reports finding types and counts, not original secret values

Build

make install

Runtime Requirements

This plugin depends on cpex>=0.1.0,<0.2 and imports hook models from cpex.framework. The compiled Rust extension is mandatory; there is no Python fallback implementation.

Usage

The plugin scans these hooks:

  • prompt_pre_fetch: scans payload.args
  • tool_pre_invoke: scans tool invocation payloads before execution
  • tool_post_invoke: scans payload.result
  • resource_post_fetch: scans payload.content.text

Typical uses:

  • block requests that contain likely credentials before they reach tools or prompts
  • redact secrets from returned tool or resource payloads
  • surface sanitized findings metadata for observability and tuning

Detection Coverage

Enabled by default:

  • aws_access_key_id
  • aws_secret_access_key
  • google_api_key
  • github_token
  • stripe_secret_key
  • slack_token
  • private_key_block

Disabled by default because they are broader and more false-positive-prone:

  • generic_api_key_assignment
  • jwt_like
  • hex_secret_32
  • base64_24

The detectors are regex-based. They do not verify whether a credential is real, active, or revoked.

Configuration

config:
  enabled:
    aws_access_key_id: true
    aws_secret_access_key: true
    google_api_key: true
    github_token: true
    stripe_secret_key: true
    slack_token: true
    private_key_block: true
    generic_api_key_assignment: false
    jwt_like: false
    hex_secret_32: false
    base64_24: false
  redact: false
  redaction_text: "***REDACTED***"
  block_on_detection: true
  min_findings_to_block: 1
Field Type Default Description
enabled dict built-in defaults Per-detector enable flags; unspecified detectors inherit defaults
redact bool false Replace matched secret values in returned payloads
redaction_text string "***REDACTED***" Replacement text used when redact=true
block_on_detection bool true Return a violation when enough findings are present
min_findings_to_block integer 1 Minimum finding count required before blocking

Behavior Notes

  • Redaction preserves payload shape where possible instead of flattening everything to plain dicts.
  • base64_24 uses capture-group redaction so leading non-base64 boundary characters are preserved.
  • Broad detectors remain opt-in to reduce noisy matches on ordinary identifiers.
  • Binary resource bodies are not scanned; resource_post_fetch only scans text content exposed as payload.content.text.
  • The plugin does not decode archives, compressed data, or arbitrary encoded blobs before scanning.

Returned Metadata

When detections occur, the plugin can emit:

  • metadata.count
  • metadata.secrets_redacted=true when redaction happened
  • metadata.secrets_findings=[{"type": "..."}] when reporting findings without redaction

Blocking responses use the SECRETS_DETECTED violation code.

Security Notes

  • Outward-facing findings metadata and violation examples do not include original matched secret values.
  • Enable broad detectors only after testing against representative payloads.
  • The detector is best-effort pattern matching and should complement, not replace, upstream secret management controls.

Testing

make ci

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cpex_secrets_detection-0.3.6.tar.gz (46.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cpex_secrets_detection-0.3.6-cp311-abi3-win_amd64.whl (760.0 kB view details)

Uploaded CPython 3.11+Windows x86-64

cpex_secrets_detection-0.3.6-cp311-abi3-manylinux_2_34_x86_64.whl (832.8 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.34+ x86-64

cpex_secrets_detection-0.3.6-cp311-abi3-manylinux_2_34_s390x.whl (867.3 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.34+ s390x

cpex_secrets_detection-0.3.6-cp311-abi3-manylinux_2_34_ppc64le.whl (858.4 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.34+ ppc64le

cpex_secrets_detection-0.3.6-cp311-abi3-manylinux_2_34_aarch64.whl (777.9 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.34+ ARM64

cpex_secrets_detection-0.3.6-cp311-abi3-macosx_11_0_arm64.whl (734.6 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

Details for the file cpex_secrets_detection-0.3.6.tar.gz.

File metadata

  • Download URL: cpex_secrets_detection-0.3.6.tar.gz
  • Upload date:
  • Size: 46.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cpex_secrets_detection-0.3.6.tar.gz
Algorithm Hash digest
SHA256 bfd857242f78a4f06a785d6e92cf26907771b27096a41436fc2aa5c6f19d9ceb
MD5 b6e3bdba52d710e9287b37bf7893701f
BLAKE2b-256 d27e18560d51e59e015b4f53bf3d62348770593be438dc17a116f7cab670c474

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpex_secrets_detection-0.3.6.tar.gz:

Publisher: release-rust-python-package.yaml on IBM/cpex-plugins

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpex_secrets_detection-0.3.6-cp311-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for cpex_secrets_detection-0.3.6-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c6a77f2105d27146b1808eabbf73c5be71620c44206b47583b5af021003c66b3
MD5 04cb6f3139d6a33d6e10a63607c2c1ad
BLAKE2b-256 617319aea512989040a6fc436e56604872a1b5911725f9a8c0d9885453750b98

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpex_secrets_detection-0.3.6-cp311-abi3-win_amd64.whl:

Publisher: release-rust-python-package.yaml on IBM/cpex-plugins

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpex_secrets_detection-0.3.6-cp311-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for cpex_secrets_detection-0.3.6-cp311-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2f8389f697e3306fb2975335e658c115b2e05f162f5921c584ce773328399c63
MD5 ef0eb02595e69dfd2a9035f101e58d4c
BLAKE2b-256 94446a3d4e31cf9ff8065ed74bb8933e3ffb61b9e6c34ddc2825053a01fe1ab8

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpex_secrets_detection-0.3.6-cp311-abi3-manylinux_2_34_x86_64.whl:

Publisher: release-rust-python-package.yaml on IBM/cpex-plugins

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpex_secrets_detection-0.3.6-cp311-abi3-manylinux_2_34_s390x.whl.

File metadata

File hashes

Hashes for cpex_secrets_detection-0.3.6-cp311-abi3-manylinux_2_34_s390x.whl
Algorithm Hash digest
SHA256 79a7101b9d2d1f609ce37f7b7a33bf45f86016be2866037005eeaeeca5825aee
MD5 157ef703b7e8375d8722701326f69720
BLAKE2b-256 96884cf5c878a5501896892a7f3db369f68ddc503910cd9951fcf41e29471bca

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpex_secrets_detection-0.3.6-cp311-abi3-manylinux_2_34_s390x.whl:

Publisher: release-rust-python-package.yaml on IBM/cpex-plugins

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpex_secrets_detection-0.3.6-cp311-abi3-manylinux_2_34_ppc64le.whl.

File metadata

File hashes

Hashes for cpex_secrets_detection-0.3.6-cp311-abi3-manylinux_2_34_ppc64le.whl
Algorithm Hash digest
SHA256 5410563d2f5eccdf317d5d3595e0cdf9e2d9615eacdfa969f911f2c0a63df0fd
MD5 e55f20643e4dc1c57b5f197df20a20c3
BLAKE2b-256 ea13f083a12b820cec83f7649131f995de8c512a4156e46e567e0f7b403ccce5

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpex_secrets_detection-0.3.6-cp311-abi3-manylinux_2_34_ppc64le.whl:

Publisher: release-rust-python-package.yaml on IBM/cpex-plugins

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpex_secrets_detection-0.3.6-cp311-abi3-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for cpex_secrets_detection-0.3.6-cp311-abi3-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 11e751b9c0f4dcc4b4f8536ed2860d0ab7c4651b1e28847faa09ec1b7ea9221a
MD5 37a3de8cdfecab8ac02d91e2157b3a62
BLAKE2b-256 bc81702d6c3b25f8ac214550710d49aeab084408fd8ff38ad143607fd04e2813

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpex_secrets_detection-0.3.6-cp311-abi3-manylinux_2_34_aarch64.whl:

Publisher: release-rust-python-package.yaml on IBM/cpex-plugins

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpex_secrets_detection-0.3.6-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cpex_secrets_detection-0.3.6-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 94e780bb544ee34430735d31854c221783d8173b56f1174f5655415c5fdc898b
MD5 9254a6d639bd872925b9e2e96753fa4b
BLAKE2b-256 53ebfe649eccd13549fb98d13d2fee8ecdd702a5199741e0bd6c094a1ad0c6a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpex_secrets_detection-0.3.6-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: release-rust-python-package.yaml on IBM/cpex-plugins

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page