Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move XmlHttpRequest and Fetch patches to cross-origin injection code #23967

Closed
AtofStryker opened this issue Sep 23, 2022 · 3 comments · Fixed by #24243
Closed

Move XmlHttpRequest and Fetch patches to cross-origin injection code #23967

AtofStryker opened this issue Sep 23, 2022 · 3 comments · Fixed by #24243

Comments

@AtofStryker
Copy link
Contributor

What would you like?

In preparation for experimentalSessionAndOrigin to go GA, we likely need to move the XmlHttpRequest and Fetch injections into the injection/cross-origin.js file. Since Cypress may or may not be instantiated yet, we might be able to leverage postMessage to send credentialStatus and resourceType to the primary, and the primary sends the information to the web socket.

Currently the Cypress.backend request happens before the request is actually send to the server, which usually almost always means that the credentials are stored in the map by the time the proxy tries to access them. If using postMessage, this might no longer be the case, and the proxy may need to listen for an event or poll until it finds the credentials it needs without slowing down the proxy server

Why is this needed?

Given the following example:

it('does a cross-origin navigation', () => {
  cy.visit('https://localhost:8080/index.html')

  cy.visit('https://www.foobar.com/index.html')
  /**
   * After visit, The AUT calls:
   *
   * fetch('www.boobaz.com/test-request', { credentials: 'include' })
   *
   * Since there is no cy.origin block active, or maybe the patch happens after the request,
   * we are unable to infer the credentials in the proxy, which essentially leads to
   * the ability of the request for www.boobaz.com/test-request does not attach cookies nor
   * has the ability to set them. This might be a problem for those who attach a cy.origin lazily after visit,
   * or are using cy.visit with chromeWebSecurity: false without cy.origin blocks.
   */
})

Other

No response

@AtofStryker AtofStryker changed the title Move XmlHttpRequest and Fetch patches to main injection code Move XmlHttpRequest and Fetch patches to cross-origin injection code Sep 23, 2022
@AtofStryker
Copy link
Contributor Author

Added from the joint #23872 review:

currently without a cy.origin block, we can't actually figure out what credentials were applied, and also leaves errors for when the cy.origin block is attached. One possible solution is to send the url and credential status of postMessage to the primary, and send this up to the backend. If we can figure out a graceful way to handle the possible race condition of which gets there first, a) the request or b) the credentials, this could be a good way forward. This shouldn't block release immediately, but needs to be figured out before going GA

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 19, 2022

The code for this is done in cypress-io/cypress#24243, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 25, 2022

Released in 10.11.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v10.11.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Oct 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants