You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/06/03 18:49:57 UTC

[GitHub] [superset] suddjian commented on a diff in pull request #20251: feat(embedded): enforce allow domains

suddjian commented on code in PR #20251:
URL: https://github.com/apache/superset/pull/20251#discussion_r889244838


##########
superset-frontend/src/embedded/index.tsx:
##########
@@ -154,15 +157,39 @@ function setupGuestClient(guestToken: string) {
 }
 
 function validateMessageEvent(event: MessageEvent) {
-  // if (!ALLOW_ORIGINS.includes(event.origin)) {
-  //   throw new Error('Message origin is not in the allowed list');
-  // }
-
   if (typeof event.data !== 'object' || event.data.type !== MESSAGE_TYPE) {
     throw new Error(`Message type does not match type used for embedded comms`);
   }
 }
 
+function validateAllowedDomains() {
+  const uuid = window.location.pathname.replace('/embedded/', '');
+  const getDashaboardConfig = makeApi<void, { result: EmbeddedDashboard }>({
+    method: 'GET',
+    endpoint: `/api/v1/embedded_dashboard/${uuid}`,
+  });
+  return getDashaboardConfig().then(
+    ({ result }) => {
+      const parentOrigin = new URL(document.referrer).origin;
+      if (
+        result.allowed_domains.length > 0 &&
+        !result.allowed_domains.includes(parentOrigin)
+      ) {
+        showFailureMessage(
+          `iframe parent ${parentOrigin} is not in the list of allowed domains`,
+        );
+      }
+    },
+    err => {

Review Comment:
   Looks like you copied this from the `getMe` call in the `start` function, but that endpoint is specifically being used to check guest token validity. This error handler is inappropriate outside that case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org