AGENT SKILL

ln-773-cors-configurator

Configures CORS policy for development and production environments. Use when setting up cross-origin access for APIs.

License 许可
MIT
最近更新
2026-06-15
Stars
★ 2
Forks
1

01 前言 Front Matter

name
ln-773-cors-configurator
license
MIT
description
Configures CORS policy for development and production environments. Use when setting up cross-origin access for APIs.

03 SKILL.md 正文

ln-773-cors-configurator

Type: L3 Worker Category: 7XX Project Bootstrap

Configures Cross-Origin Resource Sharing (CORS) policy with security-first approach.


Overview

Aspect Details
Input Context Store from ln-770
Output CORS configuration with environment-specific policies
Stacks .NET (ASP.NET Core CORS), Python (FastAPI CORSMiddleware)

Phase 1: Receive Context

Accept Context Store from coordinator.

Required Context:

  • STACK: .NET or Python
  • PROJECT_ROOT: Project directory path
  • ENVIRONMENT: Development or Production

Idempotency Check:

  • .NET: Grep for AddCors or UseCors
  • Python: Grep for CORSMiddleware
  • If found: Return { "status": "skipped" }

Phase 2: Analyze Project Structure

Determine frontend configuration.

Detection Steps:

  1. Check for frontend in same repository (/frontend, /client, /web)
  2. Read .env or appsettings.json for CORS_ORIGINS
  3. Identify common frontend ports (3000, 5173, 4200)

Detected Frontend Origins:

Framework Default Port Origin
React (CRA) 3000 http://localhost:3000
Vite 5173 http://localhost:5173
Angular 4200 http://localhost:4200
Next.js 3000 http://localhost:3000

Phase 3: Decision Points

Q1: Allowed Origins

Environment Strategy
Development Allow localhost origins (configurable)
Production Explicit origins from environment variables only

Security Warning: Never use * (wildcard) with credentials.

Q2: Allowed Methods

Method Default Notes
GET ✓ Yes Read operations
POST ✓ Yes Create operations
PUT ✓ Yes Update operations
DELETE ✓ Yes Delete operations
PATCH Optional Partial updates
OPTIONS ✓ Yes Preflight requests (automatic)

Q3: Credentials Support

Scenario AllowCredentials Notes
Cookie-based auth ✓ Yes Required for cookies
JWT in header ✗ No Not needed
OAuth2 Depends Check documentation

Warning: AllowCredentials = true prohibits * origin.

Q4: Preflight Cache Duration

Environment MaxAge Rationale
Development 0 Immediate config changes
Production 86400 (24h) Reduce preflight requests

Phase 4: Generate Configuration

.NET Output Files

File Purpose
Extensions/CorsExtensions.cs CORS service registration
appsettings.json (update) Origins configuration
appsettings.Development.json (update) Dev origins

Generation Process:

  1. Use MCP ref for current ASP.NET Core CORS API
  2. Generate CorsExtensions with:
    • Development policy (permissive)
    • Production policy (restrictive)
    • Environment-based policy selection
  3. Update appsettings with CORS:Origins

Registration Code:

builder.Services.AddCorsPolicy(builder.Configuration);
// ...
app.UseCors(builder.Environment.IsDevelopment() ? "Development" : "Production");

Python Output Files

File Purpose
middleware/cors_config.py CORS middleware configuration
.env (update) CORS_ORIGINS variable

Generation Process:

  1. Use MCP ref for FastAPI CORSMiddleware
  2. Generate cors_config.py with:
    • Origin parsing from environment
    • Method and header configuration
    • Credentials handling
  3. Update .env with CORS_ORIGINS

Registration Code:

from middleware.cors_config import configure_cors
configure_cors(app)

Phase 5: Validate

Validation Steps:

  1. Syntax check:

    • .NET: dotnet build --no-restore
    • Python: python -m py_compile middleware/cors_config.py
  2. CORS test:

    # Test preflight request
    curl -X OPTIONS http://localhost:5000/api/test \
      -H "Origin: http://localhost:3000" \
      -H "Access-Control-Request-Method: POST" \
      -v
    
  3. Verify headers:

    • Access-Control-Allow-Origin: Should match request origin
    • Access-Control-Allow-Methods: Should list allowed methods
    • Access-Control-Allow-Credentials: true (if enabled)
    • Access-Control-Max-Age: Cache duration

