
Research
/Security News
Popular npm Packages in the keyv and Cacheable Namespaces Compromised in Active Supply Chain Attack
Popular npm packages keyv and cacheable compromised.
code-firewall-mcp
Advanced tools
Code similarity firewall - blocks dangerous code patterns before they reach execution tools
A structural similarity-based code security filter for MCP (Model Context Protocol). Blocks dangerous code patterns before they reach execution tools by comparing code structure against a blacklist of known-bad patterns.
┌──────────┐ ┌─────────────┐ ┌───────────────────┐ ┌─────────────────────┐
│ Code │───▶│ CST → Embed │───▶│ Similarity Check │───▶│ Execution Tools │
│ (file) │ │ (tree-sitter│ │ vs blacklist │ │ (rlm_exec, etc.) │
└──────────┘ │ + Ollama) │ │ (ChromaDB) │ └─────────────────────┘
└─────────────┘ └─────────┬─────────┘
│
┌────────┴────────┐
▼ ▼
[BLOCKED] [ALLOWED]
Code patterns like os.system("rm -rf /") and os.system("ls") have identical structure. By normalizing away the specific commands/identifiers, we can detect dangerous patterns regardless of the specific arguments used.
# Via uvx (recommended)
uvx code-firewall-mcp
# Or install from source
pip install -e .
Pull an embedding model:
ollama pull nomic-embed-text
firewall_checkCheck if a code file is safe to pass to execution tools.
result = await firewall_check(file_path="/path/to/script.py")
# Returns: {allowed: bool, blocked: bool, similarity: float, ...}
firewall_check_codeCheck code string directly (no file required).
result = await firewall_check_code(
code="import os; os.system('rm -rf /')",
language="python"
)
firewall_blacklistAdd a dangerous pattern to the blacklist.
result = await firewall_blacklist(
code="os.system(arbitrary_command)",
reason="Arbitrary command execution",
severity="critical"
)
firewall_record_deltaRecord near-miss variants to sharpen the classifier.
result = await firewall_record_delta(
code="subprocess.run(['ls', '-la'])",
similar_to="abc123",
notes="Legitimate use case for file listing"
)
firewall_list_patternsList patterns in the blacklist or delta collection.
firewall_remove_patternRemove a pattern from blacklist or deltas.
firewall_statusGet firewall status and statistics.
Environment variables:
| Variable | Default | Description |
|---|---|---|
FIREWALL_DATA_DIR | /tmp/code-firewall | Data storage directory |
OLLAMA_URL | http://localhost:11434 | Ollama server URL |
EMBEDDING_MODEL | nomic-embed-text | Ollama embedding model |
SIMILARITY_THRESHOLD | 0.85 | Block threshold (0-1) |
NEAR_MISS_THRESHOLD | 0.70 | Near-miss recording threshold |
Use code-firewall-mcp as a gatekeeper before passing code to rlm_exec:
# 1. Check code safety
check = await firewall_check_code(user_code)
if check["blocked"]:
print(f"BLOCKED: {check['reason']}")
return
# 2. If allowed, proceed with execution
result = await rlm_exec(code=user_code, context_name="my-context")
The blacklist grows through use:
rlm_auto_analyze finds security issues, add patterns# After security audit finds issues
await firewall_blacklist(
code=dangerous_code,
reason="Command injection via subprocess",
severity="critical"
)
The normalizer strips:
my_var → _"hello" → "S"42 → NExample:
# Original
subprocess.run(["curl", url, "-o", output_file])
# Normalized
_._(["S", _, "S", _])
Both subprocess.run(["curl", ...]) and subprocess.run(["wget", ...]) normalize to the same structure, so blacklisting one catches both.
MIT
FAQs
Code similarity firewall - blocks dangerous code patterns before they reach execution tools
We found that code-firewall-mcp demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Popular npm packages keyv and cacheable compromised.

Security News
A misconfiguration gave three Anthropic models internet access, and one, believing it was in a simulation, shipped a credential-stealing package to PyPI.

Security News
/Company News
Socket has joined the new Composer and Packagist sponsorship program as a launch sponsor, supporting the team that keeps PHP's package ecosystem secure.