Skip to content

Commit a2bbf9e

Browse files
authored
fix: add validation (#1205)
* Update component.js * Linting * Updates * Lint error * Move logic to util func * Address changes
1 parent 56a69ac commit a2bbf9e

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/library/zoid/message/component.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ export default createGlobalVariableGetter('__paypal_credit_message__', () =>
144144
const { modal, index, account, merchantId, currency, amount, buyerCountry, onApply } = props;
145145
const { offerType, offerCountry, messageRequestId, lander } = meta;
146146
if (offerType === 'PURCHASE_PROTECTION') {
147-
getURIPopup(lander, offerType);
147+
if (getURIPopup(lander, offerType) == null) {
148+
logger.warn('Blocked unsafe lander URL', { lander });
149+
}
148150
} else {
149151
// Avoid spreading message props because both message and modal
150152
// zoid components have an onClick prop that functions differently

src/utils/sdk.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-disable eslint-comments/disable-enable-pair, no-else-return */
22
import arrayFrom from 'core-js-pure/stable/array/from';
3-
43
import { getStorage as getBelterStorage } from '@krakenjs/belter/src';
54
import { SDK_QUERY_KEYS, SDK_SETTINGS } from '@paypal/sdk-constants/src';
65
import {
@@ -22,7 +21,6 @@ import {
2221
getDisableSetCookie as getSDKDisableCookie,
2322
getPageType as getSDKPageType
2423
} from '@paypal/sdk-client/src';
25-
2624
import { TAG } from './constants';
2725

2826
export function getDisableSetCookie() {
@@ -275,5 +273,18 @@ export function getFeatures(featureProps) {
275273

276274
// open mini-browser with message lander url
277275
export function getURIPopup(lander, label) {
278-
return window.open(lander, label, 'width=460,height=900');
276+
try {
277+
// eslint-disable-next-line compat/compat
278+
const parsed = new URL(lander);
279+
const isHttp = parsed.protocol === 'https:';
280+
const isPayPalDomain = /\.paypal\.com$/i.test(parsed.hostname);
281+
282+
if (isHttp && isPayPalDomain) {
283+
return window.open(lander, label, 'width=460,height=900');
284+
} else {
285+
return null;
286+
}
287+
} catch (e) {
288+
return null;
289+
}
279290
}

0 commit comments

Comments
 (0)