Repository navigation
fix(security): skip an invalid custom pattern regex instead of panicking - #1763
Merged
Dumbris merged 1 commit intoOct 26, 2026
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Dumbris
approved these changes
Oct 26, 2026
Dumbris
left a comment
Member
There was a problem hiding this comment.
Verified: the PR test fails on main for the reason described and passes on this branch merged with main; race tests for the touched packages and CI lint (bare and server tags) are clean. Also built and tested together with the rest of this batch, independently reviewed, and cross-reviewed with a second model.
Member
|
Merged. Thank you, @rudycelekli! A malformed custom pattern regex no longer stops mcpproxy from starting. |
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.
Bug
sensitive_data_detection.custom_patterns[].regexcomes straight from the user's config file and is not validated when the config loads.buildCustomPatternpasses it toPatternBuilder.WithRegex, which usesregexp.MustCompile. One malformed regex therefore panics insidesecurity.NewDetector.NewDetectorruns at startup (runtime.go,server.go,mcp.go), on config reload (ReloadConfig), and when the credential input screen is built. A typo in the config means mcpproxy won't start at all. The validating loaderpatterns.LoadCustomPatternsexists, but it is not on this path.Trigger
Result:
panic: regexp: Compile((): error parsing regexp: missing closing ):(``Fix
In
buildCustomPattern, compile the regex withregexp.Compilefirst and drop the pattern if it is invalid. This matches how the function already drops a pattern with no name or no regex/keywords. The other custom patterns and all built-in patterns are still loaded.Test
TestNewDetector_InvalidCustomRegexIsSkippedconfigures one broken and one valid custom pattern. It asserts thatNewDetectordoes not panic and that the valid pattern still detectsTICKET-123456.Commands run
CGO_ENABLED=0 go test -count=1 ./internal/security: okgit stashofdetector.go), the new test fails withNewDetector panicked on an invalid custom regex: regexp: Compile((): error parsing regexp: missing closing ):(``.gofmt -lon the edited files: no output