Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit ef1cb95

Browse files
author
Luke Barnard
committed
Allow integration UI URLs with paths
The postMessage API assumed that event origins contained paths of their window origins, but they do not (https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage). This changes the origin check such that the integrations UI URL must start with the event origin.
1 parent c0b931a commit ef1cb95

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/ScalarMessaging.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,15 @@ const onMessage = function(event) {
292292
event.origin = event.originalEvent.origin;
293293
}
294294

295-
// check it is from the integrations UI URL (remove trailing spaces)
295+
// Check that the integrations UI URL starts with the origin of the event
296+
// This means the URL could contain a path (like /develop) and still be used
297+
// to validate event origins, which do not specify paths.
298+
// (See https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage)
299+
//
300+
// All strings start with the empty string, so for sanity return if the length
301+
// of the event origin is 0.
296302
let url = SdkConfig.get().integrations_ui_url;
297-
if (url.endsWith("/")) {
298-
url = url.substr(0, url.length - 1);
299-
}
300-
if (url !== event.origin) {
303+
if (event.origin.length === 0 || !url.startsWith(event.origin)) {
301304
return; // don't log this - debugging APIs like to spam postMessage which floods the log otherwise
302305
}
303306

0 commit comments

Comments
 (0)