Skip to content

Commit

Permalink
check against earlier registered origin instead of valid origins
Browse files Browse the repository at this point in the history
  • Loading branch information
imolorhe committed May 29, 2024
1 parent 1058696 commit 1e8b51e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/altair-iframe-sandbox/src/evaluator.frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,25 @@ import {
ScriptEvaluatorWorker,
ScriptWorkerMessageData,
} from 'altair-graphql-core/build/script/types';
import { validOrigins } from 'altair-graphql-core/build/origins';

export class EvaluatorFrameWorker extends ScriptEvaluatorWorker {
origin = '';
private origin: string;

constructor() {
super();
const params = new URLSearchParams(window.location.search);
// Get the source origin that embeds the iframe from the URL query parameter
const source = params.get('sc');

if (!source || !validOrigins.includes(source)) {
if (!source) {
throw new Error('Invalid source provided!');
}
this.origin = source;
}

onMessage(handler: (e: ScriptWorkerMessageData) => void): void {
window.addEventListener('message', (e) => {
if (e.origin && !validOrigins.includes(e.origin)) {
if (e.origin !== this.origin) {
return;
}
handler(e.data);
Expand Down

0 comments on commit 1e8b51e

Please sign in to comment.