Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issueid #231004 feat:play youtube help video in mylearning iframe #219

Merged
Merged
Changes from 2 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
57 changes: 8 additions & 49 deletions src/components/Assesment/Assesment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -647,14 +647,15 @@

const { virtualId } = useSelector((state) => state.user);

const [isVideoOpen, setIsVideoOpen] = useState(false);

const handleOpenVideo = () => {
setIsVideoOpen(true);
};

const handleCloseVideo = () => {
setIsVideoOpen(false);
if (process.env.REACT_APP_SHOW_HELP_VIDEO === "true") {
window.parent.postMessage(

Check failure

Code scanning / SonarCloud

Origins should be verified during cross-origin communications High

Specify a target origin for this message. See more on SonarQube Cloud
{
message: "help-video-link",
},
"*"
);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add origin verification to postMessage for security

The current implementation of postMessage lacks origin verification, which could lead to security vulnerabilities. Always specify the target origin when using cross-origin communication.

Apply this fix:

    if (process.env.REACT_APP_SHOW_HELP_VIDEO === "true") {
      window.parent.postMessage(
        {
          message: "help-video-link",
        },
-        "*"
+        process.env.REACT_APP_PARENT_ORIGIN || window.location.origin
      );
    }

Also, ensure to add REACT_APP_PARENT_ORIGIN to your environment variables.

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 GitHub Check: SonarCloud

[failure] 652-652: Origins should be verified during cross-origin communications

Specify a target origin for this message.

See more on SonarQube Cloud

};

const navigate = useNavigate();
Expand Down Expand Up @@ -855,48 +856,6 @@
</Box>
</MainLayout>
)}
{/* Video Modal */}
<Dialog
open={isVideoOpen}
onClose={handleCloseVideo}
maxWidth="lg"
fullWidth
>
<Box
sx={{
position: "relative",
width: "100%",
paddingTop: "56.25%", // Maintain 16:9 aspect ratio
backgroundColor: "black", // Optional: Ensure a dark background
}}
>
<iframe
src={process.env.REACT_APP_SHOW_HELP_VIDEO_LINK}
title="YouTube video"
frameBorder="0"
allow="autoplay; encrypted-media"
allowFullScreen
style={{
position: "absolute",
top: 0,
left: 0,
width: "100%",
height: "100%",
}}
/>
</Box>
<IconButton
onClick={handleCloseVideo}
sx={{
position: "absolute",
top: 8,
right: 8,
zIndex: 1,
}}
>
<CloseIcon />
</IconButton>
</Dialog>
</>
);
};
Expand Down