Copilot commented on code in PR #40629: URL: https://github.com/apache/superset/pull/40629#discussion_r3337853969
########## superset-frontend/src/embedded/originValidation.ts: ########## @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// The message type used for the embedded comms handshake. Must stay in sync +// with the parent SDK's handshake messages. +export const MESSAGE_TYPE = '__embedded_comms__'; + +/** + * Validates the origin of an incoming postMessage event against the dashboard's + * configured allowed domains. + * + * Enforcement is opt-in by configuration: if the allowed-domains list is empty + * or undefined, any origin is accepted (no restriction), which preserves the + * historical behavior for embeds that did not configure domains. When the list + * is non-empty, only origins present in the list are accepted. + */ +export function isMessageOriginAllowed( + origin: string, + allowedDomains?: string[], +): boolean { + if (!allowedDomains || allowedDomains.length === 0) { + return true; + } + if (allowedDomains.includes(origin)) { + return true; + } + // eslint-disable-next-line no-console + console.warn( + `[superset] ignoring embedded message from origin "${origin}" which is not in the list of allowed domains`, + ); + return false; Review Comment: The frontend uses exact-string equality (`allowedDomains.includes(origin)`) to compare `event.origin` against the configured allowed domains, but the backend uses `flask_wtf.csrf.same_origin` which compares scheme+host+port and tolerates path/trailing-slash differences. `event.origin` is always normalized by the browser to `scheme://host[:port]` with no path or trailing slash, so any allowed-domain entry that includes a path or trailing slash (e.g. `https://example.com/` or `https://app.example.com/embed`) will pass the backend referrer check but be rejected here, silently breaking embeds that the backend has already authorized. Consider parsing each entry with `new URL(domain).origin` (guarded against invalid values) and comparing against `event.origin`, so the two layers agree on what an "allowed domain" means. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
