Skip to content

Commit 7298d2e

Browse files
authored
Merge pull request #97 from project-codeguard/feature/add-mcp-security-rule
Add MCP (Model Context Protocol) security rule
2 parents 60b0fe5 + d3a5012 commit 7298d2e

File tree

6 files changed

+212
-9
lines changed

6 files changed

+212
-9
lines changed

.claude-plugin/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "codeguard-security",
33
"description": "Security code review skill based on Project CodeGuard's comprehensive security rules. Helps AI coding agents write secure code and prevent common vulnerabilities.",
4-
"version": "1.1.0",
4+
"version": "1.2.0",
55
"author": {
66
"name": "Project CodeGuard",
77
"url": "https://project-codeguard.org"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "project-codeguard"
3-
version = "1.1.0"
3+
version = "1.2.0"
44
description = "AI Coding Rules for Security and Best Practices"
55
requires-python = ">=3.11"
66
dependencies = [

skills/software-security/SKILL.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
name: software-security
33
description: A software security skill that integrates with Project CodeGuard to help AI coding agents write secure code and prevent common vulnerabilities. Use this skill when writing, reviewing, or modifying code to ensure secure-by-default practices are followed.
4-
codeguard-version: "1.0.1"
4+
codeguard-version: "1.1.0"
55
framework: "Project CodeGuard"
66
purpose: "Embed secure-by-default practices into AI coding workflows"
77
---
@@ -34,21 +34,22 @@ When writing or reviewing code:
3434
| cpp | codeguard-0-safe-c-functions.md |
3535
| d | codeguard-0-iac-security.md |
3636
| docker | codeguard-0-devops-ci-cd-containers.md, codeguard-0-supply-chain-security.md |
37-
| go | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-input-validation-injection.md, codeguard-0-session-management-and-cookies.md, codeguard-0-xml-and-serialization.md |
37+
| go | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-input-validation-injection.md, codeguard-0-mcp-security.md, codeguard-0-session-management-and-cookies.md, codeguard-0-xml-and-serialization.md |
3838
| html | codeguard-0-client-side-web-security.md, codeguard-0-input-validation-injection.md, codeguard-0-session-management-and-cookies.md |
39-
| java | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-framework-and-languages.md, codeguard-0-input-validation-injection.md, codeguard-0-mobile-apps.md, codeguard-0-session-management-and-cookies.md, codeguard-0-xml-and-serialization.md |
40-
| javascript | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-client-side-web-security.md, codeguard-0-cloud-orchestration-kubernetes.md, codeguard-0-data-storage.md, codeguard-0-devops-ci-cd-containers.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-framework-and-languages.md, codeguard-0-iac-security.md, codeguard-0-input-validation-injection.md, codeguard-0-logging.md, codeguard-0-mobile-apps.md, codeguard-0-privacy-data-protection.md, codeguard-0-session-management-and-cookies.md, codeguard-0-supply-chain-security.md |
39+
| java | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-framework-and-languages.md, codeguard-0-input-validation-injection.md, codeguard-0-mcp-security.md, codeguard-0-mobile-apps.md, codeguard-0-session-management-and-cookies.md, codeguard-0-xml-and-serialization.md |
40+
| javascript | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-client-side-web-security.md, codeguard-0-cloud-orchestration-kubernetes.md, codeguard-0-data-storage.md, codeguard-0-devops-ci-cd-containers.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-framework-and-languages.md, codeguard-0-iac-security.md, codeguard-0-input-validation-injection.md, codeguard-0-logging.md, codeguard-0-mcp-security.md, codeguard-0-mobile-apps.md, codeguard-0-privacy-data-protection.md, codeguard-0-session-management-and-cookies.md, codeguard-0-supply-chain-security.md |
4141
| kotlin | codeguard-0-additional-cryptography.md, codeguard-0-authentication-mfa.md, codeguard-0-framework-and-languages.md, codeguard-0-mobile-apps.md |
4242
| matlab | codeguard-0-additional-cryptography.md, codeguard-0-authentication-mfa.md, codeguard-0-mobile-apps.md, codeguard-0-privacy-data-protection.md |
4343
| perl | codeguard-0-mobile-apps.md |
4444
| php | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-client-side-web-security.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-framework-and-languages.md, codeguard-0-input-validation-injection.md, codeguard-0-session-management-and-cookies.md, codeguard-0-xml-and-serialization.md |
4545
| powershell | codeguard-0-devops-ci-cd-containers.md, codeguard-0-iac-security.md, codeguard-0-input-validation-injection.md |
46-
| python | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-framework-and-languages.md, codeguard-0-input-validation-injection.md, codeguard-0-session-management-and-cookies.md, codeguard-0-xml-and-serialization.md |
46+
| python | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-framework-and-languages.md, codeguard-0-input-validation-injection.md, codeguard-0-mcp-security.md, codeguard-0-session-management-and-cookies.md, codeguard-0-xml-and-serialization.md |
4747
| ruby | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-framework-and-languages.md, codeguard-0-iac-security.md, codeguard-0-input-validation-injection.md, codeguard-0-session-management-and-cookies.md, codeguard-0-xml-and-serialization.md |
48+
| rust | codeguard-0-mcp-security.md |
4849
| shell | codeguard-0-devops-ci-cd-containers.md, codeguard-0-iac-security.md, codeguard-0-input-validation-injection.md |
4950
| sql | codeguard-0-data-storage.md, codeguard-0-input-validation-injection.md |
5051
| swift | codeguard-0-additional-cryptography.md, codeguard-0-authentication-mfa.md, codeguard-0-mobile-apps.md |
51-
| typescript | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-client-side-web-security.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-framework-and-languages.md, codeguard-0-input-validation-injection.md, codeguard-0-session-management-and-cookies.md |
52+
| typescript | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-client-side-web-security.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-framework-and-languages.md, codeguard-0-input-validation-injection.md, codeguard-0-mcp-security.md, codeguard-0-session-management-and-cookies.md |
5253
| vlang | codeguard-0-client-side-web-security.md |
5354
| xml | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-devops-ci-cd-containers.md, codeguard-0-framework-and-languages.md, codeguard-0-mobile-apps.md, codeguard-0-xml-and-serialization.md |
5455
| yaml | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authorization-access-control.md, codeguard-0-cloud-orchestration-kubernetes.md, codeguard-0-data-storage.md, codeguard-0-devops-ci-cd-containers.md, codeguard-0-framework-and-languages.md, codeguard-0-iac-security.md, codeguard-0-logging.md, codeguard-0-privacy-data-protection.md, codeguard-0-supply-chain-security.md |
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
description: MCP (Model Context Protocol) Security based on CoSAI MCP Security guidelines
3+
languages:
4+
- python
5+
- javascript
6+
- typescript
7+
- go
8+
- rust
9+
- java
10+
alwaysApply: false
11+
---
12+
13+
rule_id: codeguard-0-mcp-security
14+
15+
# MCP (Model Context Protocol) Security Guidelines
16+
17+
NEVER deploy MCP servers or clients without implementing proper security controls.
18+
19+
### Workload Identity and Authentication
20+
- Use SPIFFE/SPIRE for cryptographic workload identities
21+
- SPIFFE (Secure Production Identity Framework For Everyone) provides a standard for service identity
22+
- SPIRE (SPIFFE Runtime Environment) issues and rotates short-lived cryptographic identities (SVIDs)
23+
24+
### Input and Data Sanitization
25+
- Validate ALL inputs using allowlists at every trust boundary
26+
- Sanitize file paths through canonicalization
27+
- Use parameterized queries for database operations
28+
- Apply context-aware output encoding (SQL, shell, HTML)
29+
- Sanitize tool outputs: return only minimum fields, redact all PII and sensitive data
30+
- Treat ALL inputs, tool schemas, metadata, prompts, and resource content as untrusted input
31+
- Deploy prompt injection detection systems
32+
- Use strict JSON schemas to maintain boundaries between instructions and data
33+
34+
### Sandboxing and Isolation
35+
- Design MCP servers to execute with least privilege
36+
- MCP servers interacting with host environment (files, commands, network) MUST implement sandboxing controls
37+
- LLM-generated code MUST NOT run with full user privileges
38+
- Implement additional sandboxing layers: gVisor, Kata Containers, SELinux sandboxes
39+
40+
### Cryptographic Verification of Resources
41+
- Provide cryptographic signatures and SBOMs for all server code
42+
- Implement signature verification in your MCP client before loading servers
43+
- Use TLS for ALL data in transit
44+
- Implement remote attestation capabilities to verify servers are running expected code
45+
46+
### Transport Layer Security
47+
48+
#### stdio Transport (Local Servers)
49+
- STRONGLY RECOMMENDED for local MCP to eliminate DNS rebinding risks
50+
- Direct pipe-based stream communication
51+
- Implement sandbox to prevent privilege escalation
52+
53+
#### HTTP Streaming Transport (Remote Servers)
54+
Required security controls to implement:
55+
- Payload Limits (prevent large payload and recursive payload DoS)
56+
- Rate limiting for tool calls and transport requests
57+
- Client-Server Authentication/Authorization
58+
- Mutual TLS Authentication
59+
- TLS Encryption
60+
- CORS Protection
61+
- CSRF Protection
62+
- Integrity Checks (prevent replay, spoofing, poisoned responses)
63+
64+
### Secure Tool and UX Design
65+
- Create single-purpose tools with explicit boundaries; avoid "do anything" tools
66+
- Do not rely on the LLM for validation or authorization decisions
67+
- Use two-stage commit for high-impact actions: draft/preview first, explicit commit with confirmation second
68+
- Provide rollback/undo paths (draft IDs, snapshots, reversible actions) and time-bound commits when possible
69+
70+
### Human-in-the-Loop
71+
- Implement confirmation prompts for risky operations in your MCP server
72+
- Use elicitation on MCP server side to request user confirmation of risky actions
73+
- Security-relevant messages MUST clearly indicate implications
74+
- Do NOT rely solely on human approval (users can become fatigued)
75+
76+
### Logging and Observability
77+
- Implement logging in your MCP servers and clients
78+
- Log: tools that were used, parameters, originating prompt
79+
- Use OpenTelemetry for end-to-end linkability of actions
80+
- Maintain immutable records of actions and authorizations
81+
82+
---
83+
84+
## Deployment Pattern Security
85+
86+
### All-Local (stdio or http)
87+
- Security depends entirely on host system posture
88+
- Use `stdio` transport to avoid DNS rebinding risks
89+
- Use sandboxing to limit privilege escalation attacks
90+
- Appropriate for development and personal use
91+
92+
### Single-Tenant Remote (http)
93+
- Authentication between client and server is REQUIRED
94+
- Use secure credential storage (OS keychains, secret managers)
95+
- Communication MUST be authenticated and encrypted
96+
- Enterprise clients should enforce authenticated server discovery with explicit allowlists
97+
98+
### Multi-Tenant Remote (http)
99+
- Require robust tenant isolation, identity, and access control
100+
- Implement strong multi-tenancy controls (per-tenant encryption, role-based access control)
101+
- Prefer MCP servers hosted directly by service provider
102+
- Provide remote attestation when possible
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
description: MCP (Model Context Protocol) Security based on CoSAI MCP Security guidelines
3+
languages:
4+
- python
5+
- javascript
6+
- typescript
7+
- go
8+
- rust
9+
- java
10+
alwaysApply: false
11+
---
12+
13+
# MCP (Model Context Protocol) Security Guidelines
14+
15+
NEVER deploy MCP servers or clients without implementing proper security controls.
16+
17+
### Workload Identity and Authentication
18+
- Use SPIFFE/SPIRE for cryptographic workload identities
19+
- SPIFFE (Secure Production Identity Framework For Everyone) provides a standard for service identity
20+
- SPIRE (SPIFFE Runtime Environment) issues and rotates short-lived cryptographic identities (SVIDs)
21+
22+
### Input and Data Sanitization
23+
- Validate ALL inputs using allowlists at every trust boundary
24+
- Sanitize file paths through canonicalization
25+
- Use parameterized queries for database operations
26+
- Apply context-aware output encoding (SQL, shell, HTML)
27+
- Sanitize tool outputs: return only minimum fields, redact all PII and sensitive data
28+
- Treat ALL inputs, tool schemas, metadata, prompts, and resource content as untrusted input
29+
- Deploy prompt injection detection systems
30+
- Use strict JSON schemas to maintain boundaries between instructions and data
31+
32+
### Sandboxing and Isolation
33+
- Design MCP servers to execute with least privilege
34+
- MCP servers interacting with host environment (files, commands, network) MUST implement sandboxing controls
35+
- LLM-generated code MUST NOT run with full user privileges
36+
- Implement additional sandboxing layers: gVisor, Kata Containers, SELinux sandboxes
37+
38+
### Cryptographic Verification of Resources
39+
- Provide cryptographic signatures and SBOMs for all server code
40+
- Implement signature verification in your MCP client before loading servers
41+
- Use TLS for ALL data in transit
42+
- Implement remote attestation capabilities to verify servers are running expected code
43+
44+
### Transport Layer Security
45+
46+
#### stdio Transport (Local Servers)
47+
- STRONGLY RECOMMENDED for local MCP to eliminate DNS rebinding risks
48+
- Direct pipe-based stream communication
49+
- Implement sandbox to prevent privilege escalation
50+
51+
#### HTTP Streaming Transport (Remote Servers)
52+
Required security controls to implement:
53+
- Payload Limits (prevent large payload and recursive payload DoS)
54+
- Rate limiting for tool calls and transport requests
55+
- Client-Server Authentication/Authorization
56+
- Mutual TLS Authentication
57+
- TLS Encryption
58+
- CORS Protection
59+
- CSRF Protection
60+
- Integrity Checks (prevent replay, spoofing, poisoned responses)
61+
62+
### Secure Tool and UX Design
63+
- Create single-purpose tools with explicit boundaries; avoid "do anything" tools
64+
- Do not rely on the LLM for validation or authorization decisions
65+
- Use two-stage commit for high-impact actions: draft/preview first, explicit commit with confirmation second
66+
- Provide rollback/undo paths (draft IDs, snapshots, reversible actions) and time-bound commits when possible
67+
68+
### Human-in-the-Loop
69+
- Implement confirmation prompts for risky operations in your MCP server
70+
- Use elicitation on MCP server side to request user confirmation of risky actions
71+
- Security-relevant messages MUST clearly indicate implications
72+
- Do NOT rely solely on human approval (users can become fatigued)
73+
74+
### Logging and Observability
75+
- Implement logging in your MCP servers and clients
76+
- Log: tools that were used, parameters, originating prompt
77+
- Use OpenTelemetry for end-to-end linkability of actions
78+
- Maintain immutable records of actions and authorizations
79+
80+
---
81+
82+
## Deployment Pattern Security
83+
84+
### All-Local (stdio or http)
85+
- Security depends entirely on host system posture
86+
- Use `stdio` transport to avoid DNS rebinding risks
87+
- Use sandboxing to limit privilege escalation attacks
88+
- Appropriate for development and personal use
89+
90+
### Single-Tenant Remote (http)
91+
- Authentication between client and server is REQUIRED
92+
- Use secure credential storage (OS keychains, secret managers)
93+
- Communication MUST be authenticated and encrypted
94+
- Enterprise clients should enforce authenticated server discovery with explicit allowlists
95+
96+
### Multi-Tenant Remote (http)
97+
- Require robust tenant isolation, identity, and access control
98+
- Implement strong multi-tenancy controls (per-tenant encryption, role-based access control)
99+
- Prefer MCP servers hosted directly by service provider
100+
- Provide remote attestation when possible

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)