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

SUID workaround #256

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
22 changes: 22 additions & 0 deletions script/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,25 @@ export function run(spawnOptions: SpawnOptions) {

return spawn(binaryPath, [], opts)
}

// fallback workaround for hardened linux kernel, especially Debian 10

export function runNoSandbox(spawnOptions: SpawnOptions) {
try {
// eslint-disable-next-line no-sync
const stats = Fs.statSync(binaryPath)
if (!stats.isFile()) {
return null
}
} catch (e) {
return null
}

const opts = Object.assign({}, spawnOptions)

opts.env = Object.assign(opts.env || {}, process.env, {
NODE_ENV: 'development',
})

return spawn(binaryPath, ['--no-sandbox'], opts)
}
27 changes: 26 additions & 1 deletion script/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { forceUnwrap as u } from '../app/src/lib/fatal-error'

import configs = require('../app/webpack.development')

import { run } from './run'
import { run, runNoSandbox } from './run'

function getPortOrDefault() {
const port = process.env.PORT
Expand All @@ -32,6 +32,31 @@ function startApp() {
return
}

runningApp.on('exit', (code, signal) => {
if (process.platform === 'linux') {
// attempt --no-sandbox workaround
const display_warning =
'\nWARNING: Default behavior is to abort upon sandbox error, but ' +
'GitHub Desktop will override to run without sandboxing.' +
'\nAdditional configuration may allow you to avoid seeing this error.' +
'\n\nPlease see more details on https://github.com/shiftkey/desktop/issues/222\n'
console.log(display_warning)
const linuxNoSandbox = runNoSandbox({ stdio: 'inherit' })

if (linuxNoSandbox != null) {
linuxNoSandbox.on('close', () => {
process.exit(0)
})
}
} else {
console.log('child process exited with code ' + code)
}
})

runningApp.on('error', (err) => {
console.log('failed to start process', err)
})

runningApp.on('close', () => {
process.exit(0)
})
Expand Down