Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion packages/block-text/src/EmailMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,29 @@ const GENERIC_ALLOWED_ATTRIBUTES = ['style', 'title'];
function sanitizer(html: string): string {
return insane(html, {
allowedTags: ALLOWED_TAGS,
allowedSchemes: ['http', 'https', 'mailto'],
allowedAttributes: {
...ALLOWED_TAGS.reduce<Record<string, string[]>>((res, tag) => {
res[tag] = [...GENERIC_ALLOWED_ATTRIBUTES];
return res;
}, {}),
img: ['src', 'srcset', 'alt', 'width', 'height', ...GENERIC_ALLOWED_ATTRIBUTES],
img: ['src', 'alt', 'width', 'height', ...GENERIC_ALLOWED_ATTRIBUTES],
table: ['width', ...GENERIC_ALLOWED_ATTRIBUTES],
td: ['align', 'width', ...GENERIC_ALLOWED_ATTRIBUTES],
th: ['align', 'width', ...GENERIC_ALLOWED_ATTRIBUTES],
a: ['href', 'target', ...GENERIC_ALLOWED_ATTRIBUTES],
ol: ['start', ...GENERIC_ALLOWED_ATTRIBUTES],
ul: ['start', ...GENERIC_ALLOWED_ATTRIBUTES],
},
filter: (token) => {
if (token.tag === 'a' && 'href' in token.attrs && token.attrs.href === undefined) {
token.attrs.href = '';
}
if (token.tag === 'img' && 'src' in token.attrs && token.attrs.src === undefined) {
token.attrs.src = '';
}
return true;
},
});
}

Expand Down
54 changes: 54 additions & 0 deletions packages/block-text/src/__snapshots__/index.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,60 @@ exports[`block-text sanitizes HTML 1`] = `
</p>


<div>


<img
src=""
/>


<a>
link 1
</a>


<a
href=""
>
link 2
</a>


<a
href=""
>
link 3
</a>


<a
title=""
>
link 4
</a>


<a
title=""
>
link 5
</a>


<a>
link 6
</a>


<a>
link 7
</a>


</div>


</div>
</DocumentFragment>
`;
11 changes: 11 additions & 0 deletions packages/block-text/src/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ describe('block-text', () => {
![Uh oh...](https://www.example.com/image.png"onload="alert('XSS'))
![Escape SRC - onload](https://www.example.com/image.png"onload="alert('ImageOnLoad'))
![Escape SRC - onerror]("onerror="alert('ImageOnError'))

<div>
<img src />
<a>link 1</a>
<a href>link 2</a>
<a href="">link 3</a>
<a title>link 4</a>
<a title="">link 5</a>
<a href="ftp://domain.name">link 6</a>
<a href="javascript:alert('hello world')">link 7</a>
</div>
`,
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function TextSidebarPanel({ data, setData }: TextSidebarPanelProp
onChange={(text) => updateData({ ...data, props: { ...data.props, text } })}
/>
<BooleanInput
label="Markdown"
label="Markdown (GitHub flavored)"
defaultValue={data.props?.markdown ?? false}
onChange={(markdown) => updateData({ ...data, props: { ...data.props, markdown } })}
/>
Expand Down