Skip to content

Commit 9934910

Browse files
authored
fix: rewrite top.window.location as self.window.location. This is done under modifyObstructiveCode flag (#31688)
1 parent 4b6218b commit 9934910

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

.circleci/workflows.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ mainBuildFilters: &mainBuildFilters
3838
- /^release\/\d+\.\d+\.\d+$/
3939
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
4040
- 'update-v8-snapshot-cache-on-develop'
41-
- 'feat/add_webpack_bundle_analyzer'
41+
- 'fix/top_framebust_window_location'
4242

4343
# usually we don't build Mac app - it takes a long time
4444
# but sometimes we want to really confirm we are doing the right thing
@@ -49,7 +49,7 @@ macWorkflowFilters: &darwin-workflow-filters
4949
- equal: [ develop, << pipeline.git.branch >> ]
5050
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
5151
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
52-
- equal: [ 'feat/add_webpack_bundle_analyzer', << pipeline.git.branch >> ]
52+
- equal: [ 'fix/top_framebust_window_location', << pipeline.git.branch >> ]
5353
- matches:
5454
pattern: /^release\/\d+\.\d+\.\d+$/
5555
value: << pipeline.git.branch >>
@@ -60,7 +60,7 @@ linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
6060
- equal: [ develop, << pipeline.git.branch >> ]
6161
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
6262
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
63-
- equal: [ 'feat/add_webpack_bundle_analyzer', << pipeline.git.branch >> ]
63+
- equal: [ 'fix/top_framebust_window_location', << pipeline.git.branch >> ]
6464
- matches:
6565
pattern: /^release\/\d+\.\d+\.\d+$/
6666
value: << pipeline.git.branch >>
@@ -83,7 +83,7 @@ windowsWorkflowFilters: &windows-workflow-filters
8383
- equal: [ develop, << pipeline.git.branch >> ]
8484
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
8585
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
86-
- equal: [ 'feat/add_webpack_bundle_analyzer', << pipeline.git.branch >> ]
86+
- equal: [ 'fix/top_framebust_window_location', << pipeline.git.branch >> ]
8787
- matches:
8888
pattern: /^release\/\d+\.\d+\.\d+$/
8989
value: << pipeline.git.branch >>
@@ -157,7 +157,7 @@ commands:
157157
name: Set environment variable to determine whether or not to persist artifacts
158158
command: |
159159
echo "Setting SHOULD_PERSIST_ARTIFACTS variable"
160-
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "feat/add_webpack_bundle_analyzer" ]]; then
160+
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "fix/top_framebust_window_location" ]]; then
161161
export SHOULD_PERSIST_ARTIFACTS=true
162162
fi' >> "$BASH_ENV"
163163
# You must run `setup_should_persist_artifacts` command and be using bash before running this command

cli/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ _Released 5/20/2025 (PENDING)_
1010
**Bugfixes:**
1111

1212
- Fixed an issue with the experimental usage of WebKit where Cypress incorrectly displayed `0` as the WebKit version. Addresses [#31684](https://github.com/cypress-io/cypress/issues/31684).
13+
- Fixed an issue where framebusting was occurring when `top.window.location` was being set explicitly. This fix does not require the `experimentalModifyObstructiveThirdPartyCode` configuration option. Addresses [#31687](https://github.com/cypress-io/cypress/issues/31687).
1314

1415
**Misc:**
1516

packages/proxy/lib/http/util/regex-rewriter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const topOrParentEqualityAfterRe = /(top|parent)((?:["']\])?\s*[!=]==?\s*(?:\bwi
1212
const topOrParentExpandedEqualityBeforeRe = /((?:\bwindow\b|\bself\b|\b[a-zA-z]\.\b)(?:\.|\[['"](?:top|self)['"]\])?\s*[!=]==?\s*(?:(?:window|self|[a-zA-z])(?:\.|\[['"]))?)(top|parent)(?![\w])/g
1313
const topOrParentExpandedEqualityAfterRe = /(top|parent)((?:["']\])?\s*[!=]==?\s*(?:\bwindow\b|\b(?:[a-zA-z]\.)?self\b))/g
1414

15+
// outright frame busting with top.window.location = 'https://www.foobar.com'
16+
const topWindowLocationRe = /(top)(\.window\.location\s?=)/g
17+
1518
const topOrParentLocationOrFramesRe = /([^\da-zA-Z\(\)])?(\btop\b|\bparent\b)([.])(\blocation\b|\bframes\b)/g
1619

1720
const jiraTopWindowGetterRe = /(!function\s*\((\w{1})\)\s*{\s*return\s*\w{1}\s*(?:={2,})\s*\w{1}\.parent)(\s*}\(\w{1}\))/g
@@ -38,6 +41,7 @@ export function strip (html: string, { modifyObstructiveThirdPartyCode }: Partia
3841
.replace(topOrParentLocationOrFramesRe, '$1self$3$4')
3942
.replace(jiraTopWindowGetterRe, '$1 || $2.parent.__Cypress__$3')
4043
.replace(jiraTopWindowGetterUnMinifiedRe, '$1 || $2.parent.__Cypress__$3')
44+
.replace(topWindowLocationRe, 'self$2')
4145

4246
if (modifyObstructiveThirdPartyCode) {
4347
rewrittenHTML = rewrittenHTML.replace(javaScriptIntegrityReplacementRe, `['${STRIPPED_INTEGRITY_TAG}']$2`)
@@ -59,6 +63,7 @@ export function stripStream ({ modifyObstructiveThirdPartyCode }: Partial<Securi
5963
topOrParentLocationOrFramesRe,
6064
jiraTopWindowGetterRe,
6165
jiraTopWindowGetterUnMinifiedRe,
66+
topWindowLocationRe,
6267
...(modifyObstructiveThirdPartyCode ? [
6368
javaScriptIntegrityReplacementRe,
6469
generalIntegrityReplacementRe,
@@ -70,6 +75,7 @@ export function stripStream ({ modifyObstructiveThirdPartyCode }: Partial<Securi
7075
'$1self$3$4',
7176
'$1 || $2.parent.__Cypress__$3',
7277
'$1 || $2.parent.__Cypress__$3',
78+
'self$2',
7379
...(modifyObstructiveThirdPartyCode ? [
7480
`['${STRIPPED_INTEGRITY_TAG}']$2`,
7581
`${STRIPPED_INTEGRITY_TAG}$3`,

packages/proxy/test/unit/http/util/regex-rewriter.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ const original = `\
8282
if (fooparent===selfVar) return
8383
if (loadStop===windowFile) return
8484
if (fooparent===windowFile) return
85+
top.window.location='https://www.foobar.com'
8586
</script>
8687
</body>
8788
</html>\
@@ -163,6 +164,7 @@ const expected = `\
163164
if (fooparent===selfVar) return
164165
if (loadStop===windowFile) return
165166
if (fooparent===windowFile) return
167+
self.window.location='https://www.foobar.com'
166168
</script>
167169
</body>
168170
</html>\

0 commit comments

Comments
 (0)