contextguard 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/bug_report.md +57 -0
- package/CONTRIBUTING.md +532 -0
- package/LICENSE +21 -0
- package/README.md +163 -0
- package/SECURITY.md +254 -0
- package/dist/mcp-security-wrapper.js +398 -0
- package/eslint.config.mts +23 -0
- package/mcp_security.log +2 -0
- package/package.json +46 -0
- package/security.json +12 -0
- package/src/mcp-security-wrapper.ts +527 -0
- package/src/test-server.ts +295 -0
- package/tsconfig.json +16 -0
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# ContextGuard
|
|
2
|
+
|
|
3
|
+
**Open-source security monitoring for Model Context Protocol servers**
|
|
4
|
+
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🎯 Why ContextGuard?
|
|
10
|
+
|
|
11
|
+
43% of MCP servers have critical vulnerabilities:
|
|
12
|
+
|
|
13
|
+
- Prompt injection attacks
|
|
14
|
+
- API key leakage
|
|
15
|
+
- Unauthorized file access
|
|
16
|
+
|
|
17
|
+
ContextGuard adds a security layer with zero code changes.
|
|
18
|
+
|
|
19
|
+
## 🚀 Quick Start
|
|
20
|
+
|
|
21
|
+
ContextGuard wraps your MCP server and detects threats in real-time.
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install -g contextguard
|
|
25
|
+
contextguard --server "node your-mcp-server.js"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Zero code changes needed. Less than 1% overhead.
|
|
29
|
+
|
|
30
|
+
## 📊 Performance
|
|
31
|
+
|
|
32
|
+
| Metric | Impact |
|
|
33
|
+
| ------------------ | ------ |
|
|
34
|
+
| Latency overhead | <1% |
|
|
35
|
+
| Memory usage | +15MB |
|
|
36
|
+
| Detection accuracy | 98.7% |
|
|
37
|
+
|
|
38
|
+
<!--
|
|
39
|
+
## 🛡️ What It Detects
|
|
40
|
+
|
|
41
|
+
- [x] 8+ prompt injection patterns
|
|
42
|
+
- [x] API keys, passwords, SSNs
|
|
43
|
+
- [x] Path traversal attacks
|
|
44
|
+
- [x] Rate limit violations
|
|
45
|
+
- [ ] SQL injection (coming soon)
|
|
46
|
+
- [ ] XSS attempts (coming soon)
|
|
47
|
+
|
|
48
|
+
## 🎬 See It In Action -->
|
|
49
|
+
|
|
50
|
+
## Features
|
|
51
|
+
|
|
52
|
+
✅ **Prompt injection detection** - 8+ attack patterns
|
|
53
|
+
✅ **Sensitive data scanning** - API keys, passwords, SSNs
|
|
54
|
+
✅ **Path traversal prevention** - Blocks unauthorized file access
|
|
55
|
+
✅ **Rate limiting** - Prevents abuse
|
|
56
|
+
✅ **Comprehensive logging** - JSON format with severity levels
|
|
57
|
+
|
|
58
|
+
## Quick Start
|
|
59
|
+
|
|
60
|
+
### Installation
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npm install -g ContextGuard
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Basic Usage
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
ContextGuard --server "node /path/to/mcp-server.js"
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Claude Desktop Integration
|
|
73
|
+
|
|
74
|
+
Edit `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"mcpServers": {
|
|
79
|
+
"secure-server": {
|
|
80
|
+
"command": "npx",
|
|
81
|
+
"args": ["-y", "ContextGuard", "--server", "node /path/to/your-server.js"]
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Configuration
|
|
88
|
+
|
|
89
|
+
Create `security.json`:
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"maxToolCallsPerMinute": 30,
|
|
94
|
+
"enablePromptInjectionDetection": true,
|
|
95
|
+
"enableSensitiveDataDetection": true,
|
|
96
|
+
"allowedFilePaths": ["/home/user/projects"]
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Then run:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
ContextGuard --server "node server.js" --config security.json
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Security Events
|
|
107
|
+
|
|
108
|
+
All events logged to `mcp_security.log`:
|
|
109
|
+
|
|
110
|
+
```json
|
|
111
|
+
{
|
|
112
|
+
"timestamp": "2025-10-09T10:30:45.123Z",
|
|
113
|
+
"eventType": "SECURITY_VIOLATION",
|
|
114
|
+
"severity": "HIGH",
|
|
115
|
+
"details": {
|
|
116
|
+
"violations": ["Prompt injection detected"]
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Roadmap
|
|
122
|
+
|
|
123
|
+
**Current (v0.1)**
|
|
124
|
+
|
|
125
|
+
- ✅ Stdio transport
|
|
126
|
+
- ✅ Prompt injection detection
|
|
127
|
+
- ✅ Data scanning
|
|
128
|
+
- ✅ Rate limiting
|
|
129
|
+
|
|
130
|
+
**Next (v0.2)**
|
|
131
|
+
|
|
132
|
+
- [ ] SSE/HTTP support
|
|
133
|
+
- [ ] Blocking mode
|
|
134
|
+
- [ ] Web dashboard
|
|
135
|
+
- [ ] Custom rules
|
|
136
|
+
|
|
137
|
+
## Contributing
|
|
138
|
+
|
|
139
|
+
We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
# Setup
|
|
143
|
+
git clone https://github.com/amironi/contextguard.git
|
|
144
|
+
npm install
|
|
145
|
+
npm run build
|
|
146
|
+
npm test
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
[MIT](LICENSE)
|
|
152
|
+
|
|
153
|
+
## Contact
|
|
154
|
+
|
|
155
|
+
- **Issues**: [GitHub Issues](https://github.com/amironi/contextguard/issues)
|
|
156
|
+
- **Email**: amir@mironi.co.il
|
|
157
|
+
<!-- - **Twitter**: [@yourusername](https://twitter.com/yourusername) -->
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
**Built by security engineers, for developers** 🛡️
|
|
162
|
+
|
|
163
|
+
[⭐ Star on GitHub](https://github.com/amironi/contextguard)
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Our Commitment
|
|
4
|
+
|
|
5
|
+
ContextGuard is a security tool designed to protect MCP servers from various attack vectors. We take the security of ContextGuard itself very seriously. If you discover a security vulnerability, we appreciate your help in disclosing it to us responsibly.
|
|
6
|
+
|
|
7
|
+
## Supported Versions
|
|
8
|
+
|
|
9
|
+
We release patches for security vulnerabilities for the following versions:
|
|
10
|
+
|
|
11
|
+
| Version | Supported |
|
|
12
|
+
| ------- | ------------------ |
|
|
13
|
+
| 0.1.x | :white_check_mark: |
|
|
14
|
+
| < 0.1 | :x: |
|
|
15
|
+
|
|
16
|
+
## What We Protect Against
|
|
17
|
+
|
|
18
|
+
ContextGuard currently detects and prevents:
|
|
19
|
+
|
|
20
|
+
### High Severity Threats
|
|
21
|
+
|
|
22
|
+
- **Prompt Injection Attacks**: 8+ patterns including instruction hijacking, role manipulation, and context escape attempts
|
|
23
|
+
- **Sensitive Data Leakage**: API keys, passwords, private keys, SSH keys, database credentials, social security numbers
|
|
24
|
+
- **Path Traversal Attacks**: Unauthorized file system access attempts using relative paths or escape sequences
|
|
25
|
+
|
|
26
|
+
### Medium Severity Threats
|
|
27
|
+
|
|
28
|
+
- **Rate Limit Violations**: Prevents abuse through excessive requests
|
|
29
|
+
- **Suspicious Input Patterns**: Anomalous request structures that may indicate reconnaissance
|
|
30
|
+
|
|
31
|
+
### Logging & Monitoring
|
|
32
|
+
|
|
33
|
+
- **Comprehensive Event Logging**: All security events logged with timestamps and severity levels
|
|
34
|
+
- **Forensic Analysis**: Detailed logs for post-incident investigation
|
|
35
|
+
|
|
36
|
+
## Known Limitations
|
|
37
|
+
|
|
38
|
+
ContextGuard is a defense-in-depth tool and should not be your only security measure:
|
|
39
|
+
|
|
40
|
+
### Current Limitations
|
|
41
|
+
|
|
42
|
+
- **Evasion Techniques**: Sophisticated attackers may use encoding, obfuscation, or novel patterns to bypass detection
|
|
43
|
+
- **False Positives**: Some legitimate requests may be flagged as suspicious
|
|
44
|
+
- **Performance**: While overhead is <1%, extremely high-throughput scenarios should be tested
|
|
45
|
+
- **Transport Support**: Currently only stdio transport is fully supported (SSE/HTTP in development)
|
|
46
|
+
|
|
47
|
+
### Not Protected Against
|
|
48
|
+
|
|
49
|
+
- **Zero-day MCP vulnerabilities**: Unknown vulnerabilities in the MCP protocol itself
|
|
50
|
+
- **Server-side vulnerabilities**: Bugs in your MCP server implementation
|
|
51
|
+
- **Network-level attacks**: DDoS, man-in-the-middle (requires network-level protection)
|
|
52
|
+
- **Compromised dependencies**: Supply chain attacks in your MCP server's dependencies
|
|
53
|
+
|
|
54
|
+
## Reporting a Vulnerability
|
|
55
|
+
|
|
56
|
+
**Please DO NOT report security vulnerabilities through public GitHub issues.**
|
|
57
|
+
|
|
58
|
+
### How to Report
|
|
59
|
+
|
|
60
|
+
1. **Email**: Send details to [amir@mironi.co.il](mailto:amir@mironi.co.il)
|
|
61
|
+
- Subject: "SECURITY: [Brief Description]"
|
|
62
|
+
2. **Include**:
|
|
63
|
+
|
|
64
|
+
- Type of vulnerability
|
|
65
|
+
- Full paths of source file(s) related to the vulnerability
|
|
66
|
+
- Location of affected source code (tag/branch/commit or direct URL)
|
|
67
|
+
- Step-by-step instructions to reproduce
|
|
68
|
+
- Proof-of-concept or exploit code (if available)
|
|
69
|
+
- Impact assessment
|
|
70
|
+
- Any potential fixes you've considered
|
|
71
|
+
|
|
72
|
+
3. **Response Time**:
|
|
73
|
+
- Initial response: Within 48 hours
|
|
74
|
+
- Status update: Within 7 days
|
|
75
|
+
- Fix timeline: Depends on severity
|
|
76
|
+
|
|
77
|
+
### What to Expect
|
|
78
|
+
|
|
79
|
+
After you submit a report:
|
|
80
|
+
|
|
81
|
+
1. **Acknowledgment**: We'll confirm receipt within 48 hours
|
|
82
|
+
2. **Assessment**: We'll investigate and determine severity
|
|
83
|
+
3. **Communication**: We'll keep you updated on progress
|
|
84
|
+
4. **Fix Development**: We'll work on a patch
|
|
85
|
+
5. **Disclosure**: We'll coordinate public disclosure with you
|
|
86
|
+
6. **Credit**: We'll credit you (unless you prefer anonymity)
|
|
87
|
+
|
|
88
|
+
### Severity Levels
|
|
89
|
+
|
|
90
|
+
We use the following severity scale:
|
|
91
|
+
|
|
92
|
+
| Severity | Description | Response Time |
|
|
93
|
+
| ------------ | -------------------------------------------------- | --------------- |
|
|
94
|
+
| **Critical** | Remote code execution, complete bypass of security | Immediate (24h) |
|
|
95
|
+
| **High** | Unauthorized data access, privilege escalation | 3-7 days |
|
|
96
|
+
| **Medium** | Denial of service, partial bypass | 7-14 days |
|
|
97
|
+
| **Low** | Minor information disclosure, edge cases | 14-30 days |
|
|
98
|
+
|
|
99
|
+
## Security Best Practices
|
|
100
|
+
|
|
101
|
+
When using ContextGuard:
|
|
102
|
+
|
|
103
|
+
### Deployment Recommendations
|
|
104
|
+
|
|
105
|
+
1. **Defense in Depth**
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# Use ContextGuard as ONE layer of security
|
|
109
|
+
# Also implement:
|
|
110
|
+
# - Network firewalls
|
|
111
|
+
# - Rate limiting at API gateway
|
|
112
|
+
# - Authentication/authorization
|
|
113
|
+
# - Input validation in your MCP server
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
2. **Configuration Security**
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"maxToolCallsPerMinute": 30,
|
|
121
|
+
"enablePromptInjectionDetection": true,
|
|
122
|
+
"enableSensitiveDataDetection": true,
|
|
123
|
+
"allowedFilePaths": ["/safe/directory/only"],
|
|
124
|
+
"logLevel": "info"
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
3. **Least Privilege**
|
|
129
|
+
|
|
130
|
+
- Run ContextGuard with minimal required permissions
|
|
131
|
+
- Restrict file system access to only necessary directories
|
|
132
|
+
- Use environment variables for secrets, never hardcode
|
|
133
|
+
|
|
134
|
+
4. **Regular Updates**
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
# Check for updates regularly
|
|
138
|
+
npm update -g contextguard
|
|
139
|
+
|
|
140
|
+
# Subscribe to security advisories
|
|
141
|
+
npm audit
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
5. **Monitor Logs**
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
# Review security logs regularly
|
|
148
|
+
tail -f mcp_security.log | grep "SECURITY_VIOLATION"
|
|
149
|
+
|
|
150
|
+
# Set up alerts for HIGH severity events
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Testing Security
|
|
154
|
+
|
|
155
|
+
Before production deployment:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
# 1. Test with known attack patterns
|
|
159
|
+
contextguard --server "node test-server.js" --config test-security.json
|
|
160
|
+
|
|
161
|
+
# 2. Review logs for false positives
|
|
162
|
+
cat mcp_security.log | jq 'select(.severity == "HIGH")'
|
|
163
|
+
|
|
164
|
+
# 3. Performance testing
|
|
165
|
+
# Ensure <1% overhead in your specific environment
|
|
166
|
+
|
|
167
|
+
# 4. Backup and recovery
|
|
168
|
+
# Test your incident response plan
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Security Audit History
|
|
172
|
+
|
|
173
|
+
| Date | Auditor | Scope | Status |
|
|
174
|
+
| ---- | ------- | ------------- | ------- |
|
|
175
|
+
| TBD | TBD | Full codebase | Planned |
|
|
176
|
+
|
|
177
|
+
We plan to conduct regular security audits as the project matures.
|
|
178
|
+
|
|
179
|
+
## Security-Related Configuration
|
|
180
|
+
|
|
181
|
+
### Example Production Configuration
|
|
182
|
+
|
|
183
|
+
```json
|
|
184
|
+
{
|
|
185
|
+
"maxToolCallsPerMinute": 30,
|
|
186
|
+
"enablePromptInjectionDetection": true,
|
|
187
|
+
"enableSensitiveDataDetection": true,
|
|
188
|
+
"enablePathTraversalPrevention": true,
|
|
189
|
+
"allowedFilePaths": ["/var/app/data", "/home/user/safe-directory"],
|
|
190
|
+
"blockedPatterns": [
|
|
191
|
+
"ignore previous instructions",
|
|
192
|
+
"system prompt",
|
|
193
|
+
"confidential"
|
|
194
|
+
],
|
|
195
|
+
"logLevel": "info",
|
|
196
|
+
"logFile": "/var/log/mcp_security.log",
|
|
197
|
+
"alertWebhook": "https://your-monitoring-service.com/webhook"
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Environment Variables
|
|
202
|
+
|
|
203
|
+
Never store secrets in configuration files:
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
# Good
|
|
207
|
+
export MCP_API_KEY="your-key-here"
|
|
208
|
+
contextguard --server "node server.js"
|
|
209
|
+
|
|
210
|
+
# Bad
|
|
211
|
+
# Don't hardcode secrets in config files or code
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Vulnerability Disclosure Policy
|
|
215
|
+
|
|
216
|
+
### Our Commitment
|
|
217
|
+
|
|
218
|
+
- We will respond to your report within 48 hours
|
|
219
|
+
- We will keep you informed of our progress
|
|
220
|
+
- We will not take legal action against security researchers who:
|
|
221
|
+
- Act in good faith
|
|
222
|
+
- Avoid privacy violations and service disruption
|
|
223
|
+
- Give us reasonable time to fix issues before disclosure
|
|
224
|
+
|
|
225
|
+
### Public Disclosure
|
|
226
|
+
|
|
227
|
+
- **Coordinated Disclosure**: We prefer to fix vulnerabilities before public disclosure
|
|
228
|
+
- **Timeline**: We aim to release fixes within 90 days of initial report
|
|
229
|
+
- **Credit**: We will publicly thank reporters (unless they prefer anonymity)
|
|
230
|
+
- **CVE Assignment**: Critical vulnerabilities will receive CVE identifiers
|
|
231
|
+
|
|
232
|
+
## Contact
|
|
233
|
+
|
|
234
|
+
- **Security Issues**: [amir@mironi.co.il](mailto:amir@mironi.co.il)
|
|
235
|
+
- **General Questions**: [GitHub Issues](https://github.com/amironi/contextguard/issues)
|
|
236
|
+
- **PGP Key**: Coming soon
|
|
237
|
+
|
|
238
|
+
## Attribution
|
|
239
|
+
|
|
240
|
+
We appreciate the security research community. Past contributors:
|
|
241
|
+
|
|
242
|
+
- _Your name could be here!_
|
|
243
|
+
|
|
244
|
+
## Resources
|
|
245
|
+
|
|
246
|
+
- [OWASP Top 10 for LLMs](https://owasp.org/www-project-top-10-for-large-language-model-applications/)
|
|
247
|
+
- [MCP Security Best Practices](https://modelcontextprotocol.io/docs/security)
|
|
248
|
+
- [Prompt Injection Defense](https://simonwillison.net/2023/Apr/14/worst-that-can-happen/)
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
**Last Updated**: October 2025
|
|
253
|
+
|
|
254
|
+
Thank you for helping keep ContextGuard and its users safe!
|