-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathsecurity.js
43 lines (37 loc) · 1.55 KB
/
security.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Tests located in packages/server/test/unit/security_spec
/* eslint-disable
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const stream = require('stream')
const pumpify = require('pumpify')
const replacestream = require('replacestream')
const topOrParentEqualityBeforeRe = /((?:window|self)(?:\.|\[['"](?:top|self)['"]\])?\s*[!=]==?\s*(?:(?:window|self)(?:\.|\[['"]))?)(top|parent)/g
const topOrParentEqualityAfterRe = /(top|parent)((?:["']\])?\s*[!=]==?\s*(?:window|self))/g
const topOrParentLocationOrFramesRe = /([^\da-zA-Z\(\)])?(top|parent)([.])(location|frames)/g
const jiraTopWindowGetterRe = /(!function\s*\((\w{1})\)\s*{\s*return\s*\w{1}\s*(?:={2,})\s*\w{1}\.parent)(\s*}\(\w{1}\))/g
const strip = (html) => {
return html
.replace(topOrParentEqualityBeforeRe, '$1self')
.replace(topOrParentEqualityAfterRe, 'self$2')
.replace(topOrParentLocationOrFramesRe, '$1self$3$4')
.replace(jiraTopWindowGetterRe, '$1 || $2.parent.__Cypress__$3')
}
const stripStream = () => {
return pumpify(
replacestream(topOrParentEqualityBeforeRe, '$1self'),
replacestream(topOrParentEqualityAfterRe, 'self$2'),
replacestream(topOrParentLocationOrFramesRe, '$1self$3$4'),
replacestream(jiraTopWindowGetterRe, '$1 || $2.parent.__Cypress__$3')
)
}
module.exports = {
strip,
stripStream,
}