Skip to content

Commit f5b84e5

Browse files
authored
feat: markdown sanitization of form tag (#7146)
1 parent 4abbc62 commit f5b84e5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/core/components/providers/markdown.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function sanitizer(str, { useUnsafeMarkdown = false } = {}) {
6868

6969
return DomPurify.sanitize(str, {
7070
ADD_ATTR: ["target"],
71-
FORBID_TAGS: ["style"],
71+
FORBID_TAGS: ["style", "form"],
7272
ALLOW_DATA_ATTR,
7373
FORBID_ATTR,
7474
})

test/unit/xss/markdown-script-sanitization.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ describe("Markdown Script Sanitization", function() {
1616
const el = render(<Markdown source={str} />)
1717
expect(el.html()).toEqual(`<div class="markdown"><p><img src="x"></p>\n</div>`)
1818
})
19+
20+
it("sanitizes <form> elements", function() {
21+
const str = `"<form action='https://do.not.use.url/fake' method='post' action='java'><input type='email' id='email' placeholder='Email-address' name='email' value=''><button type='submit'>Login</button>"`
22+
const el = render(<Markdown source={str} />)
23+
expect(el.html()).toEqual(`<div class="markdown"><p>&quot;</p><input value name="email" placeholder="Email-address" id="email" type="email"><button type="submit">Login</button>&quot;<p></p>\n</div>`)
24+
})
1925
})
2026

2127
describe("OAS 3", function() {
@@ -30,5 +36,11 @@ describe("Markdown Script Sanitization", function() {
3036
const el = render(<OAS3Markdown source={str} />)
3137
expect(el.html()).toEqual(`<div class="renderedMarkdown"><p><img src="x"></p></div>`)
3238
})
39+
40+
it("sanitizes <form> elements", function () {
41+
const str = `"<form action='https://do.not.use.url/fake' method='post' action='java'><input type='email' id='email' placeholder='Email-address' name='email' value=''><button type='submit'>Login</button>"`
42+
const el = render(<OAS3Markdown source={str} />)
43+
expect(el.html()).toEqual(`<div class="renderedMarkdown"><p>&quot;</p><input value name="email" placeholder="Email-address" id="email" type="email"><button type="submit">Login</button>&quot;<p></p></div>`)
44+
})
3345
})
3446
})

0 commit comments

Comments
 (0)