Skip to content

Commit

Permalink
fix: only modify js on AUT domain in proxy (#9018)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuceb authored Nov 9, 2020
1 parent dae76a8 commit 5198a86
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
**/support/fixtures/*
!**/support/fixtures/projects
**/support/fixtures/projects/**/_fixtures/*
**/support/fixtures/projects/**/static/*
**/support/fixtures/projects/**/*.jsx
**/support/fixtures/projects/**/jquery.js
**/support/fixtures/projects/**/fail.js
**/test/fixtures
**/vendor
Expand Down Expand Up @@ -41,4 +41,4 @@ npm/webpack-preprocessor/examples/use-babelrc/cypress/integration/spec.js
**/.cy
**/.git

/npm/react/bin/*
/npm/react/bin/*
5 changes: 3 additions & 2 deletions packages/proxy/lib/http/response-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,13 @@ const PatchExpressSetHeader: ResponseMiddleware = function () {
const SetInjectionLevel: ResponseMiddleware = function () {
this.res.isInitial = this.req.cookies['__cypress.initial'] === 'true'

const isReqMatchOriginPolicy = reqMatchesOriginPolicy(this.req, this.getRemoteState())
const getInjectionLevel = () => {
if (this.incomingRes.headers['x-cypress-file-server-error'] && !this.res.isInitial) {
return 'partial'
}

if (!resContentTypeIs(this.incomingRes, 'text/html') || !reqMatchesOriginPolicy(this.req, this.getRemoteState())) {
if (!resContentTypeIs(this.incomingRes, 'text/html') || !isReqMatchOriginPolicy) {
return false
}

Expand All @@ -261,7 +262,7 @@ const SetInjectionLevel: ResponseMiddleware = function () {
this.res.wantsInjection = getInjectionLevel()
}

this.res.wantsSecurityRemoved = this.config.modifyObstructiveCode && (
this.res.wantsSecurityRemoved = this.config.modifyObstructiveCode && isReqMatchOriginPolicy && (
(this.res.wantsInjection === 'full')
|| resContentTypeIsJavaScript(this.incomingRes)
)
Expand Down
16 changes: 16 additions & 0 deletions packages/server/test/e2e/7_proxying_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import e2e from '../support/helpers/e2e'

describe('e2e proxying spec', () => {
e2e.setup({
servers: {
port: 7878,
static: true,
cors: true,
https: true,
},
})

e2e.it('integrity check', {
spec: 'proxying_spec.js',
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
describe('proxying', () => {
// load a script that has obstructive code and would otherwise be modified by the proxy
// https://github.com/cypress-io/cypress/issues/8983
it('does not fail integrity check for cross-origin scripts', () => {
cy.visit('/index.html')
.then((win) => {
/**
* @type {Document}
*/
const document = win.document
const script = document.createElement('script')

script.src = 'https://localhost:7878/static/simple_obstructive_code.js'
script.integrity = 'sha256-iVKZPZrzbe7YNdMKYWJ1+f74j5lD3gRFvGjqtLyji6A='
script.crossOrigin = 'anonymous'
document.head.append(script)

return new Promise((resolve, reject) => {
script.onload = resolve
script.onerror = () => reject(new Error('script failed to load, check the console. Possibly a failed integrity check'))
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const path = require('path')
const Promise = require('bluebird')
const { useFixedFirefoxResolution } = require('../../../utils')

/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
let performance = {
track: () => Promise.resolve(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(function () {
if (top != self) {console.log('loaded!')}
})()
4 changes: 4 additions & 0 deletions packages/server/test/support/helpers/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ const startServer = function (obj) {

app.use(morgan('dev'))

if (obj.cors) {
app.use(require('cors')())
}

const s = obj.static

if (s) {
Expand Down

3 comments on commit 5198a86

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5198a86 Nov 9, 2020

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/5.6.0/circle-develop-5198a866bd4e6b7cc1ecc5261f740087cc9e9e0d/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5198a86 Nov 9, 2020

Choose a reason for hiding this comment

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

AppVeyor 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/5.5.1/appveyor-develop-5198a866bd4e6b7cc1ecc5261f740087cc9e9e0d/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5198a86 Nov 9, 2020

Choose a reason for hiding this comment

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

AppVeyor has built the win32 ia32 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/5.5.1/appveyor-develop-5198a866bd4e6b7cc1ecc5261f740087cc9e9e0d/cypress.tgz

Please sign in to comment.