Last Comment Bug 707625 - [WebAPI] Proper WebAPI permissions manager
: [WebAPI] Proper WebAPI permissions manager
Status: RESOLVED WONTFIX
:
Product: Core
Classification: Components
Component: General (show other bugs)
: Trunk
: All Gonk (Firefox OS)
: -- normal (vote)
: ---
Assigned To: Jim Straus
:
Mentors:
Depends on: 749379
Blocks: webapi 707626 707659 b2g-product-phone 758271
  Show dependency treegraph
 
Reported: 2011-12-05 03:18 PST by Justin Lebar (not reading bugmail)
Modified: 2013-08-15 20:01 PDT (History)
28 users (show)
curtisk: sec‑review+
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---
+
+


Attachments
Sketch of code for Permissions (58.56 KB, patch)
2012-03-15 10:27 PDT, Jim Straus
jstraus: review-
Details | Diff | Review
Changes to allow for prompting for more than geolocation, change to camera to use (9.10 KB, patch)
2012-03-20 08:01 PDT, Jim Straus
no flags Details | Diff | Review
WIP PermissionManager (16.94 KB, text/plain)
2012-06-13 13:48 PDT, Jim Straus
no flags Details
WIP PermissionManager (39.08 KB, patch)
2012-06-27 13:49 PDT, Jim Straus
no flags Details | Diff | Review

Description Justin Lebar (not reading bugmail) 2011-12-05 03:18:23 PST
Lots of our new Web APIs should not be available to all pages.

But we need a centralized piece of code which manages these permissions.
Comment 1 Justin Lebar (not reading bugmail) 2011-12-05 03:21:54 PST
cjones said in bug 702256 comment 48 that the current nsPermissionManager is dying.  I don't know why -- it seems pretty straightforward...
Comment 2 Justin Lebar (not reading bugmail) 2012-01-04 09:40:12 PST
This is the bug I filed a while back on the new permissions API.

Jonas, you said you had some thoughts about how this should work?
Comment 3 Chris Jones [:cjones] inactive; ni?/f?/r? if you need me 2012-01-04 14:25:05 PST
(In reply to Justin Lebar [:jlebar] from comment #1)
> cjones said in bug 702256 comment 48 that the current nsPermissionManager is
> dying.  I don't know why -- it seems pretty straightforward...

That's what I heard.  I don't have any primary-source information.
Comment 4 Chris Jones [:cjones] inactive; ni?/f?/r? if you need me 2012-01-04 14:30:27 PST
Some desiderata
 - needs to work across processes, both in that all gecko processes can do permissions checks, and in that a parent process can do a permission check of a child.  (The latter part needs to be designed very carefully, and could maybe be a followup.)
 - probably needs to be fast.
 - (obviously), populated from web-app manifests.  User force-overrides would be a nice-to-have.
Comment 5 Ben Francis [:benfrancis] 2012-01-05 04:14:49 PST
As discussed previously there are UX issues to be decided upon for this, mainly whether permissions are requested during "install" time (like Android) or at first use (e.g. like the geolocation API in Firefox)
Comment 6 Justin Lebar (not reading bugmail) 2012-01-05 05:49:36 PST
(In reply to Ben Francis from comment #5)
> As discussed previously there are UX issues to be decided upon for this,
> mainly whether permissions are requested during "install" time (like
> Android) or at first use (e.g. like the geolocation API in Firefox)

I think this is a separate issue.  I just want to track the code which stores the permissions here.  How the permissions get granted we can work out separately.
Comment 7 Chris Jones [:cjones] inactive; ni?/f?/r? if you need me 2012-01-05 11:05:28 PST
Yes.

The primary model under plan is to have a "root set" of trusted stores, configured on shipped devices by vendors.  The applications installed by those stores will be automatically granted the permissions they need.  The trusted stores are responsible for review, and there'll be an audit trail from the app to store.

The secondary model, which we'll likely use for self-hosted apps and apps from untrusted stores, is to present a UI with checkboxes (unchecked by default!) for each requested permission, to be granted by the user at a fine grain.

The first model is a higher priority, and it doesn't need UI.  The second does.
Comment 8 Justin Lebar (not reading bugmail) 2012-01-05 11:13:34 PST
On another note, I'd like for us to consider whether we want this API to have the notion of a page/origin with "root" permissions.  A page with "root" permissions is never denied permission for anything.

I'm concerned that if we don't have this, then we'll end up in basically the same place, but via a more painful road.  We'll have many separate APIs and need to give certain apps (e.g., the home screen) explicit permission to use almost all of them.  Then when we add a new API, we'll have to go through and give all these apps those same permissions again.  And when we add a new privileged page, we'll have to figure out what are the right permissions, and modify them as the page's capabilities change.

The advantage of fine-grained control over permissions is that a misbehaving page (say, hijacked via xss) can't take down the phone.  But a lot of these APIs are mission-critical anyway.  If a page can turn off the screen at will, or reboot the device, or turn the radio off, it can render the phone basically unusable.  At the point that the page can touch one of these critical APIs, there isn't a lot of point, as I see it, in further restricting what the page can do.
Comment 9 Chris Jones [:cjones] inactive; ni?/f?/r? if you need me 2012-01-05 12:02:01 PST
I think root permissions is not a good idea.  The homescreen has more touch points than most, but there's a huge set of APIs it has no business touching, like bluetooth etc.  Not just wrt malicious attacks, but bugginess etc.  As time goes on the number of touchpoints should go down, not up.  Unless you can prove to me that there's an application that needs to touch every API we will ever possibly add, r- from me ;).

POLA says that "since this app can hurt the phone's usability in one way, let's give it access to all possible ways to hurt the phone" is a bad argument.
Comment 10 Justin Lebar (not reading bugmail) 2012-01-05 12:16:55 PST
I don't think this has anything to do with the principle of least astonishment, considering how chrome JS and the Unix security models work.  That doesn't mean these are good models or the right models for B2G, but applying them here certainly doesn't surprise me.

Are you sure the homescreen doesn't need to touch bluetooth?  If we want an Android-style popover menu to appear when you hold down the power button, and we want one of those options to be airplane mode, then presumably the homescreen will need to be able to turn all the radios on and off.  (Or we're going to have to implement non-full-screen apps, so the homescreen can launch a special power-button-down dialog app.)

