fastapi-guard
Skill by Guard-Core
Adds security middleware to FastAPI apps, covering IP filtering, rate limiting and per-route security decorators. Built for developers who want to protect a FastAPI service and trial rules safely.
Install fastapi-guard
Built from the published package, never by AI.
git clone --depth 1 https://github.com/Guard-Core/fastapi-guard /tmp/fastapi-guard && mkdir -p ~/.claude/skills && cp -r /tmp/fastapi-guard/guard/.agents/skills/fastapi-guard ~/.claude/skills/fastapi-guardRun in your terminal. Claude Code loads skills from ~/.claude/skills automatically.
git clone --depth 1 https://github.com/Guard-Core/fastapi-guard /tmp/fastapi-guard && mkdir -p ~/.gemini/antigravity-cli/skills && cp -r /tmp/fastapi-guard/guard/.agents/skills/fastapi-guard ~/.gemini/antigravity-cli/skills/fastapi-guardAntigravity CLI loads skills from ~/.gemini/antigravity-cli/skills, or .agents/skills for one project.
Skills can run scripts on your machine. Some need an API key: check the README.
About
fastapi-guard is a security middleware package for FastAPI applications. It provides IP filtering with whitelists, blacklists, country rules and cloud-provider blocking, plus rate limiting with optional Redis-backed state. It also offers signature-based attack-pattern detection and per-route security decorators that attach rules such as rate limits and authentication to individual endpoints.
The middleware is configured through a SecurityConfig object and added to the app with add_middleware. Passive mode logs suspicious requests without blocking them, which helps trial rules against production traffic. An optional Guard Agent integration sends security events and metrics to the Guard SaaS. The skill is aimed at developers adding this protection to a FastAPI application.
Written from the project's SKILL.md and checked against it.
What it can do
- IP filteringApplies whitelist and blacklist rules using IPs and CIDR ranges, plus country and cloud-provider checks.
- Rate limitingSets a global request limit with per-endpoint overrides and optional Redis state.
- Per-route decoratorsAttaches rules such as rate_limit, require_auth, api_key_auth and ip_filter to single endpoints.
- Route resolution strict modeBlocks requests whose route cannot be resolved when route_resolution_strict is set to True.
- Global behavior rulesApplies behavior rules to every route, such as a global 404 watcher.
- Passive modeLogs suspicious requests and emits events without blocking them.
- Guard Agent telemetrySends security events and metrics to the Guard SaaS when enable_agent is set to True.
What you need
- Python 3.10 to 3.14
- uv or pip to install the package
- fastapi-guard[agent] extra for SaaS telemetry
- Guard SaaS API key and project ID for telemetry
- Redis, optional, for distributed rate limit state
Try asking
- Add fastapi-guard rate limiting to my FastAPI login endpoint.
- Set up passive mode to trial IP blacklist rules on my FastAPI app.
- Protect my /api/payments route with bearer auth and a rate limit.
Good to know
- Without Redis, rate limits are kept per process.
- route_resolution_strict=True makes requests to unserved paths return 500 instead of 404.
- passive_mode=True logs checks but never blocks requests.
- require_auth and api_key_auth reject requests with 401 when no verifier is supplied.
Security check
ANo download-and-run commands, hidden instructions or signs of sending keys out were found.
Checked automatically: guard/.agents/skills/fastapi-guard/SKILL.md. This looks for known risky patterns and is not a full audit. How grades work
Alternatives to fastapi-guard
All alternatives →Retrieves lab biomarker results and clinician notes from Function Health through its FHIR API. It is for people who want an AI assistant to review their own lab history and notes.
Gives an AI assistant a methodology for finding and exploiting privilege escalation weaknesses on Windows systems during authorized penetration tests. It is for security testers and defenders validating escalation paths.
Guides the assistant through designing, debugging and hardening GitHub Actions CI/CD workflows. It is aimed at teams that run production pipelines on GitHub.
Develops evidence-backed structural security hardening proposals from disclosures, findings, source code, or Codex Security scans. It is for teams that need systemic fixes and architectural tradeoffs.
Claude Security scans code for security issues with Claude Code. It covers whole repositories, branch or pull request diffs, single commits, and existing findings from SARIF files or earlier reports.
Turns vulnerability notes, disclosure reports, PoCs, source code, or Codex Security findings into self-contained vulnerability reports. Built for security researchers who need claims the evidence supports.
Compare with function_health, windows-privilege-escalation or github-actions-advanced
fastapi-guard: common questions
What does passive mode do in fastapi-guard?
Passive mode runs every check in log-only mode, so suspicious requests are logged and emitted as events but not blocked. The source suggests switching to passive_mode=False once the logs show the rules firing as expected.
Does fastapi-guard rate limiting work across several servers?
Redis is used for distributed state when enable_redis is True, which is the default. Without Redis, limits are per process.
Does fastapi-guard handle authentication by itself?
require_auth and api_key_auth need a verifier callable, given per route or globally in SecurityConfig. Without one, requests are rejected with 401. require_authorization_header only checks that the header is present and is not authentication.
How do I install fastapi-guard?
Run the command above to copy the skill into ~/.claude/skills/. Claude Code picks it up automatically.
Is fastapi-guard free?
The code is published under the MIT licence. The service it connects to may have its own pricing.
Is fastapi-guard safe to use?
It scores 80 of 100. Grades: maintenance A, licence A, quality A. Security check: grade A, no risky patterns found in the files checked. Review the code before you install. How grades work.
What are alternatives to fastapi-guard?
Similar skills: function_health, windows-privilege-escalation, github-actions-advanced, propose-security-hardening.
