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

feat: always set the browser sandbox feature for Electron >= 5.0.0 #22

Merged
merged 3 commits into from
May 3, 2019
Merged
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
5 changes: 3 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ Available features:

* `audio` - PulseAudio support
* `alsa` - ALSA support *(replaces `audio` support if both are specified)*
* `browserSandbox` - [web browser functionality](https://github.com/snapcore/snapd/wiki/Interfaces#browser-support)
(e.g., Brave)
* `browserSandbox` - [web browser functionality](https://github.com/snapcore/snapd/wiki/Interfaces#browser-support).
This is enabled by default when using Electron ≥ 5.0.0, due to the
[setuid sandbox support](https://github.com/electron/electron/pull/17269).
* `mpris` - [MPRIS](https://specifications.freedesktop.org/mpris-spec/latest/) support. If enabled,
the interface name must be specified as the feature value.
* `passwords` - Access the secret service (e.g., GNOME Keyring)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@
"dependencies": {
"cross-spawn-promise": "^0.10.1",
"debug": "^4.1.1",
"electron-installer-common": "^0.6.1",
"electron-installer-common": "^0.6.3",
"fs-extra": "^7.0.1",
"js-yaml": "^3.10.0",
"lodash.filter": "^4.6.0",
"lodash.merge": "^4.6.0",
"lodash.pull": "^4.1.0",
"nodeify": "^1.0.1",
"pify": "^4.0.1",
"semver": "^6.0.0",
"tmp-promise": "^1.0.3",
"which": "^1.3.0",
"yargs": "^13.2.2"
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const copyIcon = require('./icon')
const { copyLauncher } = require('./launcher')
const createYamlFromTemplate = require('./yaml')
const defaultArgsFromApp = require('./default_args')
const { updateSandboxHelperPermissions } = require('electron-installer-common')

class SnapCreator {
prepareOptions (userSupplied) {
Expand Down Expand Up @@ -88,6 +89,7 @@ class SnapCreator {
const snapMetaDir = path.join(snapDir, 'snap')
const snapGuiDir = path.join(snapMetaDir, 'gui')
return fs.ensureDir(snapGuiDir)
.then(() => updateSandboxHelperPermissions(this.packageDir))
.then(() => createDesktopFile(snapGuiDir, this.config))
.then(() => copyIcon(snapGuiDir, this.config))
.then(() => copyLauncher(snapDir, this.config))
Expand Down
27 changes: 17 additions & 10 deletions src/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const fs = require('fs-extra')
const merge = require('lodash.merge')
const path = require('path')
const pull = require('lodash.pull')
const semver = require('semver')
const yaml = require('js-yaml')

const { createDesktopLaunchCommand } = require('./launcher')
Expand Down Expand Up @@ -117,13 +118,16 @@ class SnapcraftYAML {
}

transformFeatures () {
if (semver.satisfies(this.electronVersion, '>= 5.0.0') && !this.features.browserSandbox) {
this.features.browserSandbox = true
}
for (const feature of Object.keys(this.features)) {
this.transformFeature(feature)
}
}

transformBrowserSandbox () {
debug('Replacing brower-support plug with browser-sandbox')
debug('Replacing browser-support plug with browser-sandbox')
pull(this.app.plugs, 'browser-support')
this.app.plugs.push('browser-sandbox')
if (!this.data.plugs) {
Expand All @@ -133,7 +137,7 @@ class SnapcraftYAML {
'allow-sandbox': true,
interface: 'browser-support'
}
console.warn('This setting will trigger a manual review in the Snap store.')
console.warn('The browser-sandbox feature will trigger a manual review in the Snap store.')
}

transformMPRIS () {
Expand All @@ -157,14 +161,13 @@ class SnapcraftYAML {
this.parts.organize = {}
this.parts.organize[path.basename(packageDir)] = this.data.name

return common.readElectronVersion(packageDir)
.then(version => this.updateDependencies(version))
return this.updateDependencies()
}

updateDependencies (version) {
this.parts.after[0] = common.getGTKDepends(version, DEPENDENCY_MAP)
this.parts['stage-packages'] = this.parts['stage-packages'].concat(common.getGConfDepends(version, DEPENDENCY_MAP))
.concat(common.getUUIDDepends(version, DEPENDENCY_MAP))
updateDependencies () {
this.parts.after[0] = common.getGTKDepends(this.electronVersion, DEPENDENCY_MAP)
this.parts['stage-packages'] = this.parts['stage-packages'].concat(common.getGConfDepends(this.electronVersion, DEPENDENCY_MAP))
.concat(common.getUUIDDepends(this.electronVersion, DEPENDENCY_MAP))

return this.data
}
Expand Down Expand Up @@ -192,8 +195,12 @@ class SnapcraftYAML {
this.renameSubtree(this.data.apps, 'electronApp', this.appName)
this.validateSummary()
this.app.command = createDesktopLaunchCommand(this.data)
this.transformFeatures()
return this.transformParts(packageDir)
return common.readElectronVersion(packageDir)
.then(electronVersion => {
this.electronVersion = electronVersion
this.transformFeatures()
return this.transformParts(packageDir)
})
}

write (filename) {
Expand Down
12 changes: 10 additions & 2 deletions test/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,24 @@ test('setting both audio and alsa prefers alsa', t =>
)

test('browserSandbox feature', t =>
createYaml(t, { name: 'electronAppName', features: { 'browserSandbox': true } })
createYaml(t, { name: 'electronAppName', features: { browserSandbox: true } })
.then(snapcraftYaml => {
util.assertNotIncludes(t, snapcraftYaml.apps.electronAppName.plugs, 'browser-support', 'browser-support is not in app plugs')
util.assertIncludes(t, snapcraftYaml.apps.electronAppName.plugs, 'browser-sandbox', 'browser-sandbox is in app plugs')
return t.deepEqual(snapcraftYaml.plugs['browser-sandbox'], { interface: 'browser-support', 'allow-sandbox': true }, 'browser-sandbox plug exists')
})
)

test('browserSandbox is always on for Electron >= 5.0.0', t =>
createYaml(t, { name: 'electronAppName' }, '5.0.0')
.then(snapcraftYaml => {
util.assertNotIncludes(t, snapcraftYaml.apps.electronAppName.plugs, 'browser-support', 'browser-support is not in app plugs')
return util.assertIncludes(t, snapcraftYaml.apps.electronAppName.plugs, 'browser-sandbox', 'browser-sandbox is in app plugs')
})
)

test('browserSandbox feature with custom plugs', t =>
createYaml(t, { name: 'electronAppName', appPlugs: ['foobar'], features: { 'browserSandbox': true }, plugs: { foobar: { interface: 'dbus', name: 'com.example.foobar' } } })
createYaml(t, { name: 'electronAppName', appPlugs: ['foobar'], features: { browserSandbox: true }, plugs: { foobar: { interface: 'dbus', name: 'com.example.foobar' } } })
.then(snapcraftYaml => {
util.assertIncludes(t, snapcraftYaml.apps.electronAppName.plugs, 'browser-sandbox', 'browser-sandbox is in app plugs')
util.assertIncludes(t, snapcraftYaml.apps.electronAppName.plugs, 'foobar', 'foobar is in app plugs')
Expand Down