ln-773-cors-configurator by levnikolaevich/claude-code-skills
npx skills add https://github.com/levnikolaevich/claude-code-skills --skill ln-773-cors-configurator类型: L3 Worker 类别: 7XX 项目引导 父级: ln-770-crosscutting-setup
以安全为先的方法配置跨源资源共享(CORS)策略。
| 方面 | 详情 |
|---|---|
| 输入 | 来自 ln-770 的上下文存储 |
| 输出 | 包含环境特定策略的 CORS 配置 |
| 技术栈 | .NET (ASP.NET Core CORS), Python (FastAPI CORSMiddleware) |
从协调器接收上下文存储。
所需上下文:
STACK: .NET 或 PythonPROJECT_ROOT: 项目目录路径ENVIRONMENT: 开发环境或生产环境广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
幂等性检查:
AddCors 或 UseCorsCORSMiddleware{ "status": "skipped" }确定前端配置。
检测步骤:
/frontend, /client, /web).env 或 appsettings.json 中的 CORS_ORIGINS检测到的前端源:
| 框架 | 默认端口 | 源 |
|---|---|---|
| React (CRA) | 3000 | http://localhost:3000 |
| Vite | 5173 | http://localhost:5173 |
| Angular | 4200 | http://localhost:4200 |
| Next.js | 3000 | http://localhost:3000 |
| 环境 | 策略 |
|---|---|
| 开发环境 | 允许 localhost 源(可配置) |
| 生产环境 | 仅允许来自环境变量的显式源 |
安全警告: 切勿将 *(通配符)与凭据一起使用。
| 方法 | 默认 | 备注 |
|---|---|---|
| GET | ✓ 是 | 读取操作 |
| POST | ✓ 是 | 创建操作 |
| PUT | ✓ 是 | 更新操作 |
| DELETE | ✓ 是 | 删除操作 |
| PATCH | 可选 | 部分更新 |
| OPTIONS | ✓ 是 | 预检请求(自动) |
| 场景 | AllowCredentials | 备注 |
|---|---|---|
| 基于 Cookie 的身份验证 | ✓ 是 | Cookie 必需 |
| Header 中的 JWT | ✗ 否 | 不需要 |
| OAuth2 | 视情况而定 | 查阅文档 |
警告: AllowCredentials = true 时禁止使用 * 源。
| 环境 | MaxAge | 依据 |
|---|---|---|
| 开发环境 | 0 | 即时配置更改 |
| 生产环境 | 86400 (24h) | 减少预检请求 |
| 文件 | 用途 |
|---|---|
Extensions/CorsExtensions.cs | CORS 服务注册 |
appsettings.json (更新) | 源配置 |
appsettings.Development.json (更新) | 开发环境源 |
生成过程:
注册代码:
builder.Services.AddCorsPolicy(builder.Configuration);
// ...
app.UseCors(builder.Environment.IsDevelopment() ? "Development" : "Production");
| 文件 | 用途 |
|---|---|
middleware/cors_config.py | CORS 中间件配置 |
.env (更新) | CORS_ORIGINS 变量 |
生成过程:
注册代码:
from middleware.cors_config import configure_cors
configure_cors(app)
验证步骤:
语法检查:
dotnet build --no-restorepython -m py_compile middleware/cors_config.pyCORS 测试:
# 测试预检请求
curl -X OPTIONS http://localhost:5000/api/test \
-H "Origin: http://localhost:3000" \
-H "Access-Control-Request-Method: POST" \
-v
验证头部:
Access-Control-Allow-Origin: 应与请求源匹配Access-Control-Allow-Methods: 应列出允许的方法Access-Control-Allow-Credentials: true (如果启用)Access-Control-Max-Age: 缓存持续时间完成前,请验证:
* 源AllowAnyMethod){
"status": "success",
"files_created": [
"Extensions/CorsExtensions.cs"
],
"packages_added": [],
"registration_code": "builder.Services.AddCorsPolicy(configuration);",
"message": "已配置包含开发和生产策略的 CORS"
}
* 源与凭据一起使用 — 违反 CORS 规范的安全问题AddCors/UseCors 或 CORSMiddleware,则返回 status: "skipped"dotnet build 或 py_compile)版本: 2.0.0 最后更新: 2026-01-10
每周安装量
152
仓库
GitHub 星标数
245
首次出现
2026年1月24日
安全审计
安装于
claude-code138
gemini-cli137
cursor137
opencode137
codex136
github-copilot131
Type: L3 Worker Category: 7XX Project Bootstrap Parent: ln-770-crosscutting-setup
Configures Cross-Origin Resource Sharing (CORS) policy with security-first approach.
| Aspect | Details |
|---|---|
| Input | Context Store from ln-770 |
| Output | CORS configuration with environment-specific policies |
| Stacks | .NET (ASP.NET Core CORS), Python (FastAPI CORSMiddleware) |
Accept Context Store from coordinator.
Required Context:
STACK: .NET or PythonPROJECT_ROOT: Project directory pathENVIRONMENT: Development or ProductionIdempotency Check:
AddCors or UseCorsCORSMiddleware{ "status": "skipped" }Determine frontend configuration.
Detection Steps:
/frontend, /client, /web).env or appsettings.json for CORS_ORIGINSDetected 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 |
| Environment | Strategy |
|---|---|
| Development | Allow localhost origins (configurable) |
| Production | Explicit origins from environment variables only |
Security Warning: Never use * (wildcard) with credentials.
| 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) |
| 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.
| Environment | MaxAge | Rationale |
|---|---|---|
| Development | 0 | Immediate config changes |
| Production | 86400 (24h) | Reduce preflight requests |
| File | Purpose |
|---|---|
Extensions/CorsExtensions.cs | CORS service registration |
appsettings.json (update) | Origins configuration |
appsettings.Development.json (update) | Dev origins |
Generation Process:
Registration Code:
builder.Services.AddCorsPolicy(builder.Configuration);
// ...
app.UseCors(builder.Environment.IsDevelopment() ? "Development" : "Production");
| File | Purpose |
|---|---|
middleware/cors_config.py | CORS middleware configuration |
.env (update) | CORS_ORIGINS variable |
Generation Process:
Registration Code:
from middleware.cors_config import configure_cors
configure_cors(app)
Validation Steps:
Syntax check:
dotnet build --no-restorepython -m py_compile middleware/cors_config.pyCORS test:
# Test preflight request
curl -X OPTIONS http://localhost:5000/api/test \
-H "Origin: http://localhost:3000" \
-H "Access-Control-Request-Method: POST" \
-v
Verify headers:
Access-Control-Allow-Origin: Should match request originAccess-Control-Allow-Methods: Should list allowed methodsAccess-Control-Allow-Credentials: true (if enabled)Before completing, verify:
* origin in productionAllowAnyMethod in prod){
"status": "success",
"files_created": [
"Extensions/CorsExtensions.cs"
],
"packages_added": [],
"registration_code": "builder.Services.AddCorsPolicy(configuration);",
"message": "Configured CORS with Development and Production policies"
}
* origin with credentials — security violation per CORS specAddCors/UseCors or CORSMiddleware exists, return status: "skipped"dotnet build or py_compile)Version: 2.0.0 Last Updated: 2026-01-10
Weekly Installs
152
Repository
GitHub Stars
245
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
claude-code138
gemini-cli137
cursor137
opencode137
codex136
github-copilot131
xdrop 文件传输脚本:Bun 环境下安全上传下载工具,支持加密分享
37,500 周安装
SpecStory 历史文件整理工具 - 按时间戳自动归档会话文件,保持项目目录整洁
101 周安装
OMC Doctor:Claude代码助手安装诊断与修复工具 - 解决OMC插件问题
101 周安装
微信文章转Markdown工具 - 高效抓取公众号文章并转换为Markdown格式,支持存档与AI处理
101 周安装
Go语言技术文档编写指南 - 专业API设计与文档生成技能
101 周安装
Mermaid图表专家技能 - 专业流程图、序列图、甘特图代码生成与可视化指南
101 周安装
销售自动化工具 - 冷邮件序列、跟进计划、话术模板与A/B测试完整指南
101 周安装
Access-Control-Max-Age