req.subdomains splits an IPv6 host that contains dots

未关闭 适合新手
#7,532 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@johnnyhuirilef 已经在做这个了。

开始于 2026年10月20日。

  • #7533 来自 @johnnyhuirilef —— 未关闭
  • #7536 来自 @princejain756 —— 已关闭,未合并
  • #7540 来自 @XRafik —— 已关闭,未合并
  • #7545 来自 @princejain756 —— 已关闭,未合并
  • #7556 来自 @johnhldiver-beep —— 已关闭,未合并
  • #7558 来自 @light1563 —— 已关闭,未合并
  • #7566 来自 @DipanshuAmbilkar03 —— 已关闭,未合并

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
api, backend

调研方向

从 lib/request.js 中的 req.subdomains 开始,阅读它如何使用 net.isIP() 检查 req.hostname。在现有的 IPv6 子域名测试旁,添加一个针对带点分隔的 IPv4-mapped IPv6 主机的回归测试。默认偏移量返回 [],且偏移量 0 保留完整的方括号括起的主机,即表示完成;issue 报告了预期输出。

由索引模型根据 Issue 内容生成。

描述

4.x 5.x bug

Hi! 🙂 req.subdomains splits an IPv6 host that contains dots.

Environment information

Version: express 5.3.0 (4.22.3 gives the same result)

Platform: Darwin 27.0.0

Node.js version: v24.21.0

Any other relevant information: None.

What steps will reproduce the bug?

req.subdomains does not split a host that is an IP address. This works for [::1]. An IPv6 address can also contain dots, for example the IPv4-mapped address [::ffff:127.0.0.1]. req.subdomains splits that host on the dots:

const express = require('express')
const app = express()

app.get('/', (req, res) => res.json(req.subdomains))
app.listen(3000)
curl -H 'Host: [::1]' http://localhost:3000/
# []

curl -H 'Host: [::ffff:127.0.0.1]' http://localhost:3000/
# ["0","[::ffff:127"]

Full repro, with npm run repro: https://github.com/johnnyhuirilef/expressjs-repros/tree/main/subdomains-ipv6-dotted-host

Note: fetch() rewrites the host to [::ffff:7f00:1], so it does not show the bug. curl, http.get() and X-Forwarded-Host (with trust proxy) send the host as written.

What is the expected behavior?

[] for [::ffff:127.0.0.1], the same as for [::1]. With subdomain offset set to 0, the expected value is ["[::ffff:127.0.0.1]"].

What do you see instead?

["0","[::ffff:127"]. With subdomain offset set to 0: ["1]","0","0","[::ffff:127"].

Additional information

req.hostname keeps the brackets of an IPv6 literal. req.subdomains passes that value to net.isIP() in lib/request.js, and isIP('[::ffff:127.0.0.1]') returns 0. The existing [::1] test passes only because that address has no dots.

I have a fix with tests. Happy to open a PR 🙌

主要语言
JavaScript
星标
69.7k
派生
25.6k
平均合并
2 天 9 小时
30 天内合并 PR
4

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

expressjs/express 的其他 Issue

查看 expressjs/express 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。