Skip to content

Conversation

@AlbanSdl
Copy link
Member

@AlbanSdl AlbanSdl commented Oct 24, 2025

Mise à jour des dépendances de l'api (basé sur feat/lexical-generator)

Faker v10 n'est pas compatible avec jest, il existe un workaround qui consiste à utiliser babel... Mais c'est un peu lourd pour les test, non ? Si on décide d'utiliser babel parce que jest ne supporte les packages pure-esm, on pourra réintroduire les tests unitaires de lexical (cf. #97)

Comment on lines +129 to +131
return html
.replaceAll('class=""', '')
.replaceAll(/(?<=<[^>]+)(?<!\w|")\s+(?=[^>]*>)|(?<=<[^>]*(?:\w|"))\s+(?=>)/g, '');

Check failure

Code scanning / CodeQL

Incomplete multi-character sanitization High

This string may still contain
<script
, which may cause an HTML element injection vulnerability.
This string may still contain
<script
, which may cause an HTML element injection vulnerability.

Copilot Autofix

AI 3 days ago

To fix this problem, we should ensure that all <script> tags, as well as other potentially dangerous HTML elements (e.g., <iframe>, <object>, <embed>, and attributes like onerror, onclick), are removed from the generated HTML string before returning it. The recommended standard is to use a well-known, vetted HTML sanitization library such as sanitize-html (npm package), which reliably strips dangerous content and attributes while retaining safe markup.

  • Update the file src/lexical/lexical.module.ts.
  • Import sanitize-html at the top.
  • In generateHTML, run the output HTML (html) through sanitizeHtml before further string replacements.
  • No changes to function arguments or existing logic, only add sanitization immediately after DOM generation and before existing post-processing.
  • You need to add an import of sanitize-html.

Suggested changeset 2
src/lexical/lexical.module.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/src/lexical/lexical.module.ts b/src/lexical/lexical.module.ts
--- a/src/lexical/lexical.module.ts
+++ b/src/lexical/lexical.module.ts
@@ -1,4 +1,5 @@
 import { Module } from '@nestjs/common';
+import sanitizeHtml from 'sanitize-html';
 import { TextNode, ParagraphNode } from 'lexical';
 import { createHeadlessEditor } from '@lexical/headless';
 import { $generateHtmlFromNodes } from '@lexical/html';
@@ -126,6 +127,11 @@
       editor.setEditorState(editor.parseEditorState(parsed));
       editor.read(() => (html = $generateHtmlFromNodes(editor)));
     });
+    // sanitize the HTML against script injection and unsafe markup
+    html = sanitizeHtml(html, {
+      allowedTags: sanitizeHtml.defaults.allowedTags.filter(tag => tag !== 'script' && tag !== 'iframe' && tag !== 'object' && tag !== 'embed'),
+      allowedAttributes: false, // remove all attributes except safe defaults
+    });
     return html
       .replaceAll('class=""', '')
       .replaceAll(/(?<=<[^>]+)(?<!\w|")\s+(?=[^>]*>)|(?<=<[^>]*(?:\w|"))\s+(?=>)/g, '');
EOF
@@ -1,4 +1,5 @@
import { Module } from '@nestjs/common';
import sanitizeHtml from 'sanitize-html';
import { TextNode, ParagraphNode } from 'lexical';
import { createHeadlessEditor } from '@lexical/headless';
import { $generateHtmlFromNodes } from '@lexical/html';
@@ -126,6 +127,11 @@
editor.setEditorState(editor.parseEditorState(parsed));
editor.read(() => (html = $generateHtmlFromNodes(editor)));
});
// sanitize the HTML against script injection and unsafe markup
html = sanitizeHtml(html, {
allowedTags: sanitizeHtml.defaults.allowedTags.filter(tag => tag !== 'script' && tag !== 'iframe' && tag !== 'object' && tag !== 'embed'),
allowedAttributes: false, // remove all attributes except safe defaults
});
return html
.replaceAll('class=""', '')
.replaceAll(/(?<=<[^>]+)(?<!\w|")\s+(?=[^>]*>)|(?<=<[^>]*(?:\w|"))\s+(?=>)/g, '');
package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/package.json b/package.json
--- a/package.json
+++ b/package.json
@@ -71,7 +71,8 @@
     "prisma": "^7.1.0",
     "reflect-metadata": "^0.2.2",
     "rxjs": "^7.8.2",
-    "sharp": "^0.34.5"
+    "sharp": "^0.34.5",
+    "sanitize-html": "^2.17.0"
   },
   "devDependencies": {
     "@faker-js/faker": "^9.9.0",
EOF
@@ -71,7 +71,8 @@
"prisma": "^7.1.0",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.2",
"sharp": "^0.34.5"
"sharp": "^0.34.5",
"sanitize-html": "^2.17.0"
},
"devDependencies": {
"@faker-js/faker": "^9.9.0",
This fix introduces these dependencies
Package Version Security advisories
sanitize-html (npm) 2.17.0 None
Copilot is powered by AI and may make mistakes. Always verify output.
@codecov
Copy link

codecov bot commented Oct 24, 2025

Codecov Report

❌ Patch coverage is 74.76923% with 82 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.29%. Comparing base (c0f3d81) to head (0c7629e).

Files with missing lines Patch % Lines
src/lexical/nodes/NodeStyleInjector.ts 25.00% 27 Missing ⚠️
src/assos/assos.service.ts 59.25% 2 Missing and 9 partials ⚠️
src/lexical/nodes/ImageNode.ts 56.52% 10 Missing ⚠️
src/lexical/lexical.module.ts 70.96% 9 Missing ⚠️
src/media/image/imagemedia.service.ts 81.39% 4 Missing and 4 partials ⚠️
src/lexical/nodes/ColorTextNode.ts 66.66% 5 Missing and 1 partial ⚠️
src/auth/guard/jwt.guard.ts 66.66% 0 Missing and 3 partials ⚠️
src/assos/assos.controller.ts 90.47% 0 Missing and 2 partials ⚠️
src/users/users.controller.ts 0.00% 0 Missing and 2 partials ⚠️
src/users/users.service.ts 33.33% 0 Missing and 2 partials ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##              dev      #99      +/-   ##
==========================================
- Coverage   83.19%   79.29%   -3.91%     
==========================================
  Files         140      119      -21     
  Lines        2398     2347      -51     
  Branches      470      387      -83     
==========================================
- Hits         1995     1861     -134     
+ Misses        398      372      -26     
- Partials        5      114     +109     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants