Skip to content

Commit

Permalink
adding html code purifier to prevent XSS (which should not happen any…
Browse files Browse the repository at this point in the history
…ways through ssl)
  • Loading branch information
niclasheun committed Jan 6, 2025
1 parent 6593309 commit 16ba1ae
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { FormDescription } from '@/components/ui/form'
import DOMPurify from 'dompurify'

interface FormDescriptionHTMLProps {
htmlCode: string
}

export const FormDescriptionHTML = ({ htmlCode }: FormDescriptionHTMLProps): JSX.Element => {
const sanitizedHtmlCode = DOMPurify.sanitize(htmlCode)

return (
<FormDescription>
<style>
Expand All @@ -19,7 +22,7 @@ export const FormDescriptionHTML = ({ htmlCode }: FormDescriptionHTMLProps): JSX
}
`}
</style>
<div dangerouslySetInnerHTML={{ __html: htmlCode }} />
<div dangerouslySetInnerHTML={{ __html: sanitizedHtmlCode }} />
</FormDescription>
)
}
1 change: 1 addition & 0 deletions clients/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"clsx": "^2.1.1",
"css-loader": "^7.1.2",
"date-fns": "^4.1.0",
"dompurify": "^3.2.3",
"file-saver": "^2.0.5",
"jwt-decode": "^4.0.0",
"keycloak-js": "22.0.5",
Expand Down
20 changes: 20 additions & 0 deletions clients/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4250,6 +4250,13 @@ __metadata:
languageName: node
linkType: hard

"@types/trusted-types@npm:^2.0.7":
version: 2.0.7
resolution: "@types/trusted-types@npm:2.0.7"
checksum: 10c0/4c4855f10de7c6c135e0d32ce462419d8abbbc33713b31d294596c0cc34ae1fa6112a2f9da729c8f7a20707782b0d69da3b1f8df6645b0366d08825ca1522e0c
languageName: node
linkType: hard

"@types/unist@npm:*":
version: 3.0.3
resolution: "@types/unist@npm:3.0.3"
Expand Down Expand Up @@ -6922,6 +6929,18 @@ __metadata:
languageName: node
linkType: hard

"dompurify@npm:^3.2.3":
version: 3.2.3
resolution: "dompurify@npm:3.2.3"
dependencies:
"@types/trusted-types": "npm:^2.0.7"
dependenciesMeta:
"@types/trusted-types":
optional: true
checksum: 10c0/0ce5cb89b76f396d800751bcb48e0d137792891d350ccc049f1bc9a5eca7332cc69030c25007ff4962e0824a5696904d4d74264df9277b5ad955642dfb6f313f
languageName: node
linkType: hard

"domutils@npm:^2.5.2, domutils@npm:^2.8.0":
version: 2.8.0
resolution: "domutils@npm:2.8.0"
Expand Down Expand Up @@ -12740,6 +12759,7 @@ __metadata:
clsx: "npm:^2.1.1"
css-loader: "npm:^7.1.2"
date-fns: "npm:^4.1.0"
dompurify: "npm:^3.2.3"
eslint: "npm:^8.57.0"
eslint-config-prettier: "npm:^9.1.0"
eslint-plugin-import: "npm:^2.29.1"
Expand Down

0 comments on commit 16ba1ae

Please sign in to comment.