url: pathToFileURL duplicates root slash across platforms and misses empty extended UNC servername
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 72/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, node.js
Hướng nghiên cứu
Bắt đầu tại lib/internal/url.js, ở hai vị trí được xác định trong issue, rồi đọc logic pathToFileURL() xung quanh và các bài kiểm thử URL liên quan. Tái hiện các trường hợp dấu gạch chéo gốc với { windows: false } và { windows: true }, đồng thời kiểm tra cách các bài kiểm thử hiện có bao phủ tên máy chủ UNC mở rộng rỗng. Công việc hoàn tất khi các URL đa nền tảng có đúng một dấu gạch chéo ở cuối và tên máy chủ rỗng gây ra ERR_INVALID_ARG_VALUE.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Version
v22.16.0 (also reproduces on main)
Platform
Microsoft Windows NT 10.0.26100.0 x64 (and POSIX platforms when passing `{ windows: true }`)
Subsystem
url
What steps will reproduce the bug?
url.pathToFileURL() has two bugs in lib/internal/url.js:
-
Cross-platform root path trailing slash duplication (
resolved[resolved.length - 1] !== path.sep):
When restoring trailing slashes stripped bypath.resolve(),pathToFileURL()compares the last character ofresolvedagainst the host platform'spath.sepinstead of the target separator (windows ? '\\' : '/'):// On Windows (where path.sep === '\\'): console.log(url.pathToFileURL('/', { windows: false }).href); // Prints: 'file:////' (4 slashes instead of 'file:///') // On POSIX / Linux / macOS (where path.sep === '/'): console.log(url.pathToFileURL('C:\\', { windows: true }).href); // Prints: 'file:///C://' (double trailing slash instead of 'file:///C:/') -
Extended UNC path empty servername bypass (
hostnameEndIndex === 2):
For extended UNC paths (\\?\UNC\...),prefixLengthis8, but the empty servername check hardcodesif (hostnameEndIndex === 2)instead ofif (hostnameEndIndex === prefixLength):console.log(url.pathToFileURL('\\\\?\\UNC\\\\share', { windows: true }).href); // Prints: 'file:///share' instead of throwing ERR_INVALID_ARG_VALUE ('Empty UNC servername')
How often does it reproduce? Is there a required condition?
Always (100% reproducible).
What is the expected behavior? Why is that the expected behavior?
url.pathToFileURL('/', { windows: false }).hrefshould return'file:///'on all platforms (including Windows).url.pathToFileURL('C:\\', { windows: true }).hrefandurl.pathToFileURL('C:/', { windows: true }).hrefshould return'file:///C:/'on all platforms (including POSIX).url.pathToFileURL('\\\\?\\UNC\\\\share', { windows: true })should throwERR_INVALID_ARG_VALUE(Empty UNC servername), matchingurl.pathToFileURL('\\\\\\share', { windows: true }).
What do you see instead?
url.pathToFileURL('/', { windows: false }).hrefon Windows returns'file:////'.url.pathToFileURL('C:\\', { windows: true }).hrefon POSIX returns'file:///C://'.url.pathToFileURL('\\\\?\\UNC\\\\share', { windows: true }).hrefreturns'file:///share'.
Additional information
In lib/internal/url.js:
- Line 1707 checks
if (hostnameEndIndex === 2)instead ofif (hostnameEndIndex === prefixLength). - Line 1722 checks
resolved[resolved.length - 1] !== path.sepinstead ofresolved[resolved.length - 1] !== (windows ? '\\' : '/').
- Ngôn ngữ chính
- JavaScript
- Star
- 123k
- Fork
- 39.3k
- Merge trung bình
- 4 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 240
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của nodejs/node
-
util.parseEnv and --env-file keep a leading UTF-8 BOM in the first keyCó thể đã có người làm @helmipradita đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
node:internal/inspector/network_http: `TypeError: Missing dataLength` in event when response uses `setEncoding()`Có thể đã có người làm @lazerg đã nhận 24 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
nodejs/node#66551 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Docs] `process.loadEnvFile()` does not document behaviour when variables already existCó thể đã có người làm @Sepandard đã nhận 34 ngày trước. Đang mởdoc
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Stream.prototype.forEach will block in first promise in queue before read more chunkCó thể đã có người làm @mmustafasenoglu đã nhận 35 ngày trước. Đang mởdoc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
nodejs 26.8.2 fails to build with clang/LLVMCó thể làm lại được @btyagi18 đã nhận 21 ngày trước và không có pull request nào đang mở. Đang mởbuild
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
nodejs/node#66076 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
follow-redirects updateĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
mailgun/mailgun.js#544 ·
-
beginner bug frontend
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
BistaDinesh03/critique#266 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
solana-foundation/solana-web3.js#4015 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: dependencies auto-generated cwe: 405 dependencies ecosystem: npm help wanted package: minimatch scope: runtime security security-alert severity: medium source: dependabot supply-chain vulnerability
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 65/100
tdk-landscape/tdk-cli-core#2811 ·
-
a11y bug confirmed issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
open-webui/open-webui#33442 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày