Skip to content

Commit 40124b9

Browse files
authored
Add sandbox attribute to YouTube and Vimeo IFRAME video player (#4567)
* Add sandbox attribute * Add tests
1 parent 324d622 commit 40124b9

File tree

7 files changed

+91
-0
lines changed

7 files changed

+91
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2525
### Fixed
2626

2727
- Fixes [#4558](https://github.com/microsoft/BotFramework-WebChat/issues/4558). In high contrast mode, "Retry" link button should use link color as defined by [CSS System Colors](https://w3c.github.io/csswg-drafts/css-color/#css-system-colors), by [@beyackle2](https://github.com/beyackle2) in PR [#4537](https://github.com/microsoft/BotFramework-WebChat/pull/4537)
28+
- Fixes [#4566](https://github.com/microsoft/BotFramework-WebChat/issues/4566). For YouTube and Vimeo `<iframe>`, add `sandbox="allow-same-origin allow-scripts"`, by [@compulim](https://github.com/compulim) in PR [#4567](https://github.com/microsoft/BotFramework-WebChat/pull/4567)
2829

2930
### Changed
3031

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
<head>
4+
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
5+
<script crossorigin="anonymous" src="/test-harness.js"></script>
6+
<script crossorigin="anonymous" src="/test-page-object.js"></script>
7+
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
8+
</head>
9+
<body>
10+
<div id="webchat"></div>
11+
<script>
12+
run(async function () {
13+
const store = testHelpers.createStore();
14+
15+
const directLine = testHelpers.createDirectLineEmulator(store);
16+
17+
WebChat.renderWebChat({ directLine, store }, document.getElementById('webchat'));
18+
19+
await pageConditions.uiConnected();
20+
21+
await directLine.emulateIncomingActivity({
22+
attachments: [{
23+
contentType: 'video/*',
24+
contentUrl: 'https://vimeo.com/269316124'
25+
}],
26+
type: 'message'
27+
});
28+
29+
await pageConditions.numActivitiesShown(1);
30+
31+
await pageConditions.became('iframe has loaded', () => document.getElementsByTagName('iframe').length, 5000);
32+
33+
const sandboxAttributeValue = document.getElementsByTagName('iframe')[0].getAttribute('sandbox')
34+
35+
expect(sandboxAttributeValue).toBeTruthy();
36+
});
37+
</script>
38+
</body>
39+
</html>

__tests__/html/video.vimeo.sandbox.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */
2+
3+
describe('Vimeo video player', () => {
4+
test('should have "sandbox" attribute set', () => runHTML('video.youtube.sandbox.html'));
5+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
<head>
4+
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
5+
<script crossorigin="anonymous" src="/test-harness.js"></script>
6+
<script crossorigin="anonymous" src="/test-page-object.js"></script>
7+
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
8+
</head>
9+
<body>
10+
<div id="webchat"></div>
11+
<script>
12+
run(async function () {
13+
const store = testHelpers.createStore();
14+
15+
const directLine = testHelpers.createDirectLineEmulator(store);
16+
17+
WebChat.renderWebChat({ directLine, store }, document.getElementById('webchat'));
18+
19+
await pageConditions.uiConnected();
20+
21+
await directLine.emulateIncomingActivity({
22+
attachments: [{
23+
contentType: 'video/*',
24+
contentUrl: 'https://youtu.be/rIJRFHDr1QE'
25+
}],
26+
type: 'message'
27+
});
28+
29+
await pageConditions.numActivitiesShown(1);
30+
31+
await pageConditions.became('iframe has loaded', () => document.getElementsByTagName('iframe').length, 5000);
32+
33+
const sandboxAttributeValue = document.getElementsByTagName('iframe')[0].getAttribute('sandbox')
34+
35+
expect(sandboxAttributeValue).toBeTruthy();
36+
});
37+
</script>
38+
</body>
39+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */
2+
3+
describe('YouTube video player', () => {
4+
test('should have "sandbox" attribute set', () => runHTML('video.youtube.sandbox.html'));
5+
});

packages/component/src/Attachment/VimeoContent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const VimeoContent: FC<VimeoContentProps> = ({ alt, autoPlay, embedID, loop }) =
2727
allowFullScreen={true}
2828
aria-label={alt}
2929
className={vimeoContentStyleSet}
30+
sandbox="allow-same-origin allow-scripts"
3031
src={`https://player.vimeo.com/video/${encodeURI(embedID)}?${search}`}
3132
/>
3233
);

packages/component/src/Attachment/YouTubeContent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const YouTubeContent: FC<YouTubeContentProps> = ({ alt, autoPlay, embedID, loop
2525
allowFullScreen={true}
2626
aria-label={alt}
2727
className={youTubeContentStyleSet}
28+
sandbox="allow-same-origin allow-scripts"
2829
src={`https://youtube.com/embed/${embedID}?${search}`}
2930
/>
3031
);

0 commit comments

Comments
 (0)