-
Notifications
You must be signed in to change notification settings - Fork 2
[Experimental] Prototype Rust CPEX secrets detection integration #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c690e3b
build: add secrets detection workspace crate
gandhipratik203 8ee7bc9
fix: disable secrets detection doctests
gandhipratik203 eab703a
refactor: rename secrets detection plugin crate
gandhipratik203 da93c8e
refactor: generalize plugin feature name
gandhipratik203 32b11be
chore: ship secrets detection plugin feature
gandhipratik203 37c3a5a
ci: keep secrets e2e manual
gandhipratik203 7f79c0a
ci: run workspace checks with all features
gandhipratik203 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| [package] | ||
| name = "cpex-secrets-detection" | ||
| version.workspace = true | ||
| edition.workspace = true | ||
| rust-version.workspace = true | ||
| license.workspace = true | ||
| publish = false | ||
|
|
||
| [lib] | ||
| doctest = false | ||
|
|
||
| [dependencies] | ||
| cpex.workspace = true | ||
| regex = "1.12.3" | ||
| serde = { workspace = true, features = ["derive"] } | ||
| serde_json.workspace = true | ||
|
|
||
| [dev-dependencies] | ||
| tokio.workspace = true | ||
|
|
||
| [lints] | ||
| workspace = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # ContextForge Gateway Secrets Detection | ||
|
|
||
| Rust CPEX secrets detection plugin for the ContextForge dataplane. | ||
|
|
||
| This crate is a first-class member of the `contextforge-data-plane` workspace. | ||
| It provides the `SecretsDetectionFactory` registered by the gateway binary when | ||
| the `plugins` Cargo feature is enabled. | ||
|
dawid-nowak marked this conversation as resolved.
|
||
|
|
||
| ## Runtime Activation | ||
|
|
||
| The crate is compiled into the gateway binary. Runtime configuration still comes | ||
| from the dataplane plugin config document stored in Redis. | ||
|
|
||
| Example config: | ||
|
|
||
| ```json | ||
| { | ||
| "version": 1, | ||
| "cpex": { | ||
| "plugins": [ | ||
| { | ||
| "name": "secrets-detection", | ||
| "kind": "validator/secrets-detection", | ||
| "hooks": ["cmf.tool_pre_invoke", "cmf.tool_post_invoke"], | ||
| "config": { | ||
| "redact": true, | ||
| "redaction_text": "[redacted]", | ||
| "block_on_detection": false | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| The dataplane integration currently wires the tool-call path: | ||
|
|
||
| - `cmf.tool_pre_invoke`: scans tool arguments before the backend receives them. | ||
| - `cmf.tool_post_invoke`: scans tool results before the client receives them. | ||
|
|
||
| The crate also keeps prompt/resource stage handling for CPEX parity and future | ||
| hosts, but the current dataplane runtime config only uses the tool pre/post | ||
| hooks. | ||
|
|
||
| ## Behavior | ||
|
|
||
| The scanner detects common secret-shaped values in JSON payloads and direct text | ||
| content. Depending on config, it can: | ||
|
|
||
| - redact detected values | ||
| - deny payloads when `block_on_detection` is enabled and the threshold is met | ||
| - apply dotted field allowlists/denylists to JSON arguments and results | ||
| - emit non-sensitive metadata from direct handlers when trace context exists | ||
|
|
||
| The CPEX plugin kind is: | ||
|
|
||
| ```text | ||
| validator/secrets-detection | ||
| ``` | ||
|
|
||
| ## Known CPEX 0.2.2 Gaps | ||
|
|
||
| - `PluginResult.metadata` is not propagated through `PluginManager`. | ||
| - A denied result cannot surface a redacted payload through `PluginManager`. | ||
|
|
||
| The direct handler can return both metadata and a redacted payload on block, but | ||
| those fields are lost at the manager/executor boundary in CPEX 0.2.2. | ||
|
|
||
| ## Verification | ||
|
|
||
| From the workspace root: | ||
|
|
||
| ```bash | ||
| cargo +1.96 test -p cpex-secrets-detection | ||
| cargo +1.96 check -p contextforge-gateway-rs --features plugins | ||
| cargo +1.96 test -p contextforge-gateway-rs-cpex | ||
| cargo +1.96 test -p contextforge-gateway-rs-lib --test gateway_plugins -- --nocapture | ||
| cargo +1.96 test -p contextforge-gateway-rs --features plugins --test secrets_detection_e2e -- --ignored --nocapture | ||
| ``` | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.