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

base64 encode the embedded runner config object so it can't b… #5155

Merged
merged 3 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>")