File tree Expand file tree Collapse file tree 5 files changed +393
-14
lines changed
src/extensions/title-update Expand file tree Collapse file tree 5 files changed +393
-14
lines changed Original file line number Diff line number Diff line change 3232 "@hocuspocus/transformer" : " 2.15.2" ,
3333 "@plane/decorators" : " workspace:*" ,
3434 "@plane/editor" : " workspace:*" ,
35- "@plane/utils" : " workspace:*" ,
3635 "@plane/logger" : " workspace:*" ,
3736 "@plane/types" : " workspace:*" ,
3837 "@sentry/node" : " catalog:" ,
4645 "express-ws" : " ^5.0.2" ,
4746 "helmet" : " ^7.1.0" ,
4847 "ioredis" : " 5.7.0" ,
48+ "isomorphic-dompurify" : " ^1.8.0" ,
4949 "uuid" : " catalog:" ,
5050 "ws" : " ^8.18.3" ,
5151 "y-prosemirror" : " ^1.3.7" ,
Original file line number Diff line number Diff line change 1- import { sanitizeHTML } from "@plane/utils" ;
1+ import DOMPurify from "isomorphic-dompurify" ;
2+
3+ /**
4+ * Sanitizes HTML by removing all HTML tags, leaving only text content
5+ * @param htmlString - The HTML string to sanitize
6+ * @returns The sanitized text with all HTML tags removed
7+ */
8+ const sanitizeHTML = ( htmlString : string ) : string => {
9+ const sanitizedText = DOMPurify . sanitize ( htmlString , { ALLOWED_TAGS : [ ] } ) ; // sanitize the string to remove all HTML tags
10+ return sanitizedText . trim ( ) ; // trim the string to remove leading and trailing whitespaces
11+ } ;
212
313/**
414 * Utility function to extract text from HTML content
Original file line number Diff line number Diff line change 6666 "emoji-regex" : " ^10.3.0" ,
6767 "highlight.js" : " ^11.8.0" ,
6868 "is-emoji-supported" : " ^0.0.5" ,
69+ "isomorphic-dompurify" : " ^1.8.0" ,
6970 "jsx-dom-cjs" : " ^8.0.3" ,
7071 "linkifyjs" : " ^4.3.2" ,
7172 "lowlight" : " ^3.0.0" ,
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import {
1111 DocumentEditorExtensionsWithoutProps ,
1212} from "@/extensions/core-without-props" ;
1313import { TitleExtensions } from "@/extensions/title-extension" ;
14- import { sanitizeHTML } from "@plane/utils " ;
14+ import DOMPurify from "isomorphic-dompurify " ;
1515
1616// editor extension configs
1717const RICH_TEXT_EDITOR_EXTENSIONS = CoreEditorExtensionsWithoutProps ;
@@ -207,8 +207,9 @@ export const convertHTMLDocumentToAllFormats = (args: TConvertHTMLDocumentToAllF
207207} ;
208208
209209export const extractTextFromHTML = ( html : string ) : string => {
210- // Use sanitizeHTML to safely extract text and remove all HTML tags
210+ // Use DOMPurify to safely extract text and remove all HTML tags
211211 // This is more secure than regex as it handles edge cases and prevents injection
212212 // Note: sanitizeHTML trims whitespace, which is acceptable for title extraction
213- return sanitizeHTML ( html ) || "" ;
213+ const sanitizedText = DOMPurify . sanitize ( html , { ALLOWED_TAGS : [ ] } ) ; // sanitize the string to remove all HTML tags
214+ return sanitizedText . trim ( ) || "" ; // trim the string to remove leading and trailing whitespaces
214215} ;
You can’t perform that action at this time.
0 commit comments