Skip to content

Commit 8c3f16b

Browse files
authored
fix: accept ipv4-mapped ipv6 loopback in vfs handler (#4212)
1 parent 0a6cd73 commit 8c3f16b

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/dev/vfs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ export function createVFSHandler(nitro: Nitro) {
1515
socket?.readable && socket?.writable && !socket?.remotePort;
1616

1717
const ip = getRequestIP(event, { xForwardedFor: isUnixSocket });
18+
const v4 = ip?.toLowerCase().startsWith("::ffff:") ? ip.slice(7) : ip;
1819

19-
const isLocalRequest = ip && /^::1$|^127\.\d+\.\d+\.\d+$/.test(ip);
20+
const isLocalRequest = v4 && /^(?:::1|127\.\d+\.\d+\.\d+)$/.test(v4);
2021
if (!isLocalRequest) {
2122
throw new HTTPError({
2223
statusText: `Forbidden IP: "${ip || "?"}"`,

0 commit comments

Comments
 (0)