Dominick Ng | f384207e | 2019-04-05 18:40:21 | [diff] [blame] | 1 | # Controlling Access to Powerful Web Platform Features |
| 2 | |
Felipe Andrade | 239aaf3c | 2019-09-11 12:31:58 | [diff] [blame] | 3 | _Author: [dominickn@chromium.org](mailto:dominickn@chromium.org)_ |
Dominick Ng | 0e7a62c | 2021-10-07 06:03:06 | [diff] [blame] | 4 | _Contributors: [mgiuca@chromium.org](mailto:mgiuca@chromium.org), [rorymcclelland@chromium.org](mailto:rorymcclelland@chromium.org)_ |
Dominick Ng | f384207e | 2019-04-05 18:40:21 | [diff] [blame] | 5 | |
| 6 | # Overview |
| 7 | |
| 8 | [Fugu](https://blog.chromium.org/2018/11/our-commitment-to-more-capable-web.html) |
| 9 | is a renewed effort to bring |
| 10 | [powerful new capabilities](https://bugs.chromium.org/p/chromium/issues/list?can=2&q=Proj%3DFugu+&colspec=ID+Pri+M+Stars+ReleaseBlock+Component+Status+Owner+Summary+OS+Modified&x=m&y=releaseblock&cells=ids) |
| 11 | to the web -- e.g. filesystem read/write access. Allowing users to control |
| 12 | which sites are able to access such APIs is crucial for maintaining the |
| 13 | security and privacy properties of the web. The impact of restrictions on the |
| 14 | developer ergonomics and user utility of the API and the web platform overall |
| 15 | must also be considered. |
| 16 | |
| 17 | This document explores approaches to guarding powerful APIs, e.g. using |
| 18 | [installed web app state](https://developers.google.com/web/progressive-web-apps/) |
| 19 | or some other proxy for high user |
| 20 | [engagement](https://www.chromium.org/developers/design-documents/site-engagement). |
| 21 | The following general principles summarise the overall approach of the |
| 22 | Chromium project to evaluating how powerful new features should be controlled |
| 23 | on the web: |
| 24 | |
| 25 | + __Access to powerful APIs__ should be available to the entire web platform |
| 26 | of secure contexts, with control managed exclusively by choosers, prompts, |
| 27 | or other user consent UX at time-of-use. |
| 28 | + __API-specific restrictions__ on the scope of access may also be used to |
| 29 | guard against potential abuse (e.g. constraints on available directories / |
| 30 | files, no access without a currently open foreground tab). |
| 31 | + Usage of powerful APIs should be clearly __disclosed__ to users, ideally |
| 32 | using a central hub that offers users __control__ over what sites can use |
| 33 | which capabilities. |
| 34 | + Installing a web app is associated with __persistence__, and thus |
| 35 | persistent and/or background access to powerful APIs may only be granted |
| 36 | (possibly subject to additional requirements) to installed web apps. |
| 37 | Non-installed sites may still request and be granted permission to use |
| 38 | powerful APIs, but should not have their access persisted. |
| 39 | + Installation or engagement alone __should not act as a vote of trust__ for |
| 40 | either granting access or enabling the ability to ask for access to |
| 41 | powerful APIs. |
| 42 | + Separately, efforts should be made to __curtail the existing persistency__ |
| 43 | on the web platform outside of installed web apps, e.g. time-limiting |
| 44 | permission grants, more aggressively expiring cookies, and restricting |
| 45 | background task execution. |
| 46 | |
| 47 | The remainder of this document explains the reasoning behind these principles, |
| 48 | and summarises why alternative proposals were not taken up. |
| 49 | |
| 50 | # Definition of Terms |
| 51 | |
| 52 | + [__Powerful Web Platform APIs__](https://www.chromium.org/Home/chromium-security/prefer-secure-origins-for-powerful-new-features) |
| 53 | are capabilities which carry inherent security or privacy risks when used, |
| 54 | but also provide users of web apps with significant utility. A canonical |
Austin Sullivan | 670e926 | 2021-01-26 21:56:52 | [diff] [blame] | 55 | example is local file system access (i.e. allowing web sites to directly |
Dominick Ng | f384207e | 2019-04-05 18:40:21 | [diff] [blame] | 56 | read and write from certain locations on the user's device). Many such |
| 57 | capabilities already exist on the web in every browser (e.g. access to |
| 58 | camera and microphone hardware), while new capabilities are under constant |
| 59 | development. |
| 60 | + [__Installation__](https://www.w3.org/TR/appmanifest/#installable-web-applications) |
| 61 | is the process where a web site may be elevated to run with a more native |
| 62 | UX treatment on a given platform and device. It is usually tied with being |
| 63 | granted a presence in the platform launcher (e.g. the desktop). |
| 64 | + [__Progressive Web Apps__](https://developers.google.com/web/progressive-web-apps/) |
| 65 | (PWAs) are web sites which are designed to be installable. |
| 66 | + [__Engagement__](https://www.chromium.org/developers/design-documents/site-engagement) |
| 67 | is a mechanism for measuring how much users interact with a site. Higher |
| 68 | engagement may be a signal that the user derives significant utility from |
| 69 | a site. |
| 70 | |
| 71 | |
| 72 | # Principles for Access to Powerful APIs |
| 73 | |
| 74 | This section outlines the general principles that the Chromium team believes |
| 75 | are critical when designing access to powerful new web platform APIs. These |
| 76 | principles will be considered when evaluating how new APIs are designed. |
| 77 | |
| 78 | ## Control and Transparency |
| 79 | |
| 80 | + Users must be able to see when the powerful APIs in use, and what sites |
| 81 | are using them. |
| 82 | + Users may revoke access to powerful APIs at any time, and preferably, |
| 83 | the revocation UI should be intuitive to locate based on how permission is |
| 84 | granted and/or disclosed to the user. |
| 85 | + The principle of least privilege should apply as broadly as possible: |
| 86 | users should not have to grant access to more resources than necessary to |
| 87 | achieve their goals. |
| 88 | |
| 89 | ## User Ergonomics |
| 90 | |
| 91 | + The web platform should be fully functional without requiring |
| 92 | installation. |
| 93 | + Sites must not be able to easily socially-engineer the user into |
| 94 | granting permissions they wouldn't otherwise want to. |
| 95 | + As much as is practical, users should not be bombarded with permission |
| 96 | prompts, as this leads to decision fatigue. |
| 97 | |
| 98 | ## Developer Predictability |
| 99 | |
| 100 | + Developers must be able to know when they can and cannot access |
| 101 | powerful APIs. |
| 102 | + Access mechanisms should be cross-browser compatible. |
| 103 | |
| 104 | # Proposal |
| 105 | |
| 106 | ### Baseline: secure contexts, top-level frames, user gesture |
| 107 | |
| 108 | Minimally, all new powerful APIs must only be available in |
| 109 | [secure contexts](https://www.chromium.org/Home/chromium-security/deprecating-powerful-features-on-insecure-origins). |
| 110 | Ideally, availability is restricted to top-level frames and requires a user |
| 111 | gesture to trigger. When a webpage is running in a secure context in |
| 112 | a top-level frame with an active user gesture, we call this situation |
| 113 | a __baseline context__. |
| 114 | |
| 115 | [Browser extensions](https://developer.chrome.com/extensions) are also |
| 116 | included as a baseline context, as they can already make use of web platform |
| 117 | APIs (subject to the same access checks as web sites). |
| 118 | |
| 119 | The |
| 120 | [permission delegation](https://docs.google.com/document/d/1x5QejvpyQ71LPWhMLsaM1lWCfSsBsSQ8Dap9kJ6uLv0/preview?ts=5b857603#heading=h.ib6rctasbt3y) |
| 121 | mechanism may be used to extend privileges to iframes on a page if it makes |
| 122 | sense for a powerful capability to be delegated in this way. |
| 123 | |
| 124 | ### The entire web platform may access new powerful APIs |
| 125 | |
| 126 | In general, any baseline context may access powerful APIs, regardless of its |
| 127 | windowing state (in the tabbed browser or in a standalone app window), |
| 128 | installation state (installed or not), or user engagement (highly interacted |
| 129 | with or not). This avoids the __fragmentation of the web__ into different, |
| 130 | sometimes unpredictable states, and encourages careful consideration of new |
| 131 | API surfaces such that they are exposed in a way that is safe for the web at |
| 132 | large. |
| 133 | |
| 134 | ### Session-based access is granted by direct user consent |
| 135 | |
| 136 | In general, access to powerful APIs must be mediated by direct, informed user |
| 137 | consent while the requesting site is open in a foreground tab via mechanisms |
| 138 | which may include: |
| 139 | |
| 140 | + choosers |
| 141 | + prompts |
| 142 | |
| 143 | These mechanisms must clearly disclose the origin of the request, and follow |
| 144 | Chromium's |
John Palmer | 046f987 | 2021-05-24 01:24:56 | [diff] [blame] | 145 | [guidelines on displaying URLs](https://chromium.googlesource.com/chromium/src/+/main/docs/security/url_display_guidelines/url_display_guidelines.md). |
Dominick Ng | f384207e | 2019-04-05 18:40:21 | [diff] [blame] | 146 | Implementations may be tested using tools such as |
| 147 | [Trickuri](https://github.com/chromium/trickuri). |
| 148 | |
| 149 | As much as possible, APIs should avoid a "double prompt", e.g. a permission |
| 150 | prompt requesting access to the file system, followed by a chooser to pick the |
| 151 | file/directory to access. There is little security or privacy benefit to such |
| 152 | a double prompt, and it detrimentally affects user and developer ergonomics. |
| 153 | |
| 154 | There are cases where double prompts are unavoidable, e.g. a web site may |
| 155 | request access to contact information, and if the user grants access, the |
| 156 | browser may need to request OS-level permission to service the request. |
| 157 | |
| 158 | In some cases, Chromium may implicitly grant access to an API if it is not |
| 159 | particularly dangerous or does not make sense to guard behind a permission |
| 160 | consent. An example of this is the |
| 161 | [Badging API](https://github.com/WICG/badging/blob/master/explainer.md), which |
| 162 | only works for installed web apps, and results in a subtle badging effect on |
| 163 | the installed app icon that is not invasive or privacy-sensitive. These cases |
| 164 | should be relatively rare considering the powerful APIs that are covered by |
| 165 | this document. |
| 166 | |
| 167 | The scope of access to APIs follows the web's same-origin model. |
| 168 | |
| 169 | ### Persistent and/or background access is restricted to installed apps |
| 170 | |
| 171 | The only definite capability granted by installation is __persistence__. By |
| 172 | installing, the user has explicitly indicated that they want the web app to |
| 173 | have a persistent presence on their system. |
| 174 | |
| 175 | New powerful APIs should exclusively use session-based permissions for web |
| 176 | sites that are not installed. In particular, there should be no access while |
| 177 | the site is not open in a tab, and access cannot be requested from a |
| 178 | non-foreground tab. When the site is closed or navigated away from, it loses |
| 179 | any granted access to powerful APIs it had, and must re-ask for access the |
| 180 | next time the user visits. |
| 181 | |
| 182 | Installed web sites _may_ instead receive a permanent grant, which is removed |
| 183 | when the site is uninstalled. In this way, installed web sites _may_ be |
| 184 | granted the ability to access capabilities in the background, depending on the |
| 185 | particular details of each capability. It also avoids overloading the |
| 186 | installation decision with consequences that users may not expect. |
| 187 | |
| 188 | Persistency for installed web sites may have other requirements, but |
| 189 | non-installed sites may never receive persistent grants to access powerful new |
| 190 | APIs. |
| 191 | |
| 192 | Some powerful APIs act as a proxy for persistence (e.g. a web site with |
| 193 | permission to write files to disk). We distinguish persistence via a currently |
| 194 | granted capability from __persistent access to the capability itself__; it is |
| 195 | the latter privilege which is granted by being installed. |
| 196 | |
| 197 | ### Disclose access and provide obvious user controls |
| 198 | |
| 199 | It should be obvious to users when sites are using powerful APIs, and they |
| 200 | should be given the tools needed to effectively manage and revoke access when |
| 201 | necessary. |
| 202 | |
| 203 | ### Improve permissions and installation UX to avoid decision fatigue |
| 204 | |
| 205 | Removing persistent access from the drive-by web may drive up |
| 206 | [decision fatigue](https://en.wikipedia.org/wiki/Decision_fatigue) due to |
| 207 | overprompting. However, we anticipate that many of these capabilities will |
| 208 | have relatively niche applications that the drive-by web should not commonly |
| 209 | access. |
| 210 | |
| 211 | Repeated granting of access to powerful APIs can be used as a signal for |
| 212 | installation. For instance, after two successful powerful permission grants, |
| 213 | Chromium could present the user with the option to install the app on the |
| 214 | third permission request. |
| 215 | |
| 216 | ### Administrator policies may override prompts and enforce persistence |
| 217 | |
| 218 | Powerful new capabilities may be paired with |
Felipe Andrade | 239aaf3c | 2019-09-11 12:31:58 | [diff] [blame] | 219 | [Chromium policies](https://cloud.google.com/docs/chrome-enterprise/policies) |
Dominick Ng | f384207e | 2019-04-05 18:40:21 | [diff] [blame] | 220 | which permit administrators to enforce persisted access to capabilities |
| 221 | without prompts. Capabilities may also be restricted or blocked by such |
| 222 | policies. This is in line with how many existing permissions have admin policy |
| 223 | overrides. |
| 224 | |
| 225 | ### Explore ways of curtailing the lifetime of existing persistence |
| 226 | |
| 227 | Currently, web sites which are not installed have access to significant |
| 228 | persistence mechanisms: |
| 229 | |
| 230 | + all existing permissions have their decisions persisted indefinitely |
| 231 | + cookie and local storage lifetime may be indefinite |
| 232 | |
| 233 | To better align the existing web to the proposal presented here, we suggest a |
| 234 | parallel effort to apply new lifetime limits on existing persistence |
| 235 | mechanisms. For example, some of the following measures could be explored: |
| 236 | |
| 237 | + forget any granted permissions if the site has not been visited in X weeks |
| 238 | + this could be challenging to apply for some capabilities such as push |
| 239 | notifications, where there is a use case for a site being able to send |
| 240 | informative notifications without ever needing to be opened. |
| 241 | + ignore cookie Max-Age headers for non-installed sites, and erase cookies |
| 242 | when the associated URL is no longer in browser history. |
| 243 | + restrict durable/persistent storage to installed apps. |
| 244 | + limit the storage quota available to sites unless they are installed (and |
| 245 | conversely, raise storage quota limits for installed sites). |
| 246 | + restrict what Service Workers may do in the background unless they control |
| 247 | a site that is installed. |
| 248 | |
Austin Sullivan | 670e926 | 2021-01-26 21:56:52 | [diff] [blame] | 249 | # Case Study -- File System Access |
Dominick Ng | f384207e | 2019-04-05 18:40:21 | [diff] [blame] | 250 | |
| 251 | We describe a high level case study based on the principles in this document |
| 252 | for granting a web site access to a) read any file in a certain directory; b) |
| 253 | write files to a directory. |
| 254 | |
| 255 | ## Granting access |
| 256 | |
| 257 | + The user must give direct consent via a file picker. |
| 258 | + The browser should disclose that access to the chosen file or directory |
| 259 | will be granted to the web site. |
| 260 | + A non-installed site will trigger the picker each page load that the API |
| 261 | to read or write to a directory is invoked. |
| 262 | + An installed site will have its access to reading or writing persisted. |
| 263 | |
| 264 | ## Additional considerations for writing to a directory |
| 265 | |
| 266 | + Existing Downloads UI and protections (e.g. malicious file scanning) |
| 267 | could be employed to ensure sites cannot use writing to a directory as a |
| 268 | bypass. |
| 269 | + Where such scanning isn't accessible, confirmation prompts for opening |
| 270 | dangerous files in the Downloads UI may be employed instead to ensure the |
| 271 | user knows if a potentially malicious file type is being stored. |
| 272 | + Non-installed sites may have additional restrictions on which folders |
| 273 | are available to choose (e.g. only allowing the user's Downloads directory, |
| 274 | or excluding the user's Documents directory). |
| 275 | |
| 276 | # Alternatives Considered |
| 277 | |
| 278 | ## Guard API Access Behind Installation |
| 279 | |
| 280 | Apps on any desktop or mobile platform require installation to run, and when |
| 281 | installed, apps are automatically granted many privileges. We could extend |
Austin Sullivan | 670e926 | 2021-01-26 21:56:52 | [diff] [blame] | 282 | this concept to the web by restricting powerful APIs like the File System |
| 283 | Access API only to installed web apps. That is, the drive-by web could not even |
Dominick Ng | f384207e | 2019-04-05 18:40:21 | [diff] [blame] | 284 | ask for permission to access an API -- the site would need to be installed. |
| 285 | |
| 286 | A key argument for using installation in this manner is that some APIs are |
| 287 | simply so powerful that the drive-by web should not be able to ask for them. |
| 288 | However, this document takes the position that installation alone as a |
| 289 | restriction is undesirable. |
| 290 | |
| 291 | ### Pros: |
| 292 | |
| 293 | + This is a simple model that is both user controllable and |
| 294 | developer-accessible (via installation APIs such as |
| 295 | [beforeinstallpromptevent](https://developers.google.com/web/fundamentals/app-install-banners/)). |
| 296 | + Installation is already synonymous with some amount of elevated privilege |
| 297 | on most platforms. |
| 298 | |
| 299 | ### Cons: |
| 300 | |
| 301 | + Fragments the web platform into installed and not installed, with |
| 302 | different APIs available depending on installed state. |
| 303 | + Disempowers the drive-by web, and undermines the "try-before-you-buy" |
| 304 | ability that the web affords today. Users may also not be willing to |
| 305 | install a site from which they cannot ascertain any benefit. |
| 306 | + Forces users to install a site to use it, even if they don't want to |
| 307 | install. |
| 308 | + May encourage web sites to prompt users on every visit to install the PWA |
| 309 | to get access to powerful features. |
| 310 | + Creates confusing scenarios when web apps are running in tabs: |
| 311 | + If a web app is installed but the user opens the site in a |
| 312 | tab, does it get access to the capability or not? |
| 313 | + What about if the web app starts off in a standalone window, but |
| 314 | the user reparents it into a tab? Or if a user sets an installed app to |
| 315 | open in a tab? |
| 316 | + Platforms where installation grants privilege all incur additional |
| 317 | friction during installation that the web currently does not exhibit. |
| 318 | Examples include: |
| 319 | + requiring something to be downloaded, |
| 320 | + requiring a confirmation prompt, installer, or some explicit |
| 321 | privilege or grant during installation, |
| 322 | + requiring an explicit display of permissions that are implicitly |
| 323 | granted. |
| 324 | + The implicit granting of privilege by installation has proven to be a |
| 325 | security and privacy challenge on many platforms, e.g. Android native apps |
| 326 | can access many |
| 327 | [powerful features](https://developer.android.com/guide/topics/permissions/overview#normal-dangerous) |
| 328 | with no permission prompt and without user recourse to revoke access. |
| 329 | + The amount of friction generated by PWA installation over the drive-by |
| 330 | web is unclear, and gating APIs behind installation increases the |
| 331 | incentive for tricking users into installing. |
| 332 | |
| 333 | ### Security considerations: |
| 334 | |
| 335 | Restricting APIs to installed web apps is not a meaningful security improvement |
| 336 | for users for several reasons: |
| 337 | |
| 338 | + While it eliminates the drive-by web as an attack surface, per-API |
| 339 | security mitigations (e.g. restricting which directories are accessible |
| 340 | for reading and writing) would still be necessary to protect users of |
| 341 | installed web apps. |
| 342 | + The effectiveness of installation as a gate on access to powerful APIs |
| 343 | weakens as the installed web app model becomes more successful. |
| 344 | + Developers are incentivised to ask for installation to utilise powerful |
| 345 | capabilities, contributing to the erosion of installation as an effective |
| 346 | security mitigation. |
| 347 | + Per-API permission requests would still be necessary in the installed |
| 348 | state, making installation effectively equivalent to an implicit permission |
| 349 | grant to ask for permission to access powerful features. We should simply |
| 350 | ask users directly if they wish to grant permission, rather than use such a |
| 351 | two-tiered requirement. |
| 352 | |
| 353 | ## Guard API Access Behind Engagement |
| 354 | |
| 355 | This is a more general concept than installation: that continual, significant |
| 356 | usage of a web site should allow that site to access more powerful APIs. |
| 357 | |
| 358 | ### Pros: |
| 359 | |
| 360 | + Continual usage of a web site can be taken as a signal of trust |
| 361 | |
| 362 | ### Cons: |
| 363 | |
| 364 | + Engagement is not standardised or exposed to the web platform, making |
| 365 | it a highly unpredictable and unergonomic mechanism of controlling access. |
| 366 | + Standardisation and a web-exposed API would both be requirements for |
| 367 | using engagement in this way. Chromium's current engagement |
| 368 | implementation is local-only and not web-exposed. There are serious |
| 369 | privacy questions about exposing such data to the web. |
| 370 | + Solving the first-run problem is non-trivial: engagement requires usage |
| 371 | to accumulate, but there are apps which legitimately require access to a |
| 372 | powerful API immediately to function (e.g. an editor -> files, or a |
| 373 | weather site -> location). |
| 374 | |
| 375 | ### Security considerations: |
| 376 | |
| 377 | + There is no real evidence to support the implicit assumption under |
| 378 | this model that continual usage of a web site correlates with user consent |
| 379 | to access powerful features. |
| 380 | + Consider users who frequently use some web site for which location |
| 381 | data is useful, but denies that site persistent, background access to |
| 382 | geolocation permission. |
| 383 | + A proportion of web traffic goes to sites which users may interact |
| 384 | with frequently, but may not necessarily want to grant powerful |
| 385 | capabilities. |
| 386 | |
| 387 | Similar to installation, the Chromium team does not regard engagement as a |
| 388 | robust way of controlling access to APIs. |