背景与价值 CL/TE走私利用不同代理与后端的解析差异触发边界绕过。统一一致性与规范化策略可在入口处阻断风险。 统一规范 - 头一致性:`Transfer-Encoding: chunked` 与 `Content-Length` 不能共存;拒绝多 `Content-Length` 或异常格式。 - 规范化解析:统一小写头键、去重并保留首个合法值。 - 禁止模糊:拒绝混淆写法(如 `Transfer-Encoding: chunked, gzip`)。 核心实现 一致性与规范化校验 ```ts type Headers = Record function normalize(headers: Headers): Record { const out: Record = {} for (const [k, v] of Object.entries(headers)) { if (v == null) continue const key = k.toLowerCase() if (!(key in out)) out[key] = String(v).trim() } return out } function hasChunked(te: string): boolean { return te.split(',').map(s => s.trim().toLowerCase()).includes('chunked') } function validContentLength(cl: string): boolean { return /^\d+$/.test(cl) } function securityCheck(headers: Headers): boolean { const h = normalize(headers) const te = h['transfer-encoding'] const cl = h['content-length'] if (te && cl) return false if (te) { if (!hasChunked(te)) return false if (te.includes(',')) return false } if (cl) { if (!validContentLength(cl)) return false } return true } ``` 落地建议 - 在代理与网关层统一执行规范化与一致性校验,拒绝不合规请求。 - 对含有多 `Content-Length` 或混合 `Transfer-Encoding` 的请求直接阻断并记录审计。 - 保持后端解析策略与代理一致,避免差异导致绕过。 验证清单 - 是否拒绝同时包含 `Content-Length` 与 `Transfer-Encoding: chunked` 的请求。 - 是否拒绝多 `Content-Length`、异常格式或混合编码的请求。

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部