Skip to content

Commit

Permalink
fix: re include document domain injections for spec-bridge and inject…
Browse files Browse the repository at this point in the history
…ion and disable origin-agent-cluster (#25013)

* Revert "chore: remove document.domain usage for cross-origin testing (#24945)"

This reverts commit a3d3074.

* fix: set origin-agent-cluster=?0 for the spec bridge iframe

* re apply comment that was reverted in 1fa1246

* Update packages/server/lib/routes-e2e.ts

Co-authored-by: Matt Schile <mschile@cypress.io>

* chore: update document.domain immutable target from chrome 106 -> chrome 109

Co-authored-by: Matt Schile <mschile@cypress.io>
  • Loading branch information
AtofStryker and mschile authored Dec 6, 2022
1 parent afb66ab commit ca01e29
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 11 deletions.
7 changes: 3 additions & 4 deletions packages/driver/src/cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,9 @@ class $Cypress {
configure (config: Record<string, any> = {}) {
const domainName = config.remote ? config.remote.domainName : undefined

// set domainName but allow us to turn off this feature in testing. not
// needed for cross-origin spec bridge, since it is strictly used
// same-origin
if (domainName && !this.isCrossOriginSpecBridge && config.testingType === 'e2e') {
// set domainName but allow us to turn
// off this feature in testing
if (domainName && config.testingType === 'e2e') {
document.domain = domainName
}

Expand Down
2 changes: 1 addition & 1 deletion packages/proxy/lib/http/response-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ const SetInjectionLevel: ResponseMiddleware = function () {
}

if (this.res.wantsInjection) {
// Chrome plans to make document.domain immutable in Chrome 106, with the default value
// Chrome plans to make document.domain immutable in Chrome 109, with the default value
// of the Origin-Agent-Cluster header becoming 'true'. We explicitly disable this header
// so that we can continue to support tests that visit multiple subdomains in a single spec.
// https://github.com/cypress-io/cypress/issues/20147
Expand Down
4 changes: 3 additions & 1 deletion packages/proxy/lib/http/util/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ export function full (domain) {
})
}

export async function fullCrossOrigin (options: FullCrossOriginOpts) {
export async function fullCrossOrigin (domain, options: FullCrossOriginOpts) {
const contents = await getRunnerCrossOriginInjectionContents()

return oneLine`
<script type='text/javascript'>
document.domain = '${domain}';
(function (cypressConfig) {
${contents}
}(${JSON.stringify(options)}));
Expand Down
2 changes: 1 addition & 1 deletion packages/proxy/lib/http/util/rewriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function getHtmlToInject (opts: InjectionOpts & SecurityOpts) {
case 'full':
return inject.full(domainName)
case 'fullCrossOrigin':
return inject.fullCrossOrigin({
return inject.fullCrossOrigin(domainName, {
modifyObstructiveThirdPartyCode,
modifyObstructiveCode,
simulatedCookies,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/controllers/iframes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const iframesController = {
extraOptions,
})

// Chrome plans to make document.domain immutable in Chrome 106, with the default value
// Chrome plans to make document.domain immutable in Chrome 109, with the default value
// of the Origin-Agent-Cluster header becoming 'true'. We explicitly disable this header
// so that we can continue to support tests that visit multiple subdomains in a single spec.
// https://github.com/cypress-io/cypress/issues/20147
Expand Down
3 changes: 3 additions & 0 deletions packages/server/lib/html/spec-bridge-iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<title>{{title}}</title>
</head>
<body>
<script type="text/javascript">
document.domain = '{{domain}}';
</script>
<script src="/{{namespace}}/runner/cypress_cross_origin_runner.js"></script>
</body>
</html>
7 changes: 7 additions & 0 deletions packages/server/lib/routes-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ export const createRoutesE2E = ({
routesE2E.get('/__cypress/spec-bridge-iframes', (req, res) => {
debug('handling cross-origin iframe for domain: %s', req.hostname)

// Chrome plans to make document.domain immutable in Chrome 109, with the default value
// of the Origin-Agent-Cluster header becoming 'true'. We explicitly disable this header
// in the spec-bridge-iframe to allow setting document.domain to the bare domain
// to guarantee the spec bridge can communicate with the injected code.
// @see https://github.com/cypress-io/cypress/issues/25010
res.setHeader('Origin-Agent-Cluster', '?0')

files.handleCrossOriginIframe(req, res, config.namespace)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const createCommonRoutes = ({
router.get(clientRoute, (req: Request & { proxiedUrl?: string }, res) => {
const nonProxied = req.proxiedUrl?.startsWith('/') ?? false

// Chrome plans to make document.domain immutable in Chrome 106, with the default value
// Chrome plans to make document.domain immutable in Chrome 109, with the default value
// of the Origin-Agent-Cluster header becoming 'true'. We explicitly disable this header
// so that we can continue to support tests that visit multiple subdomains in a single spec.
// https://github.com/cypress-io/cypress/issues/20147
Expand Down
15 changes: 13 additions & 2 deletions packages/server/test/integration/http_requests_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,17 @@ describe('Routes', () => {
})
})

it('correctly sets the "origin-agent-cluster" to opt in to setting document.domain on spec bridge iframes', function () {
return this.rp('http://localhost:2020/__cypress/spec-bridge-iframes')
.then((res) => {
expect(res.statusCode).to.eq(200)

expect(res.body).to.match(/document.domain = \'localhost\'/)

expect(res.headers['origin-agent-cluster']).to.eq('?0')
})
})

it('sets title to projectName', function () {
return this.rp('http://localhost:2020/__')
.then((res) => {
Expand Down Expand Up @@ -2651,7 +2662,7 @@ describe('Routes', () => {
})
})

it('does not inject document.domain on AUT iframe requests that do not match current superDomain', function () {
it('injects document.domain on AUT iframe requests that do not match current superDomain', function () {
nock('http://www.foobar.com')
.get('/')
.reply(200, '<html><head></head><body>hi</body></html>', {
Expand All @@ -2671,7 +2682,7 @@ describe('Routes', () => {

const body = cleanResponseBody(res.body)

expect(body).not.to.include('document.domain =')
expect(body).to.include(`<html><head> <script type='text/javascript'> document.domain = 'foobar.com';`)
})
})

Expand Down

5 comments on commit ca01e29

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ca01e29 Dec 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.0.1/linux-arm64/develop-ca01e29ab8989af14cdddc7e3ffb30a96e73c3b8/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ca01e29 Dec 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.0.1/linux-x64/develop-ca01e29ab8989af14cdddc7e3ffb30a96e73c3b8/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ca01e29 Dec 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.0.1/darwin-x64/develop-ca01e29ab8989af14cdddc7e3ffb30a96e73c3b8/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ca01e29 Dec 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.0.1/darwin-arm64/develop-ca01e29ab8989af14cdddc7e3ffb30a96e73c3b8/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ca01e29 Dec 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.0.1/win32-x64/develop-ca01e29ab8989af14cdddc7e3ffb30a96e73c3b8/cypress.tgz

Please sign in to comment.