Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

netlify dev returns 403 for static files in subdirectories on Windows (backslash in rewritten path)

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

维护者通常 1 天内回复

@Ramnath0521 已经在做这个了。

开始于 2026年10月6日。

  • #8571 来自 @Ramnath0521 —— 未关闭

评估

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

调研方向

从 dist/utils/proxy.js 中的 getStatic 开始,重点查看构建重写 URL 的 path.relative 调用。在 Windows 上使用包含 css/styles.css 的发布文件夹,并通过 netlify dev 请求该文件进行复现。当嵌套的静态文件能够通过代理获得 200,与根目录文件以及 macOS/Linux 上的行为一致时,即表示完成。

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

描述

Describe the bug

On Windows, netlify dev returns 403 Forbidden for any static file inside a subdirectory of the publish folder (e.g. /css/styles.css, /js/app.js). Files at the root of the publish folder (e.g. /index.html, /manifest.json) are served fine.

The cause is in getStatic in dist/utils/proxy.js (line 116 in 27.10.2):

return `/${path.relative(publicFolder, file)}`;

On Windows path.relative returns backslash-separated paths, so /css/styles.css becomes /css\styles.css. It is then passed through encodeURI (req.url = encodeURI(decodeURI(pathname)) + reqUrl.search) and forwarded as /css%5Cstyles.css, which @fastify/static in the static server rejects with:

{"statusCode":403,"error":"Forbidden","message":"Forbidden"}
Steps to reproduce
  1. On Windows, a site with publish = "src" and src/css/styles.css
  2. [dev] framework = "#static" (same result with netlify dev --dir src)
  3. netlify dev
  4. curl http://localhost:8888/css/styles.css → 403
  5. curl http://localhost:<static server port>/css/styles.css (bypassing the proxy) → 200
Expected behavior

/css/styles.css is served with 200 through the netlify dev proxy, as on macOS/Linux and in production.

Actual behavior

403 for every static file in a subdirectory, so pages load without their CSS/JS.

Notes
  • Windows-specific: on macOS/Linux path.relative returns forward slashes, so the path is correct. Production (Netlify CDN) is not affected.
  • Possible fix: normalize the separator, e.g.
    return `/${path.relative(publicFolder, file).split(path.sep).join('/')}`;
Environment
  • netlify-cli 27.10.2
  • Node.js v24.15.0
  • Windows 11 (10.0.26200)
主要语言
TypeScript
星标
1.9k
派生
478
平均合并
2 天 17 小时
30 天内合并 PR
63

环境准备

从这里开始

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

netlify/cli 的其他 Issue

查看 netlify/cli 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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