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

Development #254

Merged
merged 37 commits into from
Nov 11, 2024
Merged

Development #254

merged 37 commits into from
Nov 11, 2024

Conversation

flipvh
Copy link
Contributor

@flipvh flipvh commented Nov 8, 2024

No description provided.

export const AudioPreview = ({ src }: { src: string }) => (
<MediaThemeSutroAudio className="w-[70%] p-2 max-h-10">
{/* biome-ignore lint/a11y/useMediaCaption: by author */}
<audio slot="media" src={src} playsInline crossOrigin="anonymous" />

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix AI 1 day ago

To fix the problem, we need to ensure that the src value is properly sanitized before being used in the audio element. One effective way to do this is by using a library like DOMPurify to sanitize the src value. This will help prevent any malicious content from being executed.

  • Import the DOMPurify library.
  • Sanitize the src value before using it in the audio element.
  • Ensure that the sanitized value is used consistently throughout the code.
Suggested changeset 1
frontend/src/modules/common/attachments/audio-preview.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/frontend/src/modules/common/attachments/audio-preview.tsx b/frontend/src/modules/common/attachments/audio-preview.tsx
--- a/frontend/src/modules/common/attachments/audio-preview.tsx
+++ b/frontend/src/modules/common/attachments/audio-preview.tsx
@@ -1,8 +1,12 @@
 import MediaThemeSutroAudio from 'player.style/sutro-audio/react';
+import DOMPurify from 'dompurify';
 
-export const AudioPreview = ({ src }: { src: string }) => (
-  <MediaThemeSutroAudio className="w-[70%] p-2 max-h-10">
-    {/* biome-ignore lint/a11y/useMediaCaption: by author */}
-    <audio slot="media" src={src} playsInline crossOrigin="anonymous" />
-  </MediaThemeSutroAudio>
-);
+export const AudioPreview = ({ src }: { src: string }) => {
+  const sanitizedSrc = DOMPurify.sanitize(src);
+  return (
+    <MediaThemeSutroAudio className="w-[70%] p-2 max-h-10">
+      {/* biome-ignore lint/a11y/useMediaCaption: by author */}
+      <audio slot="media" src={sanitizedSrc} playsInline crossOrigin="anonymous" />
+    </MediaThemeSutroAudio>
+  );
+};
EOF
@@ -1,8 +1,12 @@
import MediaThemeSutroAudio from 'player.style/sutro-audio/react';
import DOMPurify from 'dompurify';

export const AudioPreview = ({ src }: { src: string }) => (
<MediaThemeSutroAudio className="w-[70%] p-2 max-h-10">
{/* biome-ignore lint/a11y/useMediaCaption: by author */}
<audio slot="media" src={src} playsInline crossOrigin="anonymous" />
</MediaThemeSutroAudio>
);
export const AudioPreview = ({ src }: { src: string }) => {
const sanitizedSrc = DOMPurify.sanitize(src);
return (
<MediaThemeSutroAudio className="w-[70%] p-2 max-h-10">
{/* biome-ignore lint/a11y/useMediaCaption: by author */}
<audio slot="media" src={sanitizedSrc} playsInline crossOrigin="anonymous" />
</MediaThemeSutroAudio>
);
};
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
(imagePanZoom ? (
<ReactPanZoom image={source} alt={altName} imageClass={itemClassName} showButtons={showButtons} />
) : (
<img src={source} alt={altName} className={`${itemClassName} w-full h-full`} />

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix AI 1 day ago

To fix the problem, we need to ensure that the source variable is properly sanitized before being used in the src attribute of the img tag. One way to achieve this is by using a library like DOMPurify to sanitize the URL. This will help prevent any malicious content from being executed.

  1. Install the DOMPurify library.
  2. Import DOMPurify in the relevant file.
  3. Use DOMPurify to sanitize the source variable before using it in the src attribute.
Suggested changeset 1
frontend/src/modules/common/attachments/index.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/frontend/src/modules/common/attachments/index.tsx b/frontend/src/modules/common/attachments/index.tsx
--- a/frontend/src/modules/common/attachments/index.tsx
+++ b/frontend/src/modules/common/attachments/index.tsx
@@ -4,2 +4,3 @@
 import ReactPanZoom from '~/modules/common/image-viewer';
+import DOMPurify from 'dompurify';
 
@@ -24,2 +25,3 @@
 }: AttachmentItemProps) => {
+  const sanitizedSource = DOMPurify.sanitize(source);
   return (
@@ -28,9 +30,9 @@
         (imagePanZoom ? (
-          <ReactPanZoom image={source} alt={altName} imageClass={itemClassName} showButtons={showButtons} />
+          <ReactPanZoom image={sanitizedSource} alt={altName} imageClass={itemClassName} showButtons={showButtons} />
         ) : (
-          <img src={source} alt={altName} className={`${itemClassName} w-full h-full`} />
+          <img src={sanitizedSource} alt={altName} className={`${itemClassName} w-full h-full`} />
         ))}
-      {type.includes('audio') && <AudioPreview src={source} />}
-      {type.includes('video') && <VideoPreview src={source} />}
-      {type.includes('pdf') && <PreviewPDF file={source} />}
+      {type.includes('audio') && <AudioPreview src={sanitizedSource} />}
+      {type.includes('video') && <VideoPreview src={sanitizedSource} />}
+      {type.includes('pdf') && <PreviewPDF file={sanitizedSource} />}
     </div>
EOF
@@ -4,2 +4,3 @@
import ReactPanZoom from '~/modules/common/image-viewer';
import DOMPurify from 'dompurify';

@@ -24,2 +25,3 @@
}: AttachmentItemProps) => {
const sanitizedSource = DOMPurify.sanitize(source);
return (
@@ -28,9 +30,9 @@
(imagePanZoom ? (
<ReactPanZoom image={source} alt={altName} imageClass={itemClassName} showButtons={showButtons} />
<ReactPanZoom image={sanitizedSource} alt={altName} imageClass={itemClassName} showButtons={showButtons} />
) : (
<img src={source} alt={altName} className={`${itemClassName} w-full h-full`} />
<img src={sanitizedSource} alt={altName} className={`${itemClassName} w-full h-full`} />
))}
{type.includes('audio') && <AudioPreview src={source} />}
{type.includes('video') && <VideoPreview src={source} />}
{type.includes('pdf') && <PreviewPDF file={source} />}
{type.includes('audio') && <AudioPreview src={sanitizedSource} />}
{type.includes('video') && <VideoPreview src={sanitizedSource} />}
{type.includes('pdf') && <PreviewPDF file={sanitizedSource} />}
</div>
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
export const VideoPreview = ({ src }: { src: string }) => (
<MediaThemeSutro className="w-full p-4">
{/* biome-ignore lint/a11y/useMediaCaption: by author */}
<video slot="media" src={src} playsInline crossOrigin="anonymous" />

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix AI 1 day ago

To fix the problem, we need to ensure that the src attribute is properly sanitized before being used in the video element. This can be achieved by using a library like DOMPurify to sanitize the URL. This will prevent any malicious content from being executed.

  • Import the DOMPurify library.
  • Sanitize the src value before using it in the video element.
  • Ensure that the sanitization is applied consistently wherever the src value is used.
Suggested changeset 1
frontend/src/modules/common/attachments/video-preview.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/frontend/src/modules/common/attachments/video-preview.tsx b/frontend/src/modules/common/attachments/video-preview.tsx
--- a/frontend/src/modules/common/attachments/video-preview.tsx
+++ b/frontend/src/modules/common/attachments/video-preview.tsx
@@ -1,8 +1,12 @@
 import MediaThemeSutro from 'player.style/sutro/react';
+import DOMPurify from 'dompurify';
 
-export const VideoPreview = ({ src }: { src: string }) => (
-  <MediaThemeSutro className="w-full p-4">
-    {/* biome-ignore lint/a11y/useMediaCaption: by author */}
-    <video slot="media" src={src} playsInline crossOrigin="anonymous" />
-  </MediaThemeSutro>
-);
+export const VideoPreview = ({ src }: { src: string }) => {
+  const sanitizedSrc = DOMPurify.sanitize(src);
+  return (
+    <MediaThemeSutro className="w-full p-4">
+      {/* biome-ignore lint/a11y/useMediaCaption: by author */}
+      <video slot="media" src={sanitizedSrc} playsInline crossOrigin="anonymous" />
+    </MediaThemeSutro>
+  );
+};
EOF
@@ -1,8 +1,12 @@
import MediaThemeSutro from 'player.style/sutro/react';
import DOMPurify from 'dompurify';

export const VideoPreview = ({ src }: { src: string }) => (
<MediaThemeSutro className="w-full p-4">
{/* biome-ignore lint/a11y/useMediaCaption: by author */}
<video slot="media" src={src} playsInline crossOrigin="anonymous" />
</MediaThemeSutro>
);
export const VideoPreview = ({ src }: { src: string }) => {
const sanitizedSrc = DOMPurify.sanitize(src);
return (
<MediaThemeSutro className="w-full p-4">
{/* biome-ignore lint/a11y/useMediaCaption: by author */}
<video slot="media" src={sanitizedSrc} playsInline crossOrigin="anonymous" />
</MediaThemeSutro>
);
};
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
const imageElement = element.querySelector('img');
if (imageElement) {
imageElement.onclick = onElClick;
imageElement.setAttribute('src', url);

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
const videoElement = element.querySelector('video');
if (videoElement) {
videoElement.onclick = onElClick;
videoElement.setAttribute('src', url);

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix AI 1 day ago

To fix the problem, we need to ensure that the url obtained from the data-url attribute is properly sanitized before being used as the src attribute of the video element. One way to achieve this is by using a library like DOMPurify to sanitize the URL. This will help prevent any malicious content from being executed.

  1. Install the DOMPurify library.
  2. Import DOMPurify in the file.
  3. Use DOMPurify to sanitize the url before setting it as the src attribute.
Suggested changeset 1
frontend/src/modules/common/blocknote/helpers.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/frontend/src/modules/common/blocknote/helpers.ts b/frontend/src/modules/common/blocknote/helpers.ts
--- a/frontend/src/modules/common/blocknote/helpers.ts
+++ b/frontend/src/modules/common/blocknote/helpers.ts
@@ -3,3 +3,3 @@
 import { type Slides, openCarouselDialog } from '~/modules/common/carousel/carousel-dialog';
-
+import DOMPurify from 'dompurify';
 export const getContentAsString = (blocks: Block[]) => {
@@ -55,3 +55,3 @@
   for (const element of elementsWithDataUrl) {
-    const url = element.getAttribute('data-url');
+    const url = DOMPurify.sanitize(element.getAttribute('data-url'));
     const contentType = element.getAttribute('data-content-type') || 'file';
EOF
@@ -3,3 +3,3 @@
import { type Slides, openCarouselDialog } from '~/modules/common/carousel/carousel-dialog';

import DOMPurify from 'dompurify';
export const getContentAsString = (blocks: Block[]) => {
@@ -55,3 +55,3 @@
for (const element of elementsWithDataUrl) {
const url = element.getAttribute('data-url');
const url = DOMPurify.sanitize(element.getAttribute('data-url'));
const contentType = element.getAttribute('data-content-type') || 'file';
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
const audioElement = element.querySelector('audio');
if (audioElement) {
audioElement.onclick = onElClick;
audioElement.setAttribute('src', url);

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix AI 1 day ago

To fix the problem, we need to ensure that the url value is properly sanitized before it is used. One way to do this is to use a library like DOMPurify to sanitize the URL. This will ensure that any potentially malicious content is removed before the URL is used in the setAttribute method.

  • Import the DOMPurify library.
  • Sanitize the url value before using it in the setAttribute method.
  • Ensure that the sanitized URL is used consistently across all relevant elements.
Suggested changeset 1
frontend/src/modules/common/blocknote/helpers.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/frontend/src/modules/common/blocknote/helpers.ts b/frontend/src/modules/common/blocknote/helpers.ts
--- a/frontend/src/modules/common/blocknote/helpers.ts
+++ b/frontend/src/modules/common/blocknote/helpers.ts
@@ -3,2 +3,3 @@
 import { type Slides, openCarouselDialog } from '~/modules/common/carousel/carousel-dialog';
+import DOMPurify from 'dompurify';
 
@@ -55,3 +56,3 @@
   for (const element of elementsWithDataUrl) {
-    const url = element.getAttribute('data-url');
+    const url = DOMPurify.sanitize(element.getAttribute('data-url'));
     const contentType = element.getAttribute('data-content-type') || 'file';
EOF
@@ -3,2 +3,3 @@
import { type Slides, openCarouselDialog } from '~/modules/common/carousel/carousel-dialog';
import DOMPurify from 'dompurify';

@@ -55,3 +56,3 @@
for (const element of elementsWithDataUrl) {
const url = element.getAttribute('data-url');
const url = DOMPurify.sanitize(element.getAttribute('data-url'));
const contentType = element.getAttribute('data-content-type') || 'file';
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options

case 'file': {
const fileLinkElement = document.createElement('a');
fileLinkElement.setAttribute('href', url);

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix AI 1 day ago

To fix the problem, we need to ensure that the url value is properly sanitized or encoded before being used in the setAttribute method. One way to achieve this is by using a library like DOMPurify to sanitize the url value. This will ensure that any potentially malicious content is removed before the url is used.

  1. Install the DOMPurify library.
  2. Import DOMPurify in the file.
  3. Use DOMPurify.sanitize to sanitize the url value before using it in the setAttribute method.
Suggested changeset 1
frontend/src/modules/common/blocknote/helpers.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/frontend/src/modules/common/blocknote/helpers.ts b/frontend/src/modules/common/blocknote/helpers.ts
--- a/frontend/src/modules/common/blocknote/helpers.ts
+++ b/frontend/src/modules/common/blocknote/helpers.ts
@@ -3,3 +3,3 @@
 import { type Slides, openCarouselDialog } from '~/modules/common/carousel/carousel-dialog';
-
+import DOMPurify from 'dompurify';
 export const getContentAsString = (blocks: Block[]) => {
@@ -55,3 +55,3 @@
   for (const element of elementsWithDataUrl) {
-    const url = element.getAttribute('data-url');
+    const url = DOMPurify.sanitize(element.getAttribute('data-url'));
     const contentType = element.getAttribute('data-content-type') || 'file';
EOF
@@ -3,3 +3,3 @@
import { type Slides, openCarouselDialog } from '~/modules/common/carousel/carousel-dialog';

import DOMPurify from 'dompurify';
export const getContentAsString = (blocks: Block[]) => {
@@ -55,3 +55,3 @@
for (const element of elementsWithDataUrl) {
const url = element.getAttribute('data-url');
const url = DOMPurify.sanitize(element.getAttribute('data-url'));
const contentType = element.getAttribute('data-content-type') || 'file';
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@flipvh flipvh merged commit e5a7f02 into main Nov 11, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants