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 16 days ago

The recommended fix is to ensure that the output HTML is properly sanitized. The best and safest method is to use a well-tested library for HTML sanitization, such as sanitize-html. This library will reliably strip all dangerous tags and attributes (such as <script>, <style>, on* event handlers, etc.), and keep only safe markup.

Steps:

  • Import the sanitize-html library at the top.
  • In the generateHTML function, after the string manipulations, pass the result through sanitizeHtml before returning.
  • You only need to edit the generateHTML method and add the import.
  • No changes to the rest of the code are needed, and no behavior is altered except ensuring HTML is now safe.

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,8 +127,10 @@
       editor.setEditorState(editor.parseEditorState(parsed));
       editor.read(() => (html = $generateHtmlFromNodes(editor)));
     });
-    return html
-      .replaceAll('class=""', '')
-      .replaceAll(/(?<=<[^>]+)(?<!\w|")\s+(?=[^>]*>)|(?<=<[^>]*(?:\w|"))\s+(?=>)/g, '');
+    return sanitizeHtml(
+      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,8 +127,10 @@
editor.setEditorState(editor.parseEditorState(parsed));
editor.read(() => (html = $generateHtmlFromNodes(editor)));
});
return html
.replaceAll('class=""', '')
.replaceAll(/(?<=<[^>]+)(?<!\w|")\s+(?=[^>]*>)|(?<=<[^>]*(?:\w|"))\s+(?=>)/g, '');
return sanitizeHtml(
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
@@ -72,7 +72,8 @@
     "prisma": "^6.19.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
@@ -72,7 +72,8 @@
"prisma": "^6.19.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 (77f68cf).

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