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

Commit fe0dc85

Browse files
authored
Merge pull request #583 from matrix-org/luke/fix-post-message-api-origin-check
Allow integration UI URLs with paths
2 parents b3f642e + ef1cb95 commit fe0dc85

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)