fix(ui): validate protocol in useBaseUrl to prevent DOM-based XSS

Only allow http: or https: protocols when constructing the base URL
from window.location, blocking javascript: and data: scheme injection.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
tyh.carl 2026-05-19 15:52:03 +08:00
parent 0290c7bc00
commit dfe4bf6cef

View file

@ -7,7 +7,9 @@ export const useBaseUrl = () => {
useEffect(() => {
if (typeof window !== "undefined") {
const { protocol, host } = window.location;
setBaseUrl(`${protocol}//${host}`);
if (protocol === "http:" || protocol === "https:") {
setBaseUrl(`${protocol}//${host}`);
}
}
}, []); // Removed router dependency