/saas-builder:saas-api-securityfrom saas-builder
Set up an API security layer for a SaaS application. Rate limiting, plan-based access control, input validation, error handling, CORS, and health checks. Use this skill when the user wants anything related to API security, rate limiting, authorisation, input validation, error handling, or API protection. Phrases like "secure the API", "add rate limiting", "check the plan", "input validation" trigger this skill.
Ships in saas-builder. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
This skill hardens the API layer of a SaaS application from a security, resilience, and quality perspective. It is added as a final protection and quality layer on top of the other layers (auth, payments).
Dependency: This skill is Phase 7 of the saas-launcher orchestrator skill. It can also be used independently.
Related skills:
An incoming API request must pass through these layers in order:
Request arrives
→ 1. Rate Limiting (too many requests?)
→ 2. Authentication (who is this?)
→ 3. Authorization (do they have permission? Is their plan sufficient?)
→ 4. Input Validation (is the submitted data valid?)
→ 5. Business Logic (the actual operation)
→ 6. Error Handling (if something goes wrong)
→ Return response
Each layer is independent and rejects the request without proceeding to the next layer on violation.
Without rate limiting:
Apply rate limiting at two levels:
Global level (IP-based): Apply to all endpoints. A set number of requests per second or minute. Purpose: DDoS and brute force protection.
Endpoint level (user-based): Apply separately to sensitive endpoints — login attempts, checkout creation, email sending. Purpose: fair use of resources.
In serverless environments (Vercel, Netlify) each request runs in a separate process. This means in-memory rate limiting (keeping a counter in memory) won't work — each process has its own memory and counters aren't shared.
Solution: Use an external data store. Upstash Redis is a managed Redis service optimised for serverless environments. It works over HTTP (no TCP connection required), keeping the counter in Redis on every request. Its free tier is sufficient for most early-stage SaaS.
For a simple project or MVP where even Upstash feels like overkill: skip rate limiting and add it when the need arises in production. But at minimum put a basic protection on your login endpoint and webhook endpoint.
Return HTTP 429 (Too Many Requests) when the limit is exceeded. Include the following information as headers:
User-friendly error message: "Too many requests. Please wait a few seconds and try again."
This layer consumes the session system built by the saas-auth skill.
Perform a session check on every protected API endpoint:
General protection via middleware should already be in place (see saas-auth). The API route-level check is a safety net for edge cases not covered by the middleware.
Authentication answers "who is this?" Authorization answers "can this person perform this action?"
Define plans as a hierarchy: free < starter < pro < enterprise. Each API endpoint requires a minimum plan level. Return 403 Forbidden if the user's plan is below the required level.
The 403 response should be user-friendly:
Check plans not only in API routes but also at these points:
Some plans include a monthly API call or operation limit. Track these limits:
Every piece of data from a user is potentially malicious. Unvalidated input can lead to:
Use a schema validation library like Zod. Define the data each API endpoint accepts as a schema. Pass incoming data through the schema — return 400 Bad Request if invalid, proceed with type-safe data if valid.
What to define in a validation schema:
A validation error response should clearly indicate which field is invalid and why:
{
"error": "Invalid data",
"details": [
{ "field": "email", "message": "A valid email address is required" },
{ "field": "name", "message": "Must be at most 100 characters" }
]
}
This format is both human-readable and can be processed programmatically by the client.
Error messages serve two audiences:
This balance:
| Code | Meaning | When | Message Detail |
|---|---|---|---|
| 400 | Bad Request | Input validation error | Detailed (which field, why) |
| 401 | Unauthorized | No or invalid session | "You need to log in" |
| 403 | Forbidden | Insufficient plan or no permission | Plan info + upgrade link |
| 404 | Not Found | Resource not found | "Resource not found" |
| 409 | Conflict | Conflict (duplicate) | "This resource already exists" |
| 429 | Too Many Requests | Rate limit exceeded | Wait time information |
| 500 | Internal Server Error | Unexpected error | Generic message, details in logs |
console.log is not enough in production. Use a logging service (Sentry, LogSnag, Axiom, Vercel Log Drain). On every 500 error:
Sentry is especially recommended — it groups errors, shows trends, and sends alerts.
If your API is only used by your own frontend (Next.js full-stack) CORS configuration is not needed — requests come from the same origin.
CORS is needed when:
*) — only list trusted originsAccess-Control-Allow-Credentials: true for requests requiring credentials (cookies)Every SaaS should have a /api/health endpoint. This endpoint:
Response: status (ok/degraded), timestamp, uptime. Return "degraded" if there's no database connection but still return 200 (application is running, DB connection is down).
NEXT_PUBLIC_?x-forwarded-for header. Directly using req.ip may be unreliable.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub carriegale2710/skills-library --plugin saas-builder12 skills in this plugin
/saas-analyticsSet up PostHog analytics and product analysis for a SaaS application. Event tracking, user identification, feature flags, session replay, funnel analysis, and privacy-compliant configuration. Use this skill when the user wants anything related to user analytics, PostHog, event tracking, user behaviour, feature flags, A/B testing, conversion analysis, or metric tracking. Phrases like "set up analytics", "track users", "add PostHog", "create a feature flag" trigger this skill.
/saas-authSet up the authentication layer of a SaaS application. Covers Google OAuth, Magic Link, email/password login, JWT session management, and middleware for protected routes. Use this skill when the user wants to add authentication, set up login, or configure user sessions.
/saas-databaseSet up the database layer of a SaaS application. Covers Supabase project creation, schema design, Row Level Security (RLS), migrations, and connection pooling. Use this skill when the user wants to set up a database, design a schema, or configure Supabase.
/saas-deploymentMove a SaaS application to production. Deployment with Vercel, Railway, or Fly.io, domain configuration, SSL, environment variables, CI/CD, monitoring, and operational readiness. Use this skill when the user wants anything related to deploy, publishing, production, hosting, domain, SSL, CI/CD, monitoring, or "going live". Phrases like "deploy", "publish", "go live", "put it on Vercel", "connect a domain" trigger this skill.
/saas-emailSet up the email infrastructure for a SaaS application. Covers Resend and Mailgun integration, DNS configuration (SPF, DKIM, DMARC), and transactional email templates. Use this skill when the user wants to send emails, configure a custom domain for email, or set up email templates.
/saas-landing-seoDesign a conversion-focused landing page and set up search engine optimisation (SEO) for a SaaS application. Components such as hero, pricing, FAQ, and testimonials; metadata, sitemap, robots.txt, Open Graph, structured data, and a blog system. Use this skill when the user wants a landing page, homepage, pricing page, SEO, sitemap, Open Graph, blog, or "attract more customers". Phrases like "build a nice homepage", "set up SEO", "add a pricing section", "set up a blog" trigger this skill.
Other plugins' skills for the same job