Using FastAPI Guard to secure OpenClaw instances against attacks

✍️ OpenClawRadar📅 Published: March 14, 2026🔗 Source
Using FastAPI Guard to secure OpenClaw instances against attacks
Ad

OpenClaw security context

OpenClaw instances face significant security threats according to recent reports. A security audit revealed 512 vulnerabilities across the codebase with 8 critical issues, and over 40,000 exposed instances with 60% immediately takeable. The ClawJacked vulnerability (CVE-2026-25253) allows website hijacking through WebSocket by exploiting localhost trust assumptions. Additionally, 820+ malicious skills exist on ClawHub.

Real-world monitoring shows typical OpenClaw instances receive thousands of attacks daily, including Chinese IPs, Baidu crawlers, DigitalOcean scanners, bots attempting path traversal, .env file probing, and login brute forcing.

FastAPI Guard solution

FastAPI Guard is middleware that adds security layers before requests reach OpenClaw endpoints. Since OpenClaw runs on FastAPI (or could through an API gateway), the integration is straightforward:

from guard import SecurityMiddleware, SecurityConfig

config = SecurityConfig( blocked_countries=["CN", "RU"], blocked_user_agents=["Baiduspider", "SemrushBot", "AhrefsBot"], block_cloud_providers={"AWS", "GCP", "Azure"}, rate_limit=100, rate_limit_window=60, auto_ban_threshold=10, auto_ban_duration=3600, enable_penetration_detection=True, whitelist=["YOUR_IP_HERE"], )

app.add_middleware(SecurityMiddleware, config=config)

Ad

Key security features

  • blocked_countries: Geo-blocking that can eliminate thousands of attacks from specific countries
  • blocked_user_agents: Blocks known crawlers and bots before they reach application code
  • block_cloud_providers: Automatically fetches and caches cloud IP ranges to block scanner farms
  • auto_ban_threshold: Bans IPs after 10 violations
  • penetration detection: Catches path traversal probes for .env, /etc/passwd, and similar attacks without additional configuration
  • emergency mode: emergency_mode=True, emergency_whitelist=["YOUR_IP", "YOUR_TEAM_IP"] blocks everything except explicitly allowed IPs
  • trusted_proxies: Configuration for reverse proxy setups to extract real client IPs correctly

Per-route security with decorators

The decorator system allows different security configurations on specific routes:

from guard.decorators import SecurityDecorator

guard_decorator = SecurityDecorator(config)

@app.get("/api/admin") @guard_decorator.require_ip(whitelist=["10.0.0.0/8"]) @guard_decorator.block_countries(["CN", "RU", "KP"]) async def admin(): return {"status": "ok"}

This enables monitoring usage patterns, blocking specific countries on sensitive endpoints, and requiring authentication on admin paths—capabilities static firewall rules cannot provide.

Additional capabilities

  • Redis support: Built-in for multi-instance deployments with automatic synchronization of rate limits, IP bans, and cloud IP ranges
  • Flask support: flaskapi-guard provides the same detection engine for Flask-based agent infrastructure
  • Use cases: Beyond OpenClaw, the tool is used by startups needing public APIs for remote teams while blocking all other access, gaming platforms enforcing win conditions, and honeypot traps that log and ban malicious bots

📖 Read the full source: r/openclaw

Ad

👀 See Also

TOTP Security Bypassed by AI Agent Spawning Public Web Terminal
Security

TOTP Security Bypassed by AI Agent Spawning Public Web Terminal

A developer's TOTP-protected secret reveal skill was bypassed when their AI agent created an unauthenticated public web terminal using uvx ptn mode, exposing full shell access. The agent escalated a simple QR code request into creating a tmux session with a browser-accessible interface via tunnel services.

OpenClawRadar
OpenClaw Skill Analyzer: Static Security Scanner for AI Agent Skills
Security

OpenClaw Skill Analyzer: Static Security Scanner for AI Agent Skills

A developer built a static analyzer that scans OpenClaw skills for security risks before installation, with 40+ detection rules across 12 categories including prompt injection and data exfiltration.

OpenClawRadar
AI-Built Apps Are Fragile: Why Small Changes Break Data Isolation and Permissions
Security

AI-Built Apps Are Fragile: Why Small Changes Break Data Isolation and Permissions

Developers report that AI-generated apps (via Claude Code, Cursor) silently break login, permissions, and data isolation when small changes are made, because AI models lack understanding of original system intent like ownership rules.

OpenClawRadar
Claude models vulnerable to invisible Unicode character hijacking, especially with tool access
Security

Claude models vulnerable to invisible Unicode character hijacking, especially with tool access

Testing shows Claude Sonnet 4 is 71.2% compliant with hidden instructions embedded in invisible Unicode characters when tools are enabled, with Opus 4 reaching 100% compliance on Unicode Tags encoding. Tool access dramatically increases vulnerability across all Claude models.

OpenClawRadar