From dd2cd6286cd3175e1518038a173218671adc68ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Wed, 16 Jun 2021 22:11:50 +0200 Subject: [PATCH] screenshot: Restrict callers The shell D-Bus API was always meant as a private API for core components, so enforce that by limiting caller to a list of allowed well-known names. Applications that want to request a screenshot can use the corresponding desktop portal. https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/3943 Part-of: --- js/ui/screenshot.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/js/ui/screenshot.js b/js/ui/screenshot.js index 81ab516b1..bf537b7d6 100644 --- a/js/ui/screenshot.js +++ b/js/ui/screenshot.js @@ -15,6 +15,7 @@ Gio._promisify(Shell.Screenshot.prototype, 'screenshot_area', 'screenshot_area_finish'); const { loadInterfaceXML } = imports.misc.fileUtils; +const { DBusSenderChecker } = imports.misc.util; const ScreenshotIface = loadInterfaceXML('org.gnome.Shell.Screenshot'); @@ -24,6 +25,12 @@ var ScreenshotService = class { this._dbusImpl.export(Gio.DBus.session, '/org/gnome/Shell/Screenshot'); this._screenShooter = new Map(); + this._senderChecker = new DBusSenderChecker([ + 'org.gnome.SettingsDaemon.MediaKeys', + 'org.freedesktop.impl.portal.desktop.gtk', + 'org.freedesktop.impl.portal.desktop.gnome', + 'org.gnome.Screenshot', + ]); this._lockdownSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.lockdown' }); @@ -46,6 +53,13 @@ var ScreenshotService = class { Gio.IOErrorEnum, Gio.IOErrorEnum.PERMISSION_DENIED, 'Saving to disk is disabled'); return null; + } else { + try { + this._senderChecker.checkInvocation(invocation); + } catch (e) { + invocation.return_gerror(e); + return null; + } } let shooter = new Shell.Screenshot(); @@ -254,6 +268,13 @@ var ScreenshotService = class { } async SelectAreaAsync(params, invocation) { + try { + this._senderChecker.checkInvocation(invocation); + } catch (e) { + invocation.return_gerror(e); + return; + } + let selectArea = new SelectArea(); try { let areaRectangle = await selectArea.selectAsync(); @@ -269,6 +290,13 @@ var ScreenshotService = class { } FlashAreaAsync(params, invocation) { + try { + this._senderChecker.checkInvocation(invocation); + } catch (e) { + invocation.return_gerror(e); + return; + } + let [x, y, width, height] = params; [x, y, width, height] = this._scaleArea(x, y, width, height); if (!this._checkArea(x, y, width, height)) {