Skip to content

Commit 1828337

Browse files
mprew97Brad Umbaugh
and
Brad Umbaugh
authored
[MOB-8515]: allow-popups-to-escape-sandbox (#380)
* allow-popups-to-escape-sandbox * config for allowing popups js execution * eol * remove console statement * update check * [DOCS-4682] Information about allow-popups-to-escape-sandbox (#388) * Information about allow-popups-to-escape-sandbox * SDK version information * Update README.md * Update README.md --------- Co-authored-by: Mitch Prewitt <[email protected]> --------- Co-authored-by: mitch prewitt <[email protected]> Co-authored-by: Brad Umbaugh <[email protected]>
1 parent 6e5de5d commit 1828337

File tree

8 files changed

+36
-1
lines changed

8 files changed

+36
-1
lines changed

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010

1111
# Toggle this to true if you would need to hit our EU APIs.
1212
# IS_EU_ITERABLE_SERVICE=false
13+
14+
# DANGEROUSLY_ALLOW_JS_POPUP_EXECUTION=false

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,24 @@ const SomeComponent = () => {
931931
};
932932
```
933933

934+
## Safari: Allowing JavaScript execution in tabs opened by in-app message link clicks
935+
936+
To display an in-app message, Iterable's Web SDK uses an `iframe` on which the `sandbox` attribute is set to `allow-same-origin allow-popups allow-top-navigation`. On Safari, this configuration blocks JavaScript execution in tabs that open because of link clicks in the `iframe`.
937+
938+
To allow JavaScript to run in these new tabs:
939+
940+
- On your web server, set the `DANGEROUSLY_ALLOW_JS_POPUP_EXECUTION` environment variable to `true`. This adds `allow-popups-to-escape-sandbox` to the `iframe`'s `sandbox` attribute, which allows new tabs to open with a clean browsing context.
941+
- However, use caution. Allowing JavaScript to run in new tabs opens the door to the possibility of malicious code execution.
942+
943+
SDK version support:
944+
945+
- Versions [`1.0.10+`](https://github.com/Iterable/iterable-web-sdk/releases/tag/v1.0.10) of Iterable's Web SDK support the `DANGEROUSLY_ALLOW_JS_POPUP_EXECUTION` environment variable.
946+
947+
For more information, see:
948+
949+
- [MDN docs for `allow-popups-to-escape-sandbox`](https://developer.mozilla.org/docs/Web/HTML/Element/iframe#allow-popups-to-escape-sandbox)
950+
- [Can I Use? `allow-popups-to-escape-sandbox`](https://caniuse.com/mdn-html_elements_iframe_sandbox_allow-popups-to-escape-sandbox)
951+
934952
# TypeScript
935953

936954
The Iterable Web SDK includes TypeScript definitions out of the box. All SDK methods

react-example/.env.example

+3
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88

99
# Convenience variable to automatically set the login email during testing.
1010
11+
12+
# IS_EU_ITERABLE_SERVICE=false
13+
# DANGEROUSLY_ALLOW_JS_POPUP_EXECUTION=false

src/constants.ts

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export const RETRY_USER_ATTEMPTS = 0;
77
const IS_EU_ITERABLE_SERVICE =
88
process.env.IS_EU_ITERABLE_SERVICE === 'true' ? true : false;
99

10+
export const dangerouslyAllowJsPopupExecution =
11+
process.env.DANGEROUSLY_ALLOW_JS_POPUP_EXECUTION === 'true' ? true : false;
12+
1013
const US_ITERABLE_DOMAIN = 'api.iterable.com';
1114

1215
const EU_ITERABLE_DOMAIN = 'api.eu.iterable.com';

src/inapp/utils.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { by } from '@pabra/sortby';
22
import {
33
ANIMATION_DURATION,
4+
dangerouslyAllowJsPopupExecution,
45
DEFAULT_CLOSE_BUTTON_OFFSET_PERCENTAGE
56
} from 'src/constants';
67
import { WebInAppDisplaySettings } from 'src/inapp';
@@ -286,7 +287,9 @@ const generateSecuredIFrame = () => {
286287
// event handlers on elements in it preventing our custom link handling
287288
iframe.setAttribute(
288289
'sandbox',
289-
'allow-same-origin allow-popups allow-top-navigation'
290+
`allow-same-origin allow-popups allow-top-navigation ${
291+
dangerouslyAllowJsPopupExecution ? 'allow-popups-to-escape-sandbox' : ''
292+
}`
290293
);
291294
/*
292295
_display: none_ would remove the ability to set event handlers on elements

webpack.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function getParsedEnv() {
99
...env.parsed,
1010
VERSION: version,
1111
IS_EU_ITERABLE_SERVICE: process.env.IS_EU_ITERABLE_SERVICE || false,
12+
DANGEROUSLY_ALLOW_JS_POPUP_EXECUTION:
13+
process.env.DANGEROUSLY_ALLOW_JS_POPUP_EXECUTION || false
1214
};
1315
}
1416

webpack.dev.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function getParsedEnv() {
99
...env.parsed,
1010
VERSION: version,
1111
IS_EU_ITERABLE_SERVICE: process.env.IS_EU_ITERABLE_SERVICE || false,
12+
DANGEROUSLY_ALLOW_JS_POPUP_EXECUTION:
13+
process.env.DANGEROUSLY_ALLOW_JS_POPUP_EXECUTION || false
1214
};
1315
}
1416

webpack.node.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function getParsedEnv() {
99
...env.parsed,
1010
VERSION: version,
1111
IS_EU_ITERABLE_SERVICE: process.env.IS_EU_ITERABLE_SERVICE || false,
12+
DANGEROUSLY_ALLOW_JS_POPUP_EXECUTION:
13+
process.env.DANGEROUSLY_ALLOW_JS_POPUP_EXECUTION || false
1214
};
1315
}
1416

0 commit comments

Comments
 (0)