Agent skill
managing-advanced-middleware
Advanced middleware logic for security and routing. Use for global rate limiting, security headers, and protection of admin routes.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/managing-advanced-middleware
SKILL.md
Advanced Middleware and Security Logic
When to use this skill
- Implementing site-wide security measures.
- Protecting sensitive routes like
/admin/*or/dashboard/*. - Injecting nonces or CSP headers.
Workflow
- Create
middleware.tsin the root (Next.js 15). - Define
config.matcherto specify target routes. - Implement checks (Auth check, Rate limit, CSP).
Code Pattern (CSP Header)
import { NextResponse } from 'next/server';
export function middleware(request: Request) {
const nonce = Buffer.from(crypto.randomUUID()).toString('base64');
const csp = `default-src 'self'; script-src 'self' 'nonce-${nonce}';`;
const response = NextResponse.next();
response.headers.set('Content-Security-Policy', csp);
return response;
}
Instructions
- Performance: Keep middleware logic lightweight to avoid slowing down every request.
- Auth: Appwrite sessions are stored in cookies; middleware can check for the presence of these cookies for simple protection.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?