Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/globalpayments-3ds/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,17 @@ export async function handleInitiateAuthentication(
throw new Error("Invalid challenge state. Missing challenge URL");
}

// Browsers can sometimes malform the URL's query string parameters,
// turning `&` into `&` which messes up the query string parameter
// and causes the challenge page to load incorrectly.
//
// We use the textarea element as a way to decode the HTML entities
// and grab the expected text/URL.
var url = document.createElement("textarea");
url.innerHTML = data.challenge.requestUrl;

const response = await postToIframe(
data.challenge.requestUrl,
url.value,
[
{ name: "creq", value: data.challenge.encodedChallengeRequest },
// TODO: support session data
Expand Down
4 changes: 2 additions & 2 deletions packages/globalpayments-3ds/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface IChallengeWindowOptions {
displayMode?: DisplayModeType;
encodedChallengeRequest?: string;
hide?: boolean;
origin?: string;
origin?: string | string[];
requestUrl?: string;
response?: IMessageEventData;
target?: string | Element;
Expand All @@ -76,7 +76,7 @@ export interface ICreditCardData {

export interface IIframeData {
iframe?: Element;
origin?: string;
origin?: string | string[];
timeout?: number;
}

Expand Down
9 changes: 9 additions & 0 deletions packages/globalpayments-3ds/src/lib/post-to-iframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ function getWindowMessageEventHandler(
return;
}

if (data.origin) {
const allowedOrigins = Array.isArray(data.origin) ? data.origin : [data.origin];
// include some defaults from Global Payments' sandbox
allowedOrigins.push(...['https://api.sandbox.globalpay-ecommerce.com']);
if (!allowedOrigins.includes(e.origin)) {
return;
}
}

ensureIframeClosed(data.timeout || 0);
resolve(e.data);
};
Expand Down