-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
fix: Disallow same-superdomain-origin
cy.origin blocks
#24569
fix: Disallow same-superdomain-origin
cy.origin blocks
#24569
Conversation
Thanks for taking the time to open a PR!
|
same-superdomain-origin
cy.origin blockssame-superdomain-origin
cy.origin blocks
|
||
const origin = location.origin | ||
|
||
// This is set while IN the cy.origin command. | ||
cy.state('currentActiveOrigin', origin) | ||
|
||
return new Bluebird((resolve, reject, onCancel) => { | ||
const cleanup = ({ readyForOriginFailed }: {readyForOriginFailed?: boolean} = {}): void => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readyForOriginFailed was dead code
}) | ||
} | ||
|
||
export function urlMatchesOriginProps (url, props) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed a couple of functions that were not used anywhere:
- urlMatchesOriginProps
- urlMatchesPolicyProps
- urlMatchesSameSiteProps
urlsSuperDomainOriginMatch and urlMatchesSuperDomainOriginProps are replaced by urlMatchesPolicyBasedOnDomain and urlMatchesPolicyBasedOnDomainProps
@@ -39,13 +39,14 @@ module.exports = { | |||
}) | |||
}, | |||
|
|||
handleCrossOriginIframe (req, res) { | |||
handleCrossOriginIframe (req, res, namespace) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are changes to make cypress in cypress work better (not totally fixed yet)
// TODO: The below route is not technically correct for cypress in cypress tests. | ||
// We should be using 'config.namespace' to provide the namespace instead of hard coding __cypress, however, | ||
// In the runner when we create the spec bridge we have no knowledge of the namespace used by the server so | ||
// we create a spec bridge for the namespace of the server specified in the config, but that server hasn't been created. | ||
// To fix this I think we need to find a way to listen in the cypress in cypress server for routes from the server the | ||
// cypress instance thinks should exist, but that's outside the current scope. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment says it all
const { subdomain: _unused, ...remoteProps } = cors.parseUrlIntoHostProtocolDomainTldPort(remoteOrigin) | ||
const remoteProps = cors.parseUrlIntoHostProtocolDomainTldPort(remoteOrigin) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this change, checking same-origin of something like www.google.com would always fail since the www was getting dropped. We need to keep subdomain.
Test summaryRun details
View run in Cypress Dashboard ➡️ Flakiness
This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we need to change the messaging on whether the user provides same origin vs cross origin but is same super domain origin to help point them to the right place
same-superdomain-origin
cy.origin blockssame-superdomain-origin
cy.origin blocks
@@ -11,6 +11,8 @@ const debug = debugModule('cypress:network:cors') | |||
// match IP addresses or anything following the last . | |||
const customTldsRe = /(^[\d\.]+$|\.[^\.]+$)/ | |||
|
|||
const strictSameOriginDomains = Object.freeze(['google.com']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mjhenkes can we allow somehow parametrizing this? we have mobile tests that are on the same domain, but they require different user-agent. we were trying to override it with cy.origin()
and it worked perfectly well till this PR change...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rnovosad would you be able to share an example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AtofStryker I provided it in the comment #2100 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rnovosad got it. I will reply to the thread there!
User facing changelog
Additional details
There are several changes included in this pr
cy.origin
block with thesame-superdomain-origin
as top will throw an error.same-origin
. Google is the only domain that is currently excepted.same-origin
but notsame-superdomain-origin
.cy.origin
to handle cases when the spec bridge isn't created. Previously this would cause a hang in the test.Steps to test
Run the tests added in the PR.
How has the user experience changed?
Same domain error cy cy.origin:
Failed to create spec bridge error:
PR Tasks
cypress-documentation
?type definitions
?