[ PROMPT_NODE_23962 ]
API Shield 设计模式
[ SKILL_DOCUMENTATION ]
# 模式与用例
## 使用模式 + JWT 保护 API
bash
# 1. 上传 OpenAPI 模式
POST /zones/{zone_id}/api_gateway/user_schemas
# 2. 配置 JWT 验证
POST /zones/{zone_id}/api_gateway/token_validation
{
"name": "Auth0",
"location": {"header": "Authorization"},
"jwks": "{...}"
}
# 3. 创建 JWT 规则
POST /zones/{zone_id}/api_gateway/jwt_validation_rules
# 4. 设置模式验证操作
PUT /zones/{zone_id}/api_gateway/settings/schema_validation
{"validation_default_mitigation_action": "block"}
## 渐进式部署
1. Log 模式: 观察误报
- 模式: 操作 = Log
- JWT: 操作 = Log
2. 阻止子集: 保护关键端点
- 将特定端点操作更改为 Block
- 监控防火墙事件
3. 全面强制执行: 阻止所有违规
- 将默认操作更改为 Block
- 使用自定义规则处理兜底 (Fallthrough)
## BOLA 检测
### 枚举检测
检测顺序资源访问 (例如 `/users/1`, `/users/2`, `/users/3`)。
javascript
// 阻止 BOLA 枚举尝试
(cf.api_gateway.cf-risk-bola-enumeration and http.host eq "api.example.com")
// 操作: Block 或 Challenge
### 参数污染
检测请求中重复/过多的参数。
javascript
// 阻止参数污染
(cf.api_gateway.cf-risk-bola-pollution and http.host eq "api.example.com")
// 操作: Block
### 组合 BOLA 保护
javascript
// 综合 BOLA 规则
(cf.api_gateway.cf-risk-bola-enumeration or cf.api_gateway.cf-risk-bola-pollution)
and http.host eq "api.example.com"
// 操作: Block
## 身份验证态势
### 检测缺失身份验证
javascript
// 记录缺乏身份验证的端点
(cf.api_gateway.cf-risk-missing-auth and http.host eq "api.example.com")
// 操作: Log (用于审计)
### 检测混合身份验证
javascript
// 对不一致的身份验证模式发出警报
(cf.api_gateway.cf-risk-mixed-auth and http.host eq "api.example.com")
// 操作: Log (需要审查)
## 兜底检测 (影子 API)
javascript
// WAF 自定义规则
(cf.api_gateway.fallthrough_triggered and http.host eq "api.example.com")
// 操作: Log (发现未知) 或 Block (严格)
## 按用户进行速率限制
javascript
// 速率限制规则 (现代语法)
(http.host eq "api.example.com" and
is_jwt_valid(http.request.jwt.payload["{config_id}"][0]))
// 速率: 100 请求/60秒
// 计数表达式: lookup_json_string(http.request.jwt.payload["{config_id}"][0], "sub")