Skip to content

Commit

Permalink
base64 encode the embedded runner config object so it can't b… (#5155)
Browse files Browse the repository at this point in the history
* base64 encode the config so it can't be escaped

* update tests
  • Loading branch information
flotwig authored Sep 17, 2019
1 parent 72b082d commit 8cde36e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 11 deletions.
4 changes: 3 additions & 1 deletion packages/runner/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import Container from './app/container'
configure({ enforceActions: 'strict' })

const Runner = {
start (el, config) {
start (el, base64Config) {
action('started', () => {
const config = JSON.parse(atob(base64Config))

const state = new State((config.state || {}).reporterWidth)

Runner.state = state
Expand Down
2 changes: 1 addition & 1 deletion packages/runner/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
window.__Cypress__ = true

setTimeout(function(){
Runner.start(document.getElementById('app'), {{{config}}})
Runner.start(document.getElementById('app'), "{{{base64Config}}}")
}, 0)
</script>
</body>
Expand Down
12 changes: 7 additions & 5 deletions packages/server/__snapshots__/2_config_spec.coffee.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ exports['e2e config passes 1'] = `
✓ .arch
✓ .browser
✓ .spec
.env
✓ doesn't die on <script> tags
5 passing
6 passing
(Results)
┌──────────────────────────────────────────┐
│ Tests: 5
│ Passing: 5
│ Tests: 6
│ Passing: 6
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
Expand All @@ -56,9 +58,9 @@ exports['e2e config passes 1'] = `
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✔ config_passing_spec.coffee XX:XX 5 5 - - - │
│ ✔ config_passing_spec.coffee XX:XX 6 6 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
All specs passed! XX:XX 5 5 - - -
All specs passed! XX:XX 6 6 - - -
`
Expand Down
6 changes: 5 additions & 1 deletion packages/server/lib/controllers/runner.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ module.exports = {
_.pick(config, "version", "platform", "arch", "projectName")
)

## base64 before embedding so user-supplied contents can't break out of <script>
## https://github.com/cypress-io/cypress/issues/4952
base64Config = Buffer.from(JSON.stringify(config)).toString('base64')

res.render(runner.getPathToIndex(), {
config: JSON.stringify(config)
base64Config
projectName: config.projectName
})

Expand Down
5 changes: 5 additions & 0 deletions packages/server/test/e2e/2_config_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ describe "e2e config", ->
spec: "config_passing_spec.coffee"
snapshot: true
expectedExitCode: 0
config: {
env: {
scriptlet: "<script>alert('this should not break')</script>"
}
}
})

it "fails", ->
Expand Down
8 changes: 6 additions & 2 deletions packages/server/test/integration/http_requests_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,12 @@ describe "Routes", ->
@rp("http://localhost:9999/__")
.then (res) ->
expect(res.statusCode).to.eq(200)
expect(res.body).to.include("version")
expect(res.body).to.include(pkg.version)

base64Config = /Runner\.start\(.*, "(.*)"\)/.exec(res.body)[1]
configStr = Buffer.from(base64Config, 'base64').toString()

expect(configStr).to.include("version")
expect(configStr).to.include(pkg.version)

context "GET /__cypress/runner/*", ->
beforeEach ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe "Cypress static methods + props", ->
expect(browser.version).to.be.a("string")
expect(browser.majorVersion).to.be.a("string")
expect(browser.path).to.be.a("string")

switch browser.isHeadless
when true
expect(browser.isHeaded).to.be.false
Expand All @@ -34,3 +34,8 @@ describe "Cypress static methods + props", ->
expect(spec.name).to.eq("config_passing_spec.coffee")
expect(spec.relative).to.eq("cypress/integration/config_passing_spec.coffee")
expect(spec.absolute.indexOf("cypress/integration/config_passing_spec.coffee")).to.be.gt(0)

context ".env", ->
## https://github.com/cypress-io/cypress/issues/4952
it "doesn't die on <script> tags", ->
expect(Cypress.env('scriptlet')).to.eq("<script>alert('this should not break')</script>")

4 comments on commit 8cde36e

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8cde36e Sep 17, 2019

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/linux-x64/circle-develop-8cde36eacca1bff5dca7b6c4ab208a425c96eefb-152273/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.5.0/circle-develop-8cde36eacca1bff5dca7b6c4ab208a425c96eefb-152291/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8cde36e Sep 17, 2019

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/win32-ia32/appveyor-develop-8cde36eacca1bff5dca7b6c4ab208a425c96eefb-27478025/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.5.0/win32-ia32/appveyor-develop-8cde36eacca1bff5dca7b6c4ab208a425c96eefb-27478025/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8cde36e Sep 17, 2019

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/win32-x64/appveyor-develop-8cde36eacca1bff5dca7b6c4ab208a425c96eefb-27478025/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.5.0/win32-x64/appveyor-develop-8cde36eacca1bff5dca7b6c4ab208a425c96eefb-27478025/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8cde36e Sep 17, 2019

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/darwin-x64/circle-develop-8cde36eacca1bff5dca7b6c4ab208a425c96eefb-152319/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.5.0/circle-develop-8cde36eacca1bff5dca7b6c4ab208a425c96eefb-152317/cypress.tgz

Please sign in to comment.