Commit 278cd717 authored by NGPixel's avatar NGPixel

feat: rendering security module

parent 4fb08cb1
...@@ -161,6 +161,7 @@ ...@@ -161,6 +161,7 @@
"uuid": "3.3.3", "uuid": "3.3.3",
"validate.js": "0.13.1", "validate.js": "0.13.1",
"winston": "3.2.1", "winston": "3.2.1",
"xss": "1.0.6",
"yargs": "15.0.2" "yargs": "15.0.2"
}, },
"devDependencies": { "devDependencies": {
......
...@@ -19,14 +19,16 @@ module.exports = { ...@@ -19,14 +19,16 @@ module.exports = {
...rendererInfo, ...rendererInfo,
...rdr, ...rdr,
config: _.sortBy(_.transform(rdr.config, (res, value, key) => { config: _.sortBy(_.transform(rdr.config, (res, value, key) => {
const configData = _.get(rendererInfo.props, key, {}) const configData = _.get(rendererInfo.props, key, false)
res.push({ if (configData) {
key, res.push({
value: JSON.stringify({ key,
...configData, value: JSON.stringify({
value ...configData,
value
})
}) })
}) }
}, []), 'key') }, []), 'key')
} }
}) })
......
...@@ -5,4 +5,5 @@ author: requarks.io ...@@ -5,4 +5,5 @@ author: requarks.io
icon: mdi-code-braces icon: mdi-code-braces
enabledDefault: true enabledDefault: true
dependsOn: htmlCore dependsOn: htmlCore
step: pre
props: {} props: {}
...@@ -14,7 +14,11 @@ module.exports = { ...@@ -14,7 +14,11 @@ module.exports = {
return '' return ''
} }
for (let child of this.children) { // --------------------------------
// STEP: PRE
// --------------------------------
for (let child of _.reject(this.children, ['step', 'post'])) {
const renderer = require(`../${_.kebabCase(child.key)}/renderer.js`) const renderer = require(`../${_.kebabCase(child.key)}/renderer.js`)
renderer.init($, child.config) renderer.init($, child.config)
} }
...@@ -211,6 +215,17 @@ module.exports = { ...@@ -211,6 +215,17 @@ module.exports = {
headers.push(headerSlug) headers.push(headerSlug)
}) })
return $.html('body').replace('<body>', '').replace('</body>', '') let output = $.html('body').replace('<body>', '').replace('</body>', '')
// --------------------------------
// STEP: POST
// --------------------------------
for (let child of _.filter(this.children, ['step', 'post'])) {
const renderer = require(`../${_.kebabCase(child.key)}/renderer.js`)
output = renderer.init(output, child.config)
}
return output
} }
} }
...@@ -5,4 +5,5 @@ author: requarks.io ...@@ -5,4 +5,5 @@ author: requarks.io
icon: mdi-function-variant icon: mdi-function-variant
enabledDefault: false enabledDefault: false
dependsOn: htmlCore dependsOn: htmlCore
step: pre
props: {} props: {}
...@@ -5,14 +5,10 @@ author: requarks.io ...@@ -5,14 +5,10 @@ author: requarks.io
icon: mdi-fire icon: mdi-fire
enabledDefault: true enabledDefault: true
dependsOn: htmlCore dependsOn: htmlCore
step: post
props: props:
stripJS: safeHTML:
type: Boolean type: Boolean
title: Strip Javascript title: Sanitize HTML
default: false default: true
hint: Javascript code within code blocks won't be affected hint: Sanitize HTML from unsafe attributes and tags that could lead to XSS attacks
filterBadWords:
type: Boolean
title: Filter Bad Words
default: false
hint: Replace bad words with asterisks
module.exports = { const xss = require('xss')
init($, config) {
module.exports = {
async init(input, config) {
if (config.safeHTML) {
input = xss(input, {
whiteList: {
...xss.whiteList,
a: ['class', 'id', 'href', 'target', 'title'],
blockquote: ['class', 'id'],
code: ['class'],
div: ['class', 'id'],
em: ['class'],
h1: ['class', 'id'],
h2: ['class', 'id'],
h3: ['class', 'id'],
h4: ['class', 'id'],
h5: ['class', 'id'],
h6: ['class', 'id'],
img: ['alt', 'class', 'draggable', 'height', 'src', 'width'],
li: ['class'],
ol: ['class'],
p: ['class'],
pre: ['class'],
strong: ['class'],
table: ['border', 'class', 'id', 'width'],
tbody: ['class'],
td: ['align', 'class', 'colspan', 'rowspan', 'valign'],
th: ['align', 'class', 'colspan', 'rowspan', 'valign'],
thead: ['class'],
tr: ['class', 'rowspan', 'align', 'valign'],
ul: ['class']
}
})
}
return input
} }
} }
This diff was suppressed by a .gitattributes entry.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment