Commit 278cd717 authored by NGPixel's avatar NGPixel

feat: rendering security module

parent 4fb08cb1
......@@ -161,6 +161,7 @@
"uuid": "3.3.3",
"validate.js": "0.13.1",
"winston": "3.2.1",
"xss": "1.0.6",
"yargs": "15.0.2"
},
"devDependencies": {
......
......@@ -19,7 +19,8 @@ module.exports = {
...rendererInfo,
...rdr,
config: _.sortBy(_.transform(rdr.config, (res, value, key) => {
const configData = _.get(rendererInfo.props, key, {})
const configData = _.get(rendererInfo.props, key, false)
if (configData) {
res.push({
key,
value: JSON.stringify({
......@@ -27,6 +28,7 @@ module.exports = {
value
})
})
}
}, []), 'key')
}
})
......
......@@ -5,4 +5,5 @@ author: requarks.io
icon: mdi-code-braces
enabledDefault: true
dependsOn: htmlCore
step: pre
props: {}
......@@ -14,7 +14,11 @@ module.exports = {
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`)
renderer.init($, child.config)
}
......@@ -211,6 +215,17 @@ module.exports = {
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
icon: mdi-function-variant
enabledDefault: false
dependsOn: htmlCore
step: pre
props: {}
......@@ -5,14 +5,10 @@ author: requarks.io
icon: mdi-fire
enabledDefault: true
dependsOn: htmlCore
step: post
props:
stripJS:
safeHTML:
type: Boolean
title: Strip Javascript
default: false
hint: Javascript code within code blocks won't be affected
filterBadWords:
type: Boolean
title: Filter Bad Words
default: false
hint: Replace bad words with asterisks
title: Sanitize HTML
default: true
hint: Sanitize HTML from unsafe attributes and tags that could lead to XSS attacks
module.exports = {
init($, config) {
const xss = require('xss')
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