fix: reject protocol-relative and backslash URLs in safeUrl
Address commit security review: the same-origin branch of safeUrl accepted //host and /\host, which browsers normalize to an external host (open redirect). Allow only true same-origin paths.
This commit is contained in:
parent
f8aa10f91b
commit
7317bfb2b3
1 changed files with 5 additions and 1 deletions
|
|
@ -551,7 +551,11 @@ function safeUrl(value) {
|
|||
|
||||
const url = String(value || "").trim();
|
||||
|
||||
if (/^https?:\/\//i.test(url) || url.startsWith("/")) {
|
||||
// Same-origin path, but reject protocol-relative ("//host") and backslash
|
||||
// ("/\\host") forms that browsers normalize to an external host.
|
||||
const isSameOriginPath = url.startsWith("/") && !url.startsWith("//") && !url.startsWith("/\\");
|
||||
|
||||
if (/^https?:\/\//i.test(url) || isSameOriginPath) {
|
||||
|
||||
return url;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue