Ensure OAS3 Markdown fields are sanitized
This commit is contained in:
@@ -2,15 +2,8 @@ import React, { PropTypes } from "react"
|
|||||||
import Remarkable from "react-remarkable"
|
import Remarkable from "react-remarkable"
|
||||||
import sanitize from "sanitize-html"
|
import sanitize from "sanitize-html"
|
||||||
|
|
||||||
const sanitizeOptions = {
|
|
||||||
textFilter: function(text) {
|
|
||||||
return text
|
|
||||||
.replace(/"/g, "\"")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function Markdown({ source }) {
|
function Markdown({ source }) {
|
||||||
const sanitized = sanitize(source, sanitizeOptions)
|
const sanitized = sanitizer(source)
|
||||||
return <Remarkable
|
return <Remarkable
|
||||||
options={{html: true, typographer: true, linkify: true, linkTarget: "_blank"}}
|
options={{html: true, typographer: true, linkify: true, linkTarget: "_blank"}}
|
||||||
source={sanitized}
|
source={sanitized}
|
||||||
@@ -22,3 +15,14 @@ Markdown.propTypes = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default Markdown
|
export default Markdown
|
||||||
|
|
||||||
|
const sanitizeOptions = {
|
||||||
|
textFilter: function(text) {
|
||||||
|
return text
|
||||||
|
.replace(/"/g, "\"")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sanitizer(str) {
|
||||||
|
return sanitize(str, sanitizeOptions)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import ReactMarkdown from "react-markdown"
|
import ReactMarkdown from "react-markdown"
|
||||||
import { OAS3ComponentWrapFactory } from "../helpers"
|
import { OAS3ComponentWrapFactory } from "../helpers"
|
||||||
|
import { sanitizer } from "core/components/providers/markdown"
|
||||||
|
|
||||||
export default OAS3ComponentWrapFactory(({ source }) => { return source ? (
|
export default OAS3ComponentWrapFactory(({ source }) => { return source ? (
|
||||||
<ReactMarkdown
|
<ReactMarkdown
|
||||||
source={source}
|
source={sanitizer(source)}
|
||||||
className={"renderedMarkdown"}
|
className={"renderedMarkdown"}
|
||||||
/>
|
/>
|
||||||
) : null})
|
) : null})
|
||||||
|
|||||||
Reference in New Issue
Block a user