Skip to content

Commit d7ec735

Browse files
Merge commit from fork
* Rework frontend code interacting directly with DOM Rework frontend code that uses user-supplied data to render things like comments and notes. In places where using React's built-in sanitization is possible, the feature is used. In other places, where some markup might be necessary, DOMPurify is used to sanitize the HTML before rendering it. Solves: GHSA-rh3r-8pxm-hg4w * Remove test post DOM rework * fixup! Rework frontend code interacting directly with DOM
1 parent c3a4585 commit d7ec735

File tree

11 files changed

+99
-69
lines changed

11 files changed

+99
-69
lines changed

ui/package-lock.json

Lines changed: 53 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"clsx": "^2.1.1",
2828
"connected-react-router": "^6.9.3",
2929
"deepmerge": "^4.3.1",
30+
"dompurify": "^3.3.1",
3031
"history": "^4.10.1",
3132
"inflection": "^3.0.2",
3233
"jwt-decode": "^4.0.0",

ui/src/album/AlbumDetails.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
import config from '../config'
3434
import { formatFullDate, intersperse } from '../utils'
3535
import AlbumExternalLinks from './AlbumExternalLinks'
36+
import { SafeHTML } from '../common/SafeHTML'
3637

3738
const useStyles = makeStyles(
3839
(theme) => ({
@@ -225,8 +226,7 @@ const AlbumDetails = (props) => {
225226
const [imageLoading, setImageLoading] = useState(false)
226227
const [imageError, setImageError] = useState(false)
227228

228-
let notes =
229-
albumInfo?.notes?.replace(new RegExp('<.*>', 'g'), '') || record.notes
229+
let notes = albumInfo?.notes || record.notes
230230

231231
if (notes) {
232232
notes += '..'
@@ -351,7 +351,7 @@ const AlbumDetails = (props) => {
351351
variant={'body1'}
352352
onClick={() => setExpanded(!expanded)}
353353
>
354-
<span dangerouslySetInnerHTML={{ __html: notes }} />
354+
<span><SafeHTML>{notes}</SafeHTML></span>
355355
</Typography>
356356
</Collapse>
357357
)}
@@ -371,7 +371,7 @@ const AlbumDetails = (props) => {
371371
variant={'body1'}
372372
onClick={() => setExpanded(!expanded)}
373373
>
374-
<span dangerouslySetInnerHTML={{ __html: notes }} />
374+
<span><SafeHTML>{notes}</SafeHTML></span>
375375
</Typography>
376376
</Collapse>
377377
</div>

0 commit comments

Comments
 (0)