fix(js): keep standard sse same-origin
Require non-empty data-slhx-sse values at build time and have the standard runtime reject cross-origin EventSource URLs with slhx:sse-error instead of opening an implicit external stream. req: push/006 req: diagnostics/002
This commit is contained in:
@@ -637,7 +637,12 @@
|
||||
function bindSse(root) {
|
||||
const url = root.getAttribute("data-slhx-sse");
|
||||
if (!url || sseSources.has(root) || typeof EventSource === "undefined") return;
|
||||
const source = new EventSource(new URL(url, location.href).href);
|
||||
const href = new URL(url, location.href);
|
||||
if (href.origin !== location.origin) {
|
||||
emit(root, "slhx:sse-error", url);
|
||||
return;
|
||||
}
|
||||
const source = new EventSource(href.href);
|
||||
source.addEventListener("slhx", (event) => applySseMessage(root, event));
|
||||
source.addEventListener("message", (event) => applySseMessage(root, event));
|
||||
source.addEventListener("error", () => emit(root, "slhx:sse-error", url));
|
||||
|
||||
Reference in New Issue
Block a user