Files
cypress/packages/server/lib/util/security.coffee
Brian Mann 2f8da7a7f0 server: fix runaway regexp fails parsing a massive JS file (#1331)
* server: fix runaway regexp fails parsing a massive JS file

* server: fix linting errors, better debug logs

* server: lint fix again
2018-02-17 00:26:38 -05:00

27 lines
842 B
CoffeeScript

stream = require("stream")
pumpify = require("pumpify")
replacestream = require("replacestream")
topOrParentEqualityBeforeRe = /((?:window|self)(?:\.|\[['"](?:top|self)['"]\])?\s*[!=][=]\s*(?:(?:window|self)(?:\.|\[['"]))?)(top|parent)/g
topOrParentEqualityAfterRe = /(top|parent)((?:["']\])?\s*[!=][=].*(?:window|self))/g
topOrParentLocationOrFramesRe = /([^\da-zA-Z])(top|parent)([.])(location|frames)/g
strip = (html) ->
html
.replace(topOrParentEqualityBeforeRe, "$1self")
.replace(topOrParentEqualityAfterRe, "self$2")
.replace(topOrParentLocationOrFramesRe, "$1self$3$4")
stripStream = ->
pumpify(
replacestream(topOrParentEqualityBeforeRe, "$1self")
replacestream(topOrParentEqualityAfterRe, "self$2")
replacestream(topOrParentLocationOrFramesRe, "$1self$3$4")
)
module.exports = {
strip
stripStream
}