Skip to content

Commit

Permalink
Merge pull request hackmdio#1046 from SISheogorath/feature/optimizeXSS
Browse files Browse the repository at this point in the history
Remove the xss library from webpack
  • Loading branch information
SISheogorath committed Nov 11, 2018
2 parents 722d3ed + a5ac300 commit 21d7c9f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
7 changes: 5 additions & 2 deletions public/js/render.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-env browser, jquery */
/* global filterXSS */
// allow some attributes

var filterXSS = require('xss')

var whiteListAttr = ['id', 'class', 'style']
window.whiteListAttr = whiteListAttr
// allow link starts with '.', '/' and custom protocol with '://', exclude link starts with javascript://
Expand Down Expand Up @@ -71,5 +73,6 @@ function preventXSS (html) {
window.preventXSS = preventXSS

module.exports = {
preventXSS: preventXSS
preventXSS: preventXSS,
escapeAttrValue: filterXSS.escapeAttrValue
}
4 changes: 2 additions & 2 deletions public/js/reveal-markdown.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env browser, jquery */

import { preventXSS } from './render'
import { preventXSS, escapeAttrValue } from './render'
import { md } from './extra'

/**
Expand Down Expand Up @@ -259,7 +259,7 @@ import { md } from './extra'
while ((matchesClass = mardownClassRegex.exec(classes))) {
var name = matchesClass[1]
var value = matchesClass[2]
if (name.substr(0, 5) === 'data-' || window.whiteListAttr.indexOf(name) !== -1) { elementTarget.setAttribute(name, window.filterXSS.escapeAttrValue(value)) }
if (name.substr(0, 5) === 'data-' || window.whiteListAttr.indexOf(name) !== -1) { elementTarget.setAttribute(name, escapeAttrValue(value)) }
}
return true
}
Expand Down
6 changes: 0 additions & 6 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ module.exports = {
'babel-polyfill',
'script-loader!jquery-ui-resizable',
'script-loader!js-url',
'expose-loader?filterXSS!xss',
'script-loader!Idle.Js',
'expose-loader?LZString!lz-string',
'script-loader!codemirror',
Expand Down Expand Up @@ -253,7 +252,6 @@ module.exports = {
'script-loader!handlebars',
'expose-loader?hljs!highlight.js',
'expose-loader?emojify!emojify.js',
'expose-loader?filterXSS!xss',
'script-loader!Idle.Js',
'script-loader!gist-embed',
'expose-loader?LZString!lz-string',
Expand All @@ -273,7 +271,6 @@ module.exports = {
],
pretty: [
'babel-polyfill',
'expose-loader?filterXSS!xss',
'flowchart.js',
'js-sequence-diagrams',
'expose-loader?RevealMarkdown!reveal-markdown',
Expand All @@ -298,7 +295,6 @@ module.exports = {
'script-loader!handlebars',
'expose-loader?hljs!highlight.js',
'expose-loader?emojify!emojify.js',
'expose-loader?filterXSS!xss',
'script-loader!gist-embed',
'flowchart.js',
'js-sequence-diagrams',
Expand All @@ -310,7 +306,6 @@ module.exports = {
slide: [
'babel-polyfill',
'bootstrap-tooltip',
'expose-loader?filterXSS!xss',
'flowchart.js',
'js-sequence-diagrams',
'expose-loader?RevealMarkdown!reveal-markdown',
Expand Down Expand Up @@ -338,7 +333,6 @@ module.exports = {
'script-loader!handlebars',
'expose-loader?hljs!highlight.js',
'expose-loader?emojify!emojify.js',
'expose-loader?filterXSS!xss',
'script-loader!gist-embed',
'flowchart.js',
'js-sequence-diagrams',
Expand Down

0 comments on commit 21d7c9f

Please sign in to comment.