api-protect
БесплатноБез исполняемых скриптовНе проверенAdd authentication, authorization, and security to API endpoints
от diegosouzapw★ 68 звёзд на GitHubОб этом скилле
API Protection
Add comprehensive security, authentication, and authorization to the specified API route.
Target API Route
$ARGUMENTS
Security Layers to Implement
1. Authentication (Who are you?)
- Verify user identity
- Token validation (JWT, session, API keys)
- Handle expired/invalid tokens
2. Authorization (What can you do?)
- Role-based access control (RBAC)
- Resource-level permissions
- Check user ownership
3. Input Validation
- Sanitize all inputs
- SQL/NoSQL injection prevention
- XSS prevention
- Type validation with Zod
4. Rate Limiting
- Prevent abuse
- Per-user/IP limits
- Sliding window algorithm
5. CORS (if needed)
- Whitelist allowed origins
- Proper headers
- Credentials handling
Implementation Approach
For Supabase Projects:
// Use Supabase Auth + RLS
- getUser() from server-side client
- RLS policies for data access
- Service role key for admin operations
For NextAuth.js Projects:
// Use NextAuth sessions
- getServerSession() in route handlers
- Protect with middleware
- Role checking logic
For Custom Auth:
// JWT validation
- Verify tokens
- Decode and validate claims
- Check expiration
Security Checklist
Authentication
- Verify authentication tokens
- Handle missing/invalid tokens (401)
- Check token expiration
- Secure token storage recommendations
Authorization
- Check user roles/permissions (403)
- Verify resource ownership
- Implement least privilege principle
- Log authorization failures
Input Validation
- Validate all inputs with Zod
- Sanitize SQL/NoSQL inputs
- Escape special characters
- Limit payload sizes
Rate Limiting
- Per-user limits
- Per-IP limits
- Clear error messages (429)
- Retry-After headers
CORS
- Whitelist specific origins
- Handle preflight requests
- Secure credentials
- Appropriate headers
Error Handling
- Don't expose stack traces
- Generic error messages
- Log detailed errors server-side
- Consistent error format
Logging & Monitoring
- Log authentication attempts
- Log authorization failures
- Track suspicious activity
- Monitor rate limit hits
What to Generate
- Protected Route Handler - Secured version of the API route
- Middleware/Utilities - Reusable auth helpers
- Type Definitions - User, permissions, roles
- Error Responses - Standardized auth errors
- Usage Examples - Client-side integration
Common Patterns for Solo Developers
Pattern 1: Simple Token Auth
// For internal tools, admin panels
const token = request.headers.get('authorization')
if (token !== process.env.ADMIN_TOKEN) {
return new Response('Unauthorized', { status: 401 })
}
Pattern 2: User-based Auth
// For user-facing apps
const user = await getCurrentUser(request)
if (!user) {
return new Response('Unauthorized', { status: 401 })
}
Pattern 3: Role-based Auth
// For apps with different user types
const user = await getCurrentUser(request)
if (!user || !hasRole(user, 'admin')) {
return new Response('Forbidden', { status: 403 })
}
Generate production-ready, secure code that follows the principle of least privilege.
Установить api-protect в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл api-protect?
Add authentication, authorization, and security to API endpoints
Как установить скилл api-protect?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл api-protect запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic