Skip to content

fix(mcp): use standalone flag matching to prevent false positives#1152

Open
algojogacor wants to merge 1 commit into
nextlevelbuilder:mainfrom
algojogacor:fix/mcp-arg-validation-standalone-flags
Open

fix(mcp): use standalone flag matching to prevent false positives#1152
algojogacor wants to merge 1 commit into
nextlevelbuilder:mainfrom
algojogacor:fix/mcp-arg-validation-standalone-flags

Conversation

@algojogacor
Copy link
Copy Markdown

This is an independent contribution from an open-source contributor.

Summary

Fix false positive in MCP argument validation where package names containing -c (like clickup-cli) are incorrectly rejected as dangerous patterns.

Root Cause

ValidateArgs() in internal/mcp/validation.go used strings.Contains for all dangerous patterns. This caused -c to match inside -cli, triggering false positives for npm packages like clickup-cli, mcp-cli, etc.

Fix

Split dangerousArgPatterns into two categories:

  • dangerousFlagPatterns (-c, -e, -r, --eval, --require, --import): matched using new isStandaloneFlag() helper that checks for exact match or flag=value form, avoiding substring false positives
  • dangerousCodePatterns (exec(, eval(, __import__, child_process, subprocess): continue using strings.Contains for code injection patterns that should be caught anywhere

Testing

  • All existing tests pass — flag patterns like -c, -e, --eval still correctly rejected
  • Package names like clickup-cli, @clickup-cli, mcp-cli no longer trigger false positives
  • Merged flag+value forms like -c"code", -e=script, --eval=code still correctly rejected

Closes #1027

Previously ValidateArgs used strings.Contains for all dangerous patterns,
causing legitimate package names like 'clickup-cli' to be rejected because
they contain '-c' as a substring of '-cli'.

Split dangerous patterns into:
- dangerousFlagPatterns: matched as standalone flags only (exact or flag=value)
- dangerousCodePatterns: matched by substring for code injection patterns

Closes nextlevelbuilder#1027
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant