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

Application ID is empty when a host app uses portals #579

Closed
carlocastoldi opened this issue Apr 29, 2021 · 7 comments
Closed

Application ID is empty when a host app uses portals #579

carlocastoldi opened this issue Apr 29, 2021 · 7 comments

Comments

@carlocastoldi
Copy link
Contributor

Like the title says, I found myself in need (and will) to use the Inhibit portal from a not yet flatpak-able application.
Unlike many other portal methods Inhibit doesn't take an app_id as parameter of the call, but the backend API presents it as a parameter without even specifying anywhere in the docs (I couldn't find it) that app_id is an empty string when Inhibit is used.

app_info->id = g_strdup ("");

This clashes with xdg-desktop-portal-gtk because Gtk requires a not-empty Application ID in order to grant the inhibition permission, making the usage of the portal practically unusable on GNOME by an host app.

From what @matthiasclasen told me, the portal relies on the unfakeable ID gotten from flatpak (or snap?) and not from the app-id specified in the program. The reason for this. as far as i know, appears to be that sometimes app id is used (by whom?) as a key for storing things and passing it outside of a sandbox could be a security threat.

  • Why is it a problem to pass the ID as input to portals such as Inhibit, Screenshot or ScreenCast, while for some others such as Documents, FileChooser, AppChooser or Print it isn't?
  • If I wanted to make a pull request to change the above-mentioned line in xdp-utils.c without changing Inhibit's interface, would I be able to retrieve the app ID from the window's handle? If yes, how? I would be ok to start by doing it for Wayland's application windows only.
  • If you think it is really impossible and an hassle to handle this case, should I try to make a pull request for xdg-desktop-portal-gtk so that it retrieves the ID from the handle or—if it is not possible—it uses a placeholder ID (like in gnome-session-inhibit)? I know the latter wouldn't be a beautiful solution, but it's better then denying it altogether.
  • Can you update the docs so that it is clear that app_id is empty for some portal backend API? I have spent many hours investigating this problem and I would like if others didn't do my same mistake in the future.

Why am I troubling so much using portals? I could just use XYZ!

The reason I want to use portals so bad is that I recently read more about them and I saw the hope of having a better interoperability between environments as possible. A standard that every app can follow and an easy way to manage apps' permissions.
That said, as far as I know, still many Flatpak apps don't fully use them, and thus many of them need more permissions than they should actually need.
I am really afraid that the situation won't change until portals become the de-facto standard. And a standard cannot be established if portals are used only by applications designed for Flatpak. And even if it did happen, many already-written apps might not see a re-implementation.

This is why, on my very little, I wanted to do my part and help a very common application (caffeine-ng, not yet flatpak-able) to get closer to this more universal language

Demo

You can use my small Gtk4 test application as a demo: xdg-portal-inhibitor-test-gtk4.py

@matthiasclasen
Copy link
Contributor

No portal methods take the application ID as argument.

We can't let the untrusted application in the sandbox provide its own ID. It could by lying.

We need the application ID to be provided from the outside, by flatpak

@carlocastoldi
Copy link
Contributor Author

No portal methods take the application ID as argument.

Then I suppose Documents's methods (frontend API) such as AddFull or GrantPermissions have an app_id parameter but it is a calculated risk because it wouldn't be a major threat if they were manipulated? I am genuinely asking.

We can't let the untrusted application in the sandbox provide its own ID. It could by lying.

We need the application ID to be provided from the outside, by flatpak

That is why I was thinking of using only handles from Wayland. Shouldn't it be really difficult to fake/steal information by design? If this was the case I don't see why we shouldn't trust a pseudo-random unique string. Chances of getting it right are probabilistically none.

Plus: if an un-sendboxed application is using portals because of their convenience, shouldn't it be already untrusted and capable of doing bad things outside of portals (e.g. on Xorg alone)? Trying to make portals secure-by-design on host applications feels a bit like trying to bury our head in the sand.

@swick
Copy link
Contributor

swick commented Apr 29, 2021

This clashes with xdg-desktop-portal-gtk because Gtk requires a not-empty Application ID in order to grant the inhibition permission, making the usage of the portal practically unusable on GNOME by an host app.

This sounds like a bug? Everything else you describe works as intended.

Then I suppose Documents's methods (frontend API) such as AddFull or GrantPermissions have an app_id parameter but it is a calculated risk because it wouldn't be a major threat if they were manipulated? I am genuinely asking.

All connections to the portal implicitly, through a side-channel, contain the app_id of the connected process. This app_id is used to determine the permissions. An app_id as an argument to the portal is just like any other argument. In this case it is used to specify who to give permission to for a file that you have to proof you have access to.

@carlocastoldi
Copy link
Contributor Author

This clashes with xdg-desktop-portal-gtk because Gtk requires a not-empty Application ID in order to grant the inhibition permission, making the usage of the portal practically unusable on GNOME by an host app.

This sounds like a bug? Everything else you describe works as intended.

Mmmh I remember seeing a commit/merge request on some gitlab.gnome.org official repo that explicitly enabled this feature. I guess to inform the user which process is responsible for the inhibition? I don't know.
All I know is that I am pretty sure they did it on purpose.

Then I suppose Documents's methods (frontend API) such as AddFull or GrantPermissions have an app_id parameter but it is a calculated risk because it wouldn't be a major threat if they were manipulated? I am genuinely asking.

All connections to the portal implicitly, through a side-channel, contain the app_id of the connected process. This app_id is used to determine the permissions. An app_id as an argument to the portal is just like any other argument. In this case it is used to specify who to give permission to for a file that you have to proof you have access to.

Ok. That clears that little doubt I had. Thanks for taking the time explaining me. As you may have understood I am pretty new to this interface.

P.S. May I ask if you could please address my propositions as well? Were they so out-of-this-world?

mwleeds pushed a commit that referenced this issue Mar 2, 2022
This commit adds an optional dependency on libsystemd and, when
available, uses it to attempt to find an application ID even for
processes which are not Snap or Flatpak sandboxes. This is not always
successful, so we still need to handle the case of an empty app ID for
an XdpAppInfo.

Since this is not a perfect solution for finding the app ID, we may
eventually want to introduce a way for *unsandboxed* processes to
specify their own app ID, perhaps a portal-wide SetAppID() method. This
is analogous to the security model gnome-shell has: if a process is
sandboxed use that app ID, and otherwise use information that is under
the control of the application (e.g. WM_CLASS, GApplication ID, etc.).

Helps: #579

(Originally authored by Carlo Castoldi, re-done by Phaedrus Leeds)
mwleeds pushed a commit that referenced this issue Mar 2, 2022
This commit adds an optional dependency on libsystemd and, when
available, uses it to attempt to find an application ID even for
processes which are not Snap or Flatpak sandboxes. This is not always
successful, so we still need to handle the case of an empty app ID for
an XdpAppInfo.

Since this is not a perfect solution for finding the app ID, we may
eventually want to introduce a way for *unsandboxed* processes to
specify their own app ID, perhaps a portal-wide SetAppID() method. This
is analogous to the security model gnome-shell has: if a process is
sandboxed use that app ID, and otherwise use information that is under
the control of the application (e.g. WM_CLASS, GApplication ID, etc.).

Helps: #579

(Originally authored by Carlo Castoldi, re-done by Phaedrus Leeds)
mwleeds pushed a commit that referenced this issue Mar 2, 2022
This commit adds an optional dependency on libsystemd and, when
available, uses it to attempt to find an application ID even for
processes which are not Snap or Flatpak sandboxes. This is not always
successful, so we still need to handle the case of an empty app ID for
an XdpAppInfo.

Since this is not a perfect solution for finding the app ID, we may
eventually want to introduce a way for *unsandboxed* processes to
specify their own app ID, perhaps a portal-wide SetAppID() method. This
is analogous to the security model gnome-shell has: if a process is
sandboxed use that app ID, and otherwise use information that is under
the control of the application (e.g. WM_CLASS, GApplication ID, etc.).

Helps: #579

(Originally authored by Carlo Castoldi, re-done by Phaedrus Leeds)
@mwleeds
Copy link
Contributor

mwleeds commented Mar 2, 2022

