fix: honor empty URL query and fragment markers (#2091)

URL.search and URL.hash are empty for both a missing component and an explicit empty one, so endpoint and origin checks were accepting URLs the callers meant to reject.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Faheem Ahmad
2026-10-13 06:05:29 +09:00
committed by GitHub
co-authored by Cursor
parent d59ab6d977
commit af29247a78
10 changed files with 62 additions and 14 deletions
+4 -4
View File
@@ -1,5 +1,7 @@
import { z } from "zod";
import { urlDeclaresQueryOrFragment } from "./urlComponents.js";
const parseExactOrigin = (value: string): string | undefined => {
let url: URL;
try {
@@ -15,8 +17,7 @@ const parseExactOrigin = (value: string): string | undefined => {
url.username !== "" ||
url.password !== "" ||
url.pathname !== "/" ||
url.search !== "" ||
url.hash !== ""
urlDeclaresQueryOrFragment(url)
)
return undefined;
return url.origin;
@@ -63,8 +64,7 @@ export const browserEndpointSchema = z
url.username !== "" ||
url.password !== "" ||
url.pathname !== "/" ||
url.search !== "" ||
url.hash !== ""
urlDeclaresQueryOrFragment(url)
) {
context.addIssue({
code: "custom",