Or what if we want an iOS-style dialog for "open wifi network available".  Again, the homescreen is the only app which can pop over every app.

I understand that it's appealing to explicitly lay out the permissions that each app has.  But it's precisely because of surprising requirements like these that I think maintaining this list will be a pain.  The last thing I want is for someone implementing that popover to have to argue with a reviewer as for why we should allow the homescreen to access wifi rather than moving the code into a separate app, where the only motivation for using a separate app is the vague notion of restricting the permissions we hand out.

Anyway, it's a small point.  I'll be happy when we have the permissions manager, either way.
Comment 11 Chris Jones [:cjones] inactive; ni?/f?/r? if you need me 2012-01-05 12:22:37 PST
(In reply to Justin Lebar [:jlebar] from comment #10)
> I don't think this has anything to do with the principle of least
> astonishment,

Principle of least authority.

> Are you sure the homescreen doesn't need to touch bluetooth?  If we want an
> Android-style popover menu to appear when you hold down the power button,
> and we want one of those options to be airplane mode, then presumably the
> homescreen will need to be able to turn all the radios on and off.

Bluetooth can be disabled through the settings API.

> Or what if we want an iOS-style dialog for "open wifi network available". 
> Again, the homescreen is the only app which can pop over every app.
> 

Popover for wifi dialog doesn't require access to wifi APIs.

> Anyway, it's a small point.  I'll be happy when we have the permissions
> manager, either way.

Yup, that's the #1 goal.
Comment 12 Jim Straus 2012-03-15 10:27:53 PDT
Created attachment 606280 [details] [diff] [review]
Sketch of code for Permissions

This is just a sketch of code to provide permissions, and permissions ipc.  Note that it doesn't do anything yet and isn't fully hooked up.  It also needs to be attached to JS, figure out how the master Permissions Manager process gets exec'ed and used by other processes, hook it in to replace the existing permission system (geolocation, cookies, etc), etc.
Comment 13 [:fabrice] Fabrice Desré 2012-03-15 10:33:25 PDT
Jim,

Why can't this be done as an incremental improvement of the current permission manager?
Comment 14 Jim Straus 2012-03-20 08:01:51 PDT
Created attachment 607553 [details] [diff] [review]
Changes to allow for prompting for more than geolocation, change to camera to use

Extended ContentPermissionPrompt to allow for more than just geolocation check.  Specifically added information for content-camera, but it is re-organized to allow for easy addition of new permissions.  Also modified CameraContent to use the prompt, showing how other services can use the changes.
Comment 15 Chris Jones [:cjones] inactive; ni?/f?/r? if you need me 2012-03-20 11:16:44 PDT
Comment on attachment 607553 [details] [diff] [review]
Changes to allow for prompting for more than geolocation, change to camera to use

Fabrice is a much better reviewer for this.  Fabrice, if you're too overloaded lmk and I'll pick this back up.
Comment 16 Curtis Koenig [:curtisk-use curtis.koenig+bzATgmail.com]] 2012-03-28 14:32:49 PDT
assigned to me for sec action to schedule a meeting
Comment 17 Paul Theriault [:pauljt] 2012-05-01 21:43:53 PDT
*** Bug 751002 has been marked as a duplicate of this bug. ***
Comment 18 Mounir Lamouri (:mounir) 2012-05-22 11:04:02 PDT
Re-setting blocking and dependency list, assuming it was removed by mistake by Michael.
Comment 19 Jim Straus 2012-06-13 13:48:47 PDT
Created attachment 632858 [details]
WIP PermissionManager

