refactor(mcp,core): extract shared injection-detection patterns to avoid drift#1761
Merged
refactor(mcp,core): extract shared injection-detection patterns to avoid drift#1761
Conversation
…oid drift Extract the 17 injection-detection regex patterns from an inline slice inside zeph-mcp's INJECTION_PATTERNS LazyLock into a pub const RAW_INJECTION_PATTERNS. zeph-core's ContentSanitizer now builds its INJECTION_PATTERNS from that shared const instead of maintaining a separate copy. This eliminates the maintenance risk where patterns added to one sanitization layer would silently not apply to the other. Also fixes two patterns in zeph-core that were missing the (?i) flag (xml_tag_injection, markdown_image_exfil) — these had drifted from the zeph-mcp versions which carried the flag. Closes #1747
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
zeph-mcp/src/sanitize.rsinto apub const RAW_INJECTION_PATTERNS: &[(&str, &str)]zeph-core'sContentSanitizernow builds itsINJECTION_PATTERNSLazyLockfrom this shared constant instead of maintaining a duplicate listzeph-corepatterns that had drifted:xml_tag_injectionandmarkdown_image_exfilwere missing(?i)case-insensitive flags present in thezeph-mcpcopyMotivation
Both sanitization layers had independent copies of the same pattern list. Any new pattern added to one would silently not apply to the other. Now there is a single source of truth.
No new crate required —
zeph-corealready depends onzeph-mcp, so the shared constant is reachable without new dependency edges.Test plan
cargo +nightly fmt --check— cleancargo clippy --workspace --features full -- -D warnings— cleancargo nextest run --config-file .github/nextest.toml --workspace --features full --lib --bins— 5508 passedCloses #1747