ln-773-cors-configurator
Configures CORS policy for development and production
- License 许可
- MIT
- 最近更新
- 2026-05-02
- Stars
- ★ 3
- Forks
- 1
01 前言 Front Matter
- name
- ln-773-cors-configurator
- license
- MIT
- description
- Configures CORS policy for development and production
02 资源文件 27
- 参考文档checklist.md5.5 KB
- 其他customize.toml1.5 KB
- 参考文档data/curriculum.yaml3.9 KB
- 参考文档data/quiz-questions.yaml8.2 KB
- 参考文档data/role-paths.yaml5.2 KB
- 参考文档data/session-content-map.yaml9.3 KB
- 参考文档data/tea-resources-index.yaml19.9 KB
- 参考文档instructions.md4.3 KB
- 参考文档steps-c/step-01-init.md6.3 KB
- 参考文档steps-c/step-01b-continue.md4.2 KB
- 参考文档steps-c/step-02-assess.md7.2 KB
- 参考文档steps-c/step-03-session-menu.md7.2 KB
- 参考文档steps-c/step-04-session-01.md14.8 KB
- 参考文档steps-c/step-04-session-02.md13.4 KB
- 参考文档steps-c/step-04-session-03.md7.4 KB
- 参考文档steps-c/step-04-session-04.md6.0 KB
- 参考文档steps-c/step-04-session-05.md5.7 KB
- 参考文档steps-c/step-04-session-06.md5.3 KB
- 参考文档steps-c/step-04-session-07.md6.9 KB
- 参考文档steps-c/step-05-completion.md9.7 KB
- 参考文档steps-e/step-e-01-assess-workflow.md3.3 KB
- 参考文档steps-e/step-e-02-apply-edits.md3.0 KB
- 参考文档steps-v/step-v-01-validate.md6.1 KB
- 参考文档templates/certificate-template.md2.4 KB
- 参考文档templates/progress-template.yaml2.2 KB
- 参考文档templates/session-notes-template.md1.0 KB
- 参考文档workflow-plan-teach-me-testing.md33.1 KB
03 SKILL.md 正文
ln-773-cors-configurator
Type: L3 Worker Category: 7XX Project Bootstrap Parent: ln-770-crosscutting-setup
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 PythonPROJECT_ROOT: Project directory pathENVIRONMENT: Development or Production
Idempotency Check:
- .NET: Grep for
AddCorsorUseCors - Python: Grep for
CORSMiddleware - If found: Return
{ "status": "skipped" }
Phase 2: Analyze Project Structure
Determine frontend configuration.
Detection Steps:
- Check for frontend in same repository (
/frontend,/client,/web) - Read
.envorappsettings.jsonfor CORS_ORIGINS - 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:
- Use MCP ref for current ASP.NET Core CORS API
- Generate CorsExtensions with:
- Development policy (permissive)
- Production policy (restrictive)
- Environment-based policy selection
- 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:
- Use MCP ref for FastAPI CORSMiddleware
- Generate cors_config.py with:
- Origin parsing from environment
- Method and header configuration
- Credentials handling
- Update .env with CORS_ORIGINS
Registration Code:
from middleware.cors_config import configure_cors
configure_cors(app)
Phase 5: Validate
Validation Steps:
-
Syntax check:
- .NET:
dotnet build --no-restore - Python:
python -m py_compile middleware/cors_config.py
- .NET:
-
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 -
Verify headers:
Access-Control-Allow-Origin: Should match request originAccess-Control-Allow-Methods: Should list allowed methodsAccess-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
AllowAnyMethodin 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/UseCorsorCORSMiddlewareexists, returnstatus: "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 buildorpy_compile) - Structured JSON response returned to ln-770 coordinator
Version: 2.0.0 Last Updated: 2026-01-10
04 同仓库更多 Skills
zarr-python
Chunked N-D arrays for cloud storage. Compressed arrays, parallel I/O, S3/GCS integration, NumPy/Dask/Xarray compatible, for large-scale scientific computing pipelines.
zabbix
Zabbix monitoring system automation via API and Python. Use when: (1) Managing hosts, templates, items, triggers, or host groups, (2) Automating monitoring configuration, (3) Sending data via Zabbix trapper/sender, (4) Querying historical data or events, (5) Bulk operations on Zabbix objects, (6) Maintenance window management, (7) User/permission management
x-twitter-growth
X/Twitter growth engine for building audience, crafting viral content, and analyzing engagement. Use when the user wants to grow on X/Twitter, write tweets or threads, analyze their X profile, research competitors on X, plan a posting strategy, or optimize engagement. Complements social-content (generic multi-platform) with X-specific depth: algorithm mechanics, thread engineering, reply strategy, profile optimization, and competitive intelligence via web search.
what-if-oracle
Run structured What-If scenario analysis with multi-branch possibility exploration. Use this skill when the user asks speculative questions like "what if...", "what would happen if...", "what are the possibilities", "explore scenarios", "scenario analysis", "possibility space", "what could go wrong", "best case / worst case", "risk analysis", "contingency planning", "strategic options", or any question about uncertain futures. Also trigger when the user faces a fork-in-the-road decision, wants to stress-test an idea, or needs to think through consequences before committing.
vercel-react-best-practices
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
venue-templates
Access comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.