Skip to content
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

feat(packages/sui-js): exclude script tags in html sanitization #1674

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion packages/sui-js/src/react/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,46 @@
export {default as htmlStringToReactElement} from 'htmr'
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: {
...DANGEROUS_TRANSFORMS,
...options?.transform
}
})

const isReactRefObj = target => {
if (target && typeof target === 'object') {
Expand Down
Loading