# 400 错误请求：查询参数包含被屏蔽的 SQL 关键字

- **ID:** `api/rest-query-parameter-sql-injection-blocked`
- **领域:** api
- **类别:** security_error
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

API 网关或 WAF（Web 应用防火墙）将查询参数值标记为包含 SQL 注入模式（例如 SELECT、DROP、UNION）并拒绝了该请求。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| AWS WAF 2024 | active | — | — |
| Cloudflare WAF 2023 | active | — | — |
| Kong Gateway 3.5 | active | — | — |
| nginx ModSecurity 3.0 | active | — | — |

## 解决方案

1. ```
   对于接受可能包含 SQL 关键字的用户输入的搜索/过滤端点，使用 POST 请求加 JSON 体代替 GET 加查询参数。这将负载移出 URL，WAF 规则通常对请求体不那么激进。
   ```
2. ```
   如果某个参数（如 'search' 或 'query'）已知会接受可能包含类似 SQL 模式的任意文本作为合法数据（例如代码搜索工具），则为该特定参数名称添加 WAF 例外规则。
   ```

## 无效尝试

- **** — Modern WAFs decode URL-encoded payloads before inspection; double encoding may work temporarily but is often patched quickly and violates API standards. (85% 失败率)
- **** — This removes critical security protection, making the API vulnerable to actual SQL injection attacks; not recommended for production. (95% 失败率)
