CORS 测试器: 调试并生成 CORS 配置 - Openclaw Skills
什么是 CORS Tester?
CORS Tester 是一款专门设计的工具,旨在通过验证服务器如何处理跨源请求,帮助开发人员排除故障并保护其 Web 应用程序。作为 Openclaw Skills 生态系统的关键组件,它允许检查响应标头、模拟预检 OPTIONS 请求以及识别常见的安全配置错误。
除了简单的测试外,该技能还提供了一个配置生成器,可为流行的 Web 服务器和框架生成生产就绪的代码片段。这确保了您的 CORS 策略既实用又安全,在保持无缝的前后端集成的同时,降低了未经授权数据访问的风险。
下载入口:https://github.com/openclaw/skills/tree/main/skills/johnnywang2001/cors-tester
安装与下载
1. ClawHub CLI
从源直接安装技能的最快方式。
npx clawhub@latest install cors-tester
2. 手动安装
将技能文件夹复制到以下位置之一
全局模式~/.openclaw/skills/
工作区
<project>/skills/
优先级:工作区 > 本地 > 内置
3. 提示词安装
将此提示词复制到 OpenClaw 即可自动安装。
请帮我使用 Clawhub 安装 cors-tester。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。
CORS Tester 应用场景
- 在浏览器控制台的后端开发过程中调试 CORS 错误。
- 审计实时 API 的安全漏洞,如源反射或过度宽松的通配符。
- 验证预检 OPTIONS 请求是否返回正确的允许方法和标头。
- 为 Nginx、Apache 或 Express 部署生成样板 CORS 配置代码。
- 用户通过 CLI 提供目标 URL 和模拟源。
- 该技能发送包含指定源和标头的 HTTP 请求(或用于预检的 OPTIONS 请求)。
- 它捕获并解析服务器响应,专门查找 Access-Control-Allow-* 标头。
- 对于安全审计,它执行一系列测试,以检查常见的配置错误,例如通配符源与凭据结合使用。
- 如果有要求,它会根据验证的参数为目标框架生成代码片段。
CORS Tester 配置指南
要将此工具集成到您的环境中,请确保已安装 Python 3。您可以使用以下模式直接从终端执行脚本:
# Test basic CORS headers
python3 scripts/cors_tester.py test https://api.example.com/data --origin https://myapp.com
# Run a security audit
python3 scripts/cors_tester.py audit https://api.example.com/data
CORS Tester 数据架构与分类体系
该技能根据以下类别处理和生成数据:
| 数据类型 | 描述 |
|---|---|
| 测试结果 | 验证 Access-Control-Allow-Origin、凭据和公开的标头。 |
| 预检数据 | 评估允许的方法、标头和 Max-Age 缓存持续时间。 |
| 审计日志 | 识别诸如缺失 Vary: Origin 标头或源反射之类的问题。 |
| 配置模板 | 适用于 nginx、apache、express、flask、fastapi 和 rails 的片段。 |
name: cors-tester
description: Test and debug CORS (Cross-Origin Resource Sharing) configurations on live URLs. Use when checking if a server returns correct CORS headers, debugging CORS errors, testing preflight OPTIONS requests, verifying allowed origins/methods/headers, or auditing CORS security posture. Also use when generating CORS configurations for Apache, Nginx, Express, or other frameworks.
cors-tester
Test, debug, and generate CORS configurations from the command line.
Quick Start
# Test CORS headers on a URL
python3 scripts/cors_tester.py test https://api.example.com/data --origin https://myapp.com
# Test preflight (OPTIONS) request
python3 scripts/cors_tester.py preflight https://api.example.com/data --origin https://myapp.com --method POST --header "Content-Type"
# Generate CORS config for a framework
python3 scripts/cors_tester.py config --framework nginx --origins "https://myapp.com,https://staging.myapp.com" --methods "GET,POST,PUT,DELETE"
# Audit CORS security
python3 scripts/cors_tester.py audit https://api.example.com/data
Commands
test
Send a request with an Origin header and inspect the CORS response headers.
python3 scripts/cors_tester.py test <url> --origin <origin> [--method GET]
Options:
--origin <url>— Origin to test (required)--method <method>— HTTP method (default: GET)--verbose— Show all response headers
Output shows:
Access-Control-Allow-Origin— Whether the origin is allowedAccess-Control-Allow-Credentials— Whether credentials are supportedAccess-Control-Expose-Headers— Which headers are exposed
preflight
Send an OPTIONS preflight request to test if a cross-origin request would be allowed.
python3 scripts/cors_tester.py preflight <url> --origin <origin> [--method POST] [--header Content-Type]
Options:
--origin <url>— Origin to test (required)--method <method>— Method to request (default: POST)--header <name>— Custom header to request (repeatable)
Output shows:
Access-Control-Allow-Methods— Allowed methodsAccess-Control-Allow-Headers— Allowed headersAccess-Control-Max-Age— Preflight cache duration
audit
Check a URL for common CORS misconfigurations and security issues.
python3 scripts/cors_tester.py audit <url>
Checks for:
- Wildcard origin (
*) with credentials - Origin reflection (server echoes any origin back)
- Missing
Vary: Originheader - Overly permissive allowed methods
- Missing preflight cache (
Access-Control-Max-Age)
config
Generate CORS configuration snippets for common frameworks.
python3 scripts/cors_tester.py config --framework <name> --origins <origins> [--methods <methods>] [--headers <headers>] [--credentials]
Options:
--framework <name>— Target:nginx,apache,express,flask,fastapi,rails--origins <csv>— Comma-separated allowed origins--methods <csv>— Comma-separated methods (default:GET,POST,OPTIONS)--headers <csv>— Comma-separated allowed headers (default:Content-Type,Authorization)--credentials— Allow credentials--max-age <seconds>— Preflight cache (default: 86400)