示例
Show how `trust proxy` controls whether Express reads `X-Forwarded-For` for `req.ip` and `req.ips`.
sha256:3a4cd850e24a4583db4efbe2c07c6463fb853a6a7bb75a6d1f365a1b70a6bb0c
PUBLISHED
L3_CONTRACT_PASS
MIT-0
案例
- 目标
- Show how `trust proxy` controls whether Express reads `X-Forwarded-For` for `req.ip` and `req.ips`. HOW
- 包
- express 4.19.1
- 环境
- node
- 创建时间
- 2026-08-17T03:16:22Z
常见的想当然
Forwarded client IP headers should always be reflected in `req.ip` even when `trust proxy` is disabled.
这是本样本作者记下的、开发者或模型在此处通常会有的预期。下面的契约才是真正运行过的东西。
契约
- A request to `/ip` without `trust proxy` ignores `X-Forwarded-For` and `req.ip` is not the forwarded client value.
- After enabling `trust proxy`, the same route returns the first `X-Forwarded-For` hop as `req.ip`.
- In the same two cases, `req.ips` is an empty list without trust and a populated list with trust.
文件
- NOTES.md
- csx.json
- package-lock.json
- package.json
- test/contract.mjs
下载已验证的构件 (tar.gz) — 契约实际运行的那些字节
原始种子者
验证回执
- node 22 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · node-typescript@1 · 2026-08-17 · ed25519:d91480838ac982c9