Skip to content

Commit

Permalink
feat(packages/sui-js): exclude all dangerous html elements
Browse files Browse the repository at this point in the history
  • Loading branch information
stivaliserna committed Dec 1, 2023
1 parent 92ef4e3 commit b2fd013
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion packages/sui-js/src/react/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
import htmr from 'htmr'

// This is a list of all the elements that should not be allowed to be rendered as they pose a security risk.
// See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element
// If you want to allow one of these elements, you can add it to the `transform` object in the `options`.
export const DANGEROUS_TRANSFORMS = {
area: () => null,
audio: () => null,
base: () => null,
canvas: () => null,
embed: () => null,
form: () => null,
frame: () => null,
frameset: () => null,
head: () => null,
html: () => null,
iframe: () => null,
img: () => null,
link: () => null,
map: () => null,
meta: () => null,
noscript: () => null,
object: () => null,
picture: () => null,
portal: () => null,
script: () => null,
slot: () => null,
source: () => null,
style: () => null,
template: () => null,
title: () => null,
track: () => null,
video: () => null
}

export const htmlStringToReactElement = (string, options) =>
htmr(string, {
...options,
transform: {
script: () => null,
...DANGEROUS_TRANSFORMS,
...options?.transform
}
})
Expand Down

0 comments on commit b2fd013

Please sign in to comment.