No portal methods take the application ID as argument.

Then I suppose Documents's methods (frontend API) such as AddFull or GrantPermissions have an app_id parameter but it is a calculated risk because it wouldn't be a major threat if they were manipulated? I am genuinely asking.

In those methods the app_id parameter is the app ID being granted permissions, not the app ID of the calling process. The interface allows one app to grant permissions to another (conditional on a permission check for the caller).

mwleeds pushed a commit that referenced this issue Mar 7, 2022
This commit adds an optional dependency on libsystemd and, when
available, uses it to attempt to find an application ID even for
processes which are not Snap or Flatpak sandboxes. This is not always
successful, so we still need to handle the case of an empty app ID for
an XdpAppInfo.

Since this is not a perfect solution for finding the app ID, we may
eventually want to introduce a way for *unsandboxed* processes to
specify their own app ID, perhaps a portal-wide SetAppID() method. This
is analogous to the security model gnome-shell has: if a process is
sandboxed use that app ID, and otherwise use information that is under
the control of the application (e.g. WM_CLASS, GApplication ID, etc.).

Helps: #579

(Originally authored by Carlo Castoldi, re-done by Phaedrus Leeds)
mwleeds pushed a commit that referenced this issue Mar 8, 2022
This commit adds an optional dependency on libsystemd and, when
available, uses it to attempt to find an application ID even for
processes which are not Snap or Flatpak sandboxes. This is not always
successful, so we still need to handle the case of an empty app ID for
an XdpAppInfo.

Since this is not a perfect solution for finding the app ID, we may
eventually want to introduce a way for *unsandboxed* processes to
specify their own app ID, perhaps a portal-wide SetAppID() method. This
is analogous to the security model gnome-shell has: if a process is
sandboxed use that app ID, and otherwise use information that is under
the control of the application (e.g. WM_CLASS, GApplication ID, etc.).

Helps: #579

(Originally authored by Carlo Castoldi, re-done by Phaedrus Leeds)
GeorgesStavracas pushed a commit that referenced this issue Mar 11, 2022
This commit adds an optional dependency on libsystemd and, when
available, uses it to attempt to find an application ID even for
processes which are not Snap or Flatpak sandboxes. This is not always
successful, so we still need to handle the case of an empty app ID for
an XdpAppInfo.

Since this is not a perfect solution for finding the app ID, we may
eventually want to introduce a way for *unsandboxed* processes to
specify their own app ID, perhaps a portal-wide SetAppID() method. This
is analogous to the security model gnome-shell has: if a process is
sandboxed use that app ID, and otherwise use information that is under
the control of the application (e.g. WM_CLASS, GApplication ID, etc.).

Helps: #579

(Originally authored by Carlo Castoldi, re-done by Phaedrus Leeds)
GeorgesStavracas pushed a commit that referenced this issue Mar 11, 2022
This commit adds an optional dependency on libsystemd and, when
available, uses it to attempt to find an application ID even for
processes which are not Snap or Flatpak sandboxes. This is not always
successful, so we still need to handle the case of an empty app ID for
an XdpAppInfo.

Since this is not a perfect solution for finding the app ID, we may
eventually want to introduce a way for *unsandboxed* processes to
specify their own app ID, perhaps a portal-wide SetAppID() method. This
is analogous to the security model gnome-shell has: if a process is
sandboxed use that app ID, and otherwise use information that is under
the control of the application (e.g. WM_CLASS, GApplication ID, etc.).

Helps: #579

(Originally authored by Carlo Castoldi, re-done by Phaedrus Leeds)
@carlocastoldi
Copy link
Contributor Author

#719 fixes my use case for which I opened this issue. From my part this issue can be closed.
Don't know if you'd like to keep it open for those use cases where the un-sendoxed application is not launched from shell...

@GeorgesStavracas
Copy link
Member

Yeah, I don't think we need to cover this use-case for now. Properly spawning applications require some help from the compositor and the session manager these days, and that's primarily what we're trying to improve here.

Thanks everyone for your work here.

@mwleeds mwleeds changed the title Application ID is empty when an host app uses portals Application ID is empty when a host app uses portals Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants