cypress icon indicating copy to clipboard operation
cypress copied to clipboard

Cypress replaces usages of variables called "parent" with "self"

Open umanghome opened this issue 2 years ago • 2 comments

Current behavior

Whenever a variable called "parent" is used in the same line as a variable named "window", Cypress silently replaces "parent" with "self".

We found a relevant PR that may have introduced this code (https://github.com/cypress-io/cypress/pull/1295) for security reasons, but it misses a pretty trivial case like eval("parent"), as demonstrated in the reproduction. As long as the string version of "parent" is left as-is, any attacker can get the value of parent.

Desired behavior

There should at least be documentation for this, or this behavior should be opt-in. This is very tricky to even debug when you have source maps enabled which shows "self" as "parent".

Test code to reproduce

https://github.com/umanghome/cypress-parent-self-issue

You can see the code that runs on the page here: https://codesandbox.io/s/cypress-parent-self-issue-qjee0g?file=/script.js

Source code

image

What the browser sees while running Cypress

See line 8, where Cypress replaced parent with self. But it did not on line 13. image

Cypress Version

12.0.2

Node version

v16.13.2

Operating System

macOS 12.3

Debug Logs

No response

Other

No response

umanghome avatar Dec 10 '22 12:12 umanghome

Replacing parent with self is used to prevent frame-busting, since Cypress runs your application in an iframe. Without it, any sites that have frame-busting can't run in Cypress since they tend to take over the entirety of the browser. It's documented here and configurable with the modifyObstructiveCode option.

Looks like replacing eval('parent') isn't one we've encountered or taken into consideration, so I'll route this to my team to look into that.

chrisbreiding avatar Jan 12 '23 18:01 chrisbreiding

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

cypress-app-bot avatar Jul 12 '23 02:07 cypress-app-bot

This issue has been closed due to inactivity.

cypress-app-bot avatar Jul 27 '23 01:07 cypress-app-bot