From d43e5720a79f802c587daccf08be19edf5bffd32 Mon Sep 17 00:00:00 2001 From: Mike Wu Date: Wed, 6 Sep 2023 16:10:29 +1000 Subject: [PATCH] Allow story to embedded video sources from Youtube only. --- lib/ReactViews/Story/StoryPanel/StoryBody.tsx | 65 ++++++++++++++++--- .../Story/StoryPanel/StoryBodySpec.tsx | 14 ++-- 2 files changed, 65 insertions(+), 14 deletions(-) diff --git a/lib/ReactViews/Story/StoryPanel/StoryBody.tsx b/lib/ReactViews/Story/StoryPanel/StoryBody.tsx index 68cc6558260..311236b7404 100644 --- a/lib/ReactViews/Story/StoryPanel/StoryBody.tsx +++ b/lib/ReactViews/Story/StoryPanel/StoryBody.tsx @@ -4,6 +4,7 @@ import parseCustomHtmlToReact from "../../Custom/parseCustomHtmlToReact"; import styled from "styled-components"; import Box from "../../../Styled/Box"; import Text from "../../../Styled/Text"; +import URI from "urijs"; const StoryContainer = styled(Box).attrs((props: { isCollapsed: boolean }) => ({ paddedVertically: props.isCollapsed ? 0 : 2, @@ -45,6 +46,61 @@ const StoryContainer = styled(Box).attrs((props: { isCollapsed: boolean }) => ({ } `; +const allowedStoryBodyIframeSources = ["https://www.youtube.com"]; + +function extractIframeSources(text: string): string[] { + const startString = '' + text: 'Story with video. ' }; act(() => { @@ -37,17 +38,18 @@ describe("StoryBody", function () { const theIframeInstance = theInstance.children[1] as ReactTestInstance; expect(theIframeInstance.type).toBe("iframe"); - expect(theIframeInstance.props.title).toBe("My Title"); - expect(theIframeInstance.props.src).toBe("https://some.video.link"); + expect(theIframeInstance.props.src).toBe( + "https://www.youtube.com/embed/1234" + ); expect(theIframeInstance.props.width).toBe("560"); expect(theIframeInstance.props.height).toBe("315"); }); - it("should exclude embedded media using unsafe tag", function () { + it("should exclude embedded media using iframe tag with any forbidden sources", function () { const theStory = { id: "some id", title: "test", - text: 'Story with video. ' + text: 'Story with video. ' }; act(() => {