Repository navigation
fix: harden MCP security boundaries - #444
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
📝 WalkthroughWalkthroughThis PR implements the MCP security threat model and supply-chain hardening roadmap. It adds comprehensive threat documentation, hardens credential/secret redaction in share-safe artifacts, updates user-facing guidance, and validates both through extensive tests. ChangesMCP Security Threat Model and Artifact Hardening
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes The changes span security documentation, credential-redaction logic with medium complexity, user-facing guidance updates, and comprehensive test validation. The credential redaction logic is the most intricate portion, combining URL parsing, pattern matching, and sentinel-based redaction normalization. Most changes are well-scoped documentation and testing additions with consistent patterns across files, though the redaction helpers require careful review to ensure coverage of credential variants. Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/unit/share-safe-artifacts.test.ts (1)
22-26: ⚡ Quick winAdd regression cases for
apikeyandx-api-keyassignment redactionPlease extend this test to include those common credential-like forms so the sanitizer contract is locked against regressions.
✅ Suggested test extension
- it('redacts credential-like environment assignments and bearer tokens', () => { - const text = 'MADAR_TOKEN=abc123 Authorization: Bearer super-secret-value' + it('redacts credential-like environment assignments and bearer tokens', () => { + const text = 'MADAR_TOKEN=abc123 apikey=def456 x-api-key=ghi789 Authorization: Bearer super-secret-value' - expect(sanitizeShareSafeText(text, ROOTS)).toBe('MADAR_TOKEN=[REDACTED] Authorization: Bearer [REDACTED]') + expect(sanitizeShareSafeText(text, ROOTS)).toBe( + 'MADAR_TOKEN=[REDACTED] apikey=[REDACTED] x-api-key=[REDACTED] Authorization: Bearer [REDACTED]', + ) })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unit/share-safe-artifacts.test.ts` around lines 22 - 26, Update the test case that asserts sanitizeShareSafeText behavior (the "redacts credential-like environment assignments and bearer tokens" spec) to also cover assignment forms "apikey=..." and "x-api-key=..." so the sanitizer contract prevents regressions; modify the test using the same INPUT/ROOTS setup and add expectations like expect(sanitizeShareSafeText('apikey=secret123', ROOTS)).toBe('apikey=[REDACTED]') and expect(sanitizeShareSafeText('x-api-key=anotherSecret', ROOTS)).toBe('x-api-key=[REDACTED]') (or combine them into one string alongside existing tokens) referencing the sanitizeShareSafeText function and ROOTS constant so the new assertions run with existing cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/shared/share-safe-artifacts.ts`:
- Around line 46-57: The credential redaction misses names like "apikey" and
hyphenated keys (e.g. "x-api-key") because SENSITIVE_CREDENTIAL_NAME_PATTERN
doesn't include "apikey" and the name capture in redactCredentialLikeText only
allows underscores (uses ([A-Z0-9_]+)). Update SENSITIVE_CREDENTIAL_NAME_PATTERN
to include "apikey" and allow hyphens inside names (e.g. use a pattern that
permits [A-Z0-9-] around the sensitive tokens), and change the name capture in
redactCredentialLikeText from ([A-Z0-9_]+) to ([A-Z0-9_-]+) so hyphenated keys
are recognized; keep using isSensitiveCredentialName to test the normalized name
after these changes.
---
Nitpick comments:
In `@tests/unit/share-safe-artifacts.test.ts`:
- Around line 22-26: Update the test case that asserts sanitizeShareSafeText
behavior (the "redacts credential-like environment assignments and bearer
tokens" spec) to also cover assignment forms "apikey=..." and "x-api-key=..." so
the sanitizer contract prevents regressions; modify the test using the same
INPUT/ROOTS setup and add expectations like
expect(sanitizeShareSafeText('apikey=secret123',
ROOTS)).toBe('apikey=[REDACTED]') and
expect(sanitizeShareSafeText('x-api-key=anotherSecret',
ROOTS)).toBe('x-api-key=[REDACTED]') (or combine them into one string alongside
existing tokens) referencing the sanitizeShareSafeText function and ROOTS
constant so the new assertions run with existing cases.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 82503574-d2c2-4215-88f1-197d3c257a8e
📒 Files selected for processing (13)
README.mdSECURITY.mddocs/release.mddocs/security/mcp-threat-model.mdsrc/infrastructure/install-skill-templates.tssrc/infrastructure/review-compare.tssrc/shared/share-safe-artifacts.tstests/unit/install-docs.test.tstests/unit/install-templates.test.tstests/unit/mcp-threat-model-doc.test.tstests/unit/release-docs.test.tstests/unit/security.test.tstests/unit/share-safe-artifacts.test.ts
| const SENSITIVE_CREDENTIAL_NAME_PATTERN = /(?:^|[_-])(token|key|secret|password|pass|auth|authorization|signature|sig)(?:[_-]|$)/i | ||
| const REDACTION_SENTINEL = 'MADAR_SHARE_SAFE_REDACTED' | ||
|
|
||
| function isSensitiveCredentialName(name: string): boolean { | ||
| const normalized = name.trim().toLowerCase().replace(/\[\]$/, '') | ||
| return SENSITIVE_CREDENTIAL_NAME_PATTERN.test(normalized) | ||
| } | ||
|
|
||
| function redactCredentialLikeText(text: string): string { | ||
| return text | ||
| .replaceAll(/(^|[\s([{])([A-Z0-9_]+)=([^\s]+)/gim, (match, prefix: string, name: string) => | ||
| isSensitiveCredentialName(name) ? `${prefix}${name}=[REDACTED]` : match, |
There was a problem hiding this comment.
Credential matcher misses common apikey / hyphenated key forms
Line 46 and Line 56 together can leave secrets unredacted for common shapes like apikey=... and x-api-key=..., because separator matching is too strict and - is excluded from parsed key names.
🔧 Proposed fix
-const SENSITIVE_CREDENTIAL_NAME_PATTERN = /(?:^|[_-])(token|key|secret|password|pass|auth|authorization|signature|sig)(?:[_-]|$)/i
+const SENSITIVE_CREDENTIAL_NAME_PATTERN =
+ /(?:^|[_-])(token|api[_-]?key|key|secret|password|pass|auth|authorization|signature|sig)(?:[_-]|$)/i
function isSensitiveCredentialName(name: string): boolean {
- const normalized = name.trim().toLowerCase().replace(/\[\]$/, '')
+ const normalized = name
+ .trim()
+ .replace(/\[\]$/, '')
+ .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
+ .toLowerCase()
return SENSITIVE_CREDENTIAL_NAME_PATTERN.test(normalized)
}
function redactCredentialLikeText(text: string): string {
return text
- .replaceAll(/(^|[\s([{])([A-Z0-9_]+)=([^\s]+)/gim, (match, prefix: string, name: string) =>
+ .replaceAll(/(^|[\s([{])([A-Z0-9_-]+)=([^\s]+)/gim, (match, prefix: string, name: string) =>
isSensitiveCredentialName(name) ? `${prefix}${name}=[REDACTED]` : match,
)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const SENSITIVE_CREDENTIAL_NAME_PATTERN = /(?:^|[_-])(token|key|secret|password|pass|auth|authorization|signature|sig)(?:[_-]|$)/i | |
| const REDACTION_SENTINEL = 'MADAR_SHARE_SAFE_REDACTED' | |
| function isSensitiveCredentialName(name: string): boolean { | |
| const normalized = name.trim().toLowerCase().replace(/\[\]$/, '') | |
| return SENSITIVE_CREDENTIAL_NAME_PATTERN.test(normalized) | |
| } | |
| function redactCredentialLikeText(text: string): string { | |
| return text | |
| .replaceAll(/(^|[\s([{])([A-Z0-9_]+)=([^\s]+)/gim, (match, prefix: string, name: string) => | |
| isSensitiveCredentialName(name) ? `${prefix}${name}=[REDACTED]` : match, | |
| const SENSITIVE_CREDENTIAL_NAME_PATTERN = | |
| /(?:^|[_-])(token|api[_-]?key|key|secret|password|pass|auth|authorization|signature|sig)(?:[_-]|$)/i | |
| const REDACTION_SENTINEL = 'MADAR_SHARE_SAFE_REDACTED' | |
| function isSensitiveCredentialName(name: string): boolean { | |
| const normalized = name | |
| .trim() | |
| .replace(/\[\]$/, '') | |
| .replace(/([a-z0-9])([A-Z])/g, '$1_$2') | |
| .toLowerCase() | |
| return SENSITIVE_CREDENTIAL_NAME_PATTERN.test(normalized) | |
| } | |
| function redactCredentialLikeText(text: string): string { | |
| return text | |
| .replaceAll(/(^|[\s([{])([A-Z0-9_-]+)=([^\s]+)/gim, (match, prefix: string, name: string) => | |
| isSensitiveCredentialName(name) ? `${prefix}${name}=[REDACTED]` : match, |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/shared/share-safe-artifacts.ts` around lines 46 - 57, The credential
redaction misses names like "apikey" and hyphenated keys (e.g. "x-api-key")
because SENSITIVE_CREDENTIAL_NAME_PATTERN doesn't include "apikey" and the name
capture in redactCredentialLikeText only allows underscores (uses ([A-Z0-9_]+)).
Update SENSITIVE_CREDENTIAL_NAME_PATTERN to include "apikey" and allow hyphens
inside names (e.g. use a pattern that permits [A-Z0-9-] around the sensitive
tokens), and change the name capture in redactCredentialLikeText from
([A-Z0-9_]+) to ([A-Z0-9_-]+) so hyphenated keys are recognized; keep using
isSensitiveCredentialName to test the normalized name after these changes.
Summary
Test Plan
Closes #426
Summary by CodeRabbit
Documentation
New Features
Tests