Skip to content

Commit

Permalink
fix: refuse to render non-string Markdown field values (via #5295)
Browse files Browse the repository at this point in the history
  • Loading branch information
shockey authored Apr 10, 2019
1 parent f50bbec commit 1dd87ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/components/providers/markdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ DomPurify.addHook("beforeSanitizeElements", function (current, ) {
const isPlainText = (str) => /^[A-Z\s0-9!?\.]+$/gi.test(str)

function Markdown({ source, className = "" }) {
if (typeof source !== "string") {
return null
}

if(isPlainText(source)) {
// If the source text is not Markdown,
// let's save some time and just render it.
Expand Down
4 changes: 4 additions & 0 deletions src/core/plugins/oas3/wrap-components/markdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ parser.block.ruler.enable(["table"])
parser.set({ linkTarget: "_blank" })

export const Markdown = ({ source, className = "" }) => {
if(typeof source !== "string") {
return null
}

if ( source ) {
const html = parser.render(source)
const sanitized = sanitizer(html)
Expand Down

0 comments on commit 1dd87ce

Please sign in to comment.