This is a work in progress of the actual permission manager.  I'm not sure if the pattern I used for asynchronously responding to permission tests is the best, so feedback there would be appreciated.  It doesn't interface into any UI yet (so it doesn't even try to prompt), nor is it tied to the electroysization (though the interfaces are quite similar).  Mostly what this is here for is to show how the ApiTestPermission looks (asynchronously, with associated event being sent back), the tagging of permissions with app type, how the manifest permissions would be stored into the permission manager, and how the Settings would get and store changes by the user.
Note that the uri is expected to be something different for apps.  One thought is to use app://rest.of/uri and apps://rest.of/uri.  This would keep app permissions from leaking to web permissions, and would allow mapping back to http and https for locking web access to the originating domain.
Comment 20 Jonas Sicking (:sicking) 2012-06-16 18:16:12 PDT
Jim, I don't quite understand what your patch is trying to solve. It appears that you're adding a few functions to add/remove/check permissions, but we already have functions to do that on nsIPermissionManager.

You're also adding a new 'appType' argument here and there, but that won't really do much to help with the current shortcommings of the current API since we still can't key on which app we're talking about. I.e. we can't give facebook.com different access when installed as an app, compared to when browsed to using the web browser.

In general the main thing that we need to change on nsIPermissionManager is to change to from keying on nsIURIs to keying on nsIPrincipal, and then make it pull out all the relevant information from the principal.

Have you talked with Mounir who has started work on sticking the appropriate information on principals.
Comment 21 Lucas Adamski [:ladamski] 2012-06-27 07:42:39 PDT
Seems like this is the best place to note it, but we need to ensure that only permissions explicitly enumerated in the manifest can be granted.  This holds true for implicit and explicit permissions.
Comment 22 Jim Straus 2012-06-27 13:49:07 PDT
Created attachment 637242 [details] [diff] [review]
WIP PermissionManager

Here is a much more complete version, though not done yet.
The functionality that is added is to 1) mass set defaults for permissions (like whatever parses the manifest will need).  The defaults are held in the PermissionManager (and can be seen in the Init function).   This function also tests if the requesting uri is allowed to set the permissions.  2) Two other mass permissions functions to get and set are there for the Settings app.  3) ApiTest(Exact)Permission that is asynchronous.  Other changes are to validate that the permissions being requested are known, that for ApiTestPermission a permission that wasn't from the manifest is always denied.

As for distinguishing between an installed app and web content, there was discussions previously (mailing lists and work week) and it looks like somewhat covered by bug 758258 that maybe the URI for installed apps might be different.  I've inquired with Mounir but haven't gotten a response back.  Whatever is selected can be used by the new functions once we know what they are.

Also, this still needs a secure way to prompt the user to grant permissions when needed.
Comment 23 Jonas Sicking (:sicking) 2012-06-28 17:24:10 PDT
Hmm.. still not understanding all aspects of this patch, but it's looking closer.

I'd really like to keep the permission manager API simple, so I don't think we should add support for mass setting/getting permissions. That's just as easy to do as a simple loop in the app.install() implementation.

There's also the missing manifest uri etc which will determine with "data jar" to check the permission for. However Mounir is already working on that part in the "data jar" bug, so I think we should focus on the other pieces in this bug.

Specifically what would be great to do here would be to add the infrastructure which calls the permission manager, and if needed calls into the gaia front-end code to bring up a prompt and asynchronously return a yes/no decision and write that into the permission manager if the decision is a permanent one.
Comment 24 Jonas Sicking (:sicking) 2012-07-11 11:40:46 PDT
We're going through and cleaning up the dependency tree for the security model bugs for basecamp.

I'm not entirely clear on what work we're hoping to do in this bug, but since there's both discussions and patches here I don't want to close it without making sure that nothing is lost.

We currently have the following, more narrowly scoped bugs:

Bug 770731: API exposed to JS for managing app permissions. Useful for for example the settings app.

Bug 764189: Tracking the overall security model

Bug 758269: Making the install code put data into nsIPermissionManager based on information from the app manifest

Is there anything else that we should do? If so, should we perhaps file separate bugs on that that more narrowly scoped. It's always hard to follow bugs which contain a lot of general discussions like this one does.
Comment 25 Jonas Sicking (:sicking) 2012-07-20 12:01:54 PDT
I'll take the silence as agreement that we have coverage on the topics discovered here. :-)

Jokes aside, I *think* the topics discussed here has coverage in other more narrowly scoped bugs as per previous comment. However if you disagree, don't hesitate to reopen this bug, or file new bugs.

Note You need to log in before you can comment on or make changes to this bug.