mirror of
https://github.com/outline/outline.git
synced 2026-12-05 18:55:10 +03:00
fix: Improve validation of urls extracted from data transfer event (#10740)
This commit is contained in:
1 parent
e85fbf3299
commit
7ce407910e
1 file changed
+27
-1
+27
-1
@@ -1,4 +1,5 @@
|
||||
import { isMac } from "./browser";
|
||||
import { isUrl } from "./urls";
|
||||
|
||||
/**
|
||||
* Converts bytes to human readable string for display
|
||||
@@ -45,11 +46,36 @@ export function getDataTransferImage(
|
||||
const untrustedHTML = dt?.getData("text/html");
|
||||
|
||||
try {
|
||||
return untrustedHTML
|
||||
const src = untrustedHTML
|
||||
? new DOMParser()
|
||||
.parseFromString(untrustedHTML, "text/html")
|
||||
.querySelector("img")?.src
|
||||
: dt?.getData("url");
|
||||
|
||||
// Validate URL to prevent XSS attacks
|
||||
if (src && typeof src === "string") {
|
||||
// Allow relative URLs starting with /
|
||||
if (src.startsWith("/")) {
|
||||
return src;
|
||||
}
|
||||
|
||||
// Allow data URLs only for images
|
||||
if (src.toLowerCase().startsWith("data:image/")) {
|
||||
return src;
|
||||
}
|
||||
|
||||
// For all other URLs, use isUrl which blocks dangerous protocols
|
||||
if (
|
||||
isUrl(src, {
|
||||
requireProtocol: false,
|
||||
requireHostname: false,
|
||||
})
|
||||
) {
|
||||
return src;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
} catch (_err) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user