CORS localhost requests are considered invalid host and get blocked
维护者通常 1 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 52/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- javascript, node.js, webpack
调研方向
从 lib/Server.js 中的 cross-origin-header-check 中间件开始,然后跟踪 isValidHost、isHostAllowed 以及 issue 中提到的 validateHost 路径。使用链接的最小复现及其 README 验证行为;当来自 no-cors 跨站 iframe 的 localhost 请求能够成功,且无需将 localhost 显式添加到 allowedHosts 时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Bug Description
If webpack-dev-server gets "no-cors cross-site" requests, localhost is not considered an allowed host and a 403 Forbidden is returned.
By explicitly adding allowedHosts: ['localhost'] to the webpack config, the bug is circumvented.
Link to Minimal Reproduction and step to reproduce
In the following project, an iframe is constructed from a blob HTML string. The iframe contains a script tag which refers to a resource URL which is hosted by webpack dev server.
https://github.com/RedMser/bug-webpack-dev-server-corb
See the readme in the repo for reproduction steps.
Expected Behavior
Requests to localhost should succeed, even if they originate from a "no-cors cross-site" context.
Actual Behavior
The request fails with a 403 Forbidden response.
Environment
System:
OS: Windows 11 10.0.26100
CPU: (4) x64 Intel(R) Xeon(R) Platinum 8462Y+
Memory: 2.84 GB / 19.00 GB
Binaries:
Node: 24.11.1 - C:\nvm4w\nodejs\node.EXE
npm: 11.6.2 - C:\nvm4w\nodejs\npm.CMD
Browsers:
Chrome: 141.0.7390.123
Edge: Chromium (141.0.3537.57)
Firefox: 140.5.0 - C:\Program Files\Mozilla Firefox\firefox.exe
Internet Explorer: 11.0.26100.1882
Packages:
webpack: ^5.102.1 => 5.102.1
webpack-cli: ^6.0.1 => 6.0.1
webpack-dev-server: ^5.2.2 => 5.2.2
Is this a regression?
None
Last Working Version
No response
Additional Context
Responsible is the cross-origin-header-check middleware.
In particular, isValidHost calls isHostAllowed which contains following comment:
According to this outdated comment, localhost should be always allowed, but there is no code that actually ensures this here!
isValidHost does check for localhost among other things, but validateHost == false in this particular instance.
It might be caused by the refactor in 6045b1e9d63078fb24cac52eb361b7356944cddd but I did not investigate further. This used to work in the past so it's likely a regression, let me know if more info is needed.
- 主要语言
- JavaScript
- 星标
- 7.9k
- 派生
- 1.5k
- 平均合并
- 2 天 12 小时
- 30 天内合并 PR
- 8
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
webpack/webpack-dev-server 的其他 Issue
-
Add support for Chrome DevTools Workspaces可能重新可做 @AnumanyaJaiswal 于 35 天前认领,目前没有进行中的 PR。 未关闭
难度 4/5 3-5 天 新手友好度 45/100
webpack/webpack-dev-server#5716 · 2 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 45/100
webpack/webpack-dev-server#5679 · 3 条评论 ·
维护者通常 1 天内回复
-
Webpack dev server URL should be displayed more prominently可能已有人在做 @snitin315 于 805 天前认领。 未关闭
webpack/webpack-dev-server#4907 · 7 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 35/100
webpack/webpack-dev-server#4540 · 9 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
webpack/webpack-dev-server#4378 · 29 条评论 · 3 个 reaction ·
维护者通常 1 天内回复
查看 webpack/webpack-dev-server 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 64/100
babalae/bettergi-scripts-list#3905 · 1 条评论 ·
维护者通常 1 天内回复
-
[Bug] "Configure Colota" opens Colota with "Invalid configuration: No configuration data in URL"未关闭
难度 1/5 1-3 小时 新手友好度 87/100
dedicatedcode/reitti#1445 ·
维护者通常 1 天内回复
-
New tool: Uncle Desk可能已有人在做 @github-actions 今天认领。 未关闭submission triage
难度 1/5 1 小时以内 新手友好度 85/100
kausalflow/tools#384 · 1 条评论 ·
维护者通常 1 天内回复
-
good first issue
难度 2/5 1-3 小时 新手友好度 67/100
-
area: css
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复