Security Checklist

Before completing, verify:

  • [ ] No wildcard * origin in production
  • [ ] Explicit allowed methods (not AllowAnyMethod in prod)
  • [ ] Credentials only if needed
  • [ ] Origins from environment variables in production
  • [ ] Preflight caching enabled in production

Return to Coordinator

{
  "status": "success",
  "files_created": [
    "Extensions/CorsExtensions.cs"
  ],
  "packages_added": [],
  "registration_code": "builder.Services.AddCorsPolicy(configuration);",
  "message": "Configured CORS with Development and Production policies"
}

Reference Links


Critical Rules

  • Never use wildcard * origin with credentials — security violation per CORS spec
  • Production origins from environment variables only — no hardcoded URLs in code
  • Separate Development and Production policies — permissive locally, restrictive in production
  • Idempotent — if AddCors/UseCors or CORSMiddleware exists, return status: "skipped"
  • Enable preflight caching in Production — MaxAge 86400 (24h) to reduce OPTIONS requests

Definition of Done

  • [ ] Context Store received (stack, project root, environment)
  • [ ] Frontend origins detected (port/framework auto-detection)
  • [ ] User decisions collected (origins, methods, credentials, cache duration)
  • [ ] CORS configuration generated with environment-specific policies
  • [ ] Security checklist verified (no wildcard + credentials, explicit methods, env-based origins)
  • [ ] Syntax validated (dotnet build or py_compile)
  • [ ] Structured JSON response returned to ln-770 coordinator

Version: 2.0.0 Last Updated: 2026-01-10

04 同仓库更多 Skills

vitalikpestov
vitalikpestov/Skills-Catalog

solana-dev

Use when user asks to "build a Solana dapp", "write an Anchor program", "create a token", "debug Solana errors", "set up wallet connection", "test my Solana program", "deploy to devnet", or "explain Solana concepts" (rent, accounts, PDAs, CPIs, etc.). End-to-end Solana development playbook covering wallet connection, Anchor/Pinocchio programs, Codama client generation, LiteSVM/Mollusk/Surfpool testing, and security checklists. Integrates with the Solana MCP server for live documentation search. Prefers framework-kit (@solana/client + @solana/react-hooks) for UI, wallet-standard-first connection (incl. ConnectorKit), @solana/kit for client/RPC code, and @solana/web3-compat for legacy boundaries.

开发工程师测试与质量前端开发
★ 2
vitalikpestov
vitalikpestov/Skills-Catalog

generating-trading-signals

Generate trading signals using technical indicators (RSI, MACD, Bollinger Bands, etc.). Combines multiple indicators into composite signals with confidence scores. Use when analyzing assets for trading opportunities or checking technical indicators. Trigger with phrases like "get trading signals", "check indicators", "analyze for entry", "scan for opportunities", "generate buy/sell signals", or "technical analysis".

★ 2
vitalikpestov
vitalikpestov/Skills-Catalog

prediction-monitor

Prediction Monitor - Auto-activating skill for ML Deployment. Triggers on: prediction monitor, prediction monitor Part of the ML Deployment skill category.

★ 2
vitalikpestov
vitalikpestov/Skills-Catalog

strategy-advisor

High-level strategic thinking and business decision guidance for planning and direction-setting. Use when: making strategic decisions, evaluating business options, setting direction, analyzing trade-offs, or when user mentions strategy, business planning, competitive analysis, or long-term planning.

★ 2
vitalikpestov
vitalikpestov/Skills-Catalog

app-paywall-pilot

Design, audit, debug, and implement App Store-compliant mobile paywalls, subscription flows, pricing screens, trials, offers, feature gates, and subscription lifecycle UX. Use when the user asks to audit my paywall, fix App Store 3.1.2 rejection, improve trial-to-paid, choose plans/prices/trials, review RevenueCat/Adapty/Apphud/Superwall setup, calculate LTV/ROAS, or build paywall implementation.

设计师视觉设计
★ 2
vitalikpestov
vitalikpestov/Skills-Catalog

figma

Use the Figma MCP server to fetch design context, screenshots, variables, and assets from Figma, and to translate Figma nodes into production code. Trigger when a task involves Figma URLs, node IDs, design-to-code implementation, or Figma MCP setup and troubleshooting.

设计师Skill与智能体开发
★ 2