-
Notifications
You must be signed in to change notification settings - Fork 0
Update deps #99
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
base: dev
Are you sure you want to change the base?
Update deps #99
Conversation
* missing : tables, nested list styles, checklists
* faker v10 is not compatible with jest : https://v10.fakerjs.dev/guide/upgrading.html#incompatibility-with-jest
| return html | ||
| .replaceAll('class=""', '') | ||
| .replaceAll(/(?<=<[^>]+)(?<!\w|")\s+(?=[^>]*>)|(?<=<[^>]*(?:\w|"))\s+(?=>)/g, ''); |
Check failure
Code scanning / CodeQL
Incomplete multi-character sanitization High
<script
This string may still contain
<script
Show autofix suggestion
Hide autofix suggestion
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-htmlat the top. - In
generateHTML, run the output HTML (html) throughsanitizeHtmlbefore 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.
-
Copy modified line R2 -
Copy modified lines R130-R134
| @@ -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, ''); |
-
Copy modified lines R74-R75
| @@ -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", |
| Package | Version | Security advisories |
| sanitize-html (npm) | 2.17.0 | None |
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
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)