Skip to content

Commit

Permalink
Fix safe apps msg parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Oct 29, 2023
1 parent 71222ef commit 97af353
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/safe-apps/AppFrame/useAppCommunicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ const useAppCommunicator = (
const initCommunicator = (iframeRef: MutableRefObject<HTMLIFrameElement>, app?: SafeAppData) => {
communicatorInstance = new AppCommunicator(iframeRef, {
onMessage: (msg) => {
if (!msg.data) return

const isCustomApp = app && app.id < 1

trackSafeAppEvent(
Expand Down
1 change: 1 addition & 0 deletions src/components/safe-apps/AppFrame/useFromAppAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const ALLOWED_DOMAINS: RegExp[] = [
const useAnalyticsFromSafeApp = (iframeRef: MutableRefObject<HTMLIFrameElement | null>): void => {
const isValidMessage = useCallback(
(msg: MessageEvent<AnalyticsEvent>) => {
if (!msg.data) return false
const isFromIframe = iframeRef.current?.contentWindow === msg.source
const isCategoryAllowed = msg.data.category === SAFE_APPS_ANALYTICS_CATEGORY
const isDomainAllowed = ALLOWED_DOMAINS.find((regExp) => regExp.test(msg.origin)) !== undefined
Expand Down
2 changes: 2 additions & 0 deletions src/services/safe-apps/AppCommunicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class AppCommunicator {
}

private isValidMessage = (msg: SDKMessageEvent): boolean => {
if (!msg.data) return false
if (msg.data.hasOwnProperty('isCookieEnabled')) {
return true
}
Expand All @@ -40,6 +41,7 @@ class AppCommunicator {
}

private canHandleMessage = (msg: SDKMessageEvent): boolean => {
if (!msg.data) return false
return Boolean(this.handlers.get(msg.data.method))
}

Expand Down

0 comments on commit 97af353

Please sign in to comment.