blob: 5aed42bcc67752213532b2bd08387acd99675a9b [file] [log] [blame] [view]
Camille0f2a39f2022-11-04 10:45:041# Web Platform Security guidelines
2
3[TOC]
4
5## Introduction
6The Open Web Platform (OWP) is a fast evolving platform, with new features
7continuously expanding the scope of what the platform can do. It is also a
8particularly rich target for would-be attackers. In this context, all new
9features should be reviewed with particular care when it comes to their
10security implications. The goal of this document is to help feature teams go
11through the Security part of the S&P review process which ensures that their
12features meet the security requirements expected of a new Web Platform feature.
13
14The guidelines in this document provide insight on how the Security teams think
15about the security implications of new Web Platform features. They are here to
16help feature teams think about security early on when designing their APIs. As
17new threats and new mitigations arise, we will update this document to reflect
18our updated recommendations.
19
20Currently, this document is divided into three sets of guidelines: security
21boundaries, integration with security APIs and security UX. We have written
22those based on the Web Platform Security team experience of conducting security
23reviews, in partnership with other security teams at Google. This is based on
24concerns that have come up in security reviews, and a few items that we
25envision could be problematic.
26
27The goal of this document is not to provide a checklist, where if every item in
28the list is checked a feature can be considered secure. If you find that your
29feature cannot meet some of the security guidelines on this list, please reach
30out to the Web Platform Security team earlier rather than later, and we can
31work together on how to support your feature’s needs in a secure manner.
32
33## Guidelines
34
35### General guidelines
36
37<a name="TOC-safe-api-guidelines"></a>
38#### Safe API design
39
40> Prefer simple APIs.
41
42* It is easier for developers to use higher-level and well laid out APIs. Try
43to make the easy thing the safe thing in new APIs.
44* If an API really needs potentially risky knobs, they should be well
45documented and ideally named to explicitly call out their risk (e.g., the
46subtle property in WebCrypto -- although this naming could be even more
47explicit).
48
49<a name="TOC-design-with-the-web-ecosystem-in-mind"></a>
50#### Design with the web ecosystem in mind
51
52> Consider how your feature will interact with the whole web ecosystem. In
53particular, consider the interactions with workers (ServiceWorkers,
54SharedWorkers, DedicatedWorkers), Fenced Frames and with the back/forward
55cache.
56
57* Some features might need to be restricted in workers. For example, we have
58restricted access to features like camera/microphone/geolocation because we
59have no UI surface with which to explain the implication of an API to users.
60* Fenced Frames have particular privacy requirements that might require
61disabling a feature inside them. For example, CSP EE required particular
62integration as enforcing a CSP on a Fenced Frame would provide a
63communication channel with the Fenced Frame embedder.
64* The interaction of the feature with the back/forward cache might be a
65security concern. For example, audio and video capture should only be allowed
66in pages currently shown to the users, and not in pages located in the
67back/forward cache. See also the [non-fully
68active](https://www.w3.org/TR/security-privacy-questionnaire/#non-fully-active)
69part of the W3C security and privacy questionnaire.
70
71<a name="TOC-enterprise-policies"></a>
72#### Enterprise policies
73
74> New enterprise policies are not allowed to bypass existing web security
75policies/protections. Enterprise policies can only be added to bypass newly
76introduced security restrictions, to maintain compatibility of existing
77enterprise web apps. Enterprise policies should only ever bypass policy
78decisions made by the browser, and not policies requested by websites.
79
80* When the browser introduces a new security restriction, such as gating Shared
81Array Buffers behind crossOriginIsolation, it is ok to introduce an
82enterprise policy to bypass that restriction in order to maintain
83compatibility of existing enterprise web apps.
84* It is not ok to create an enterprise policy to bypass longstanding security
85restrictions that should be supported by existing apps. For example, it would
86not be ok to introduce an enterprise policy to bypass the same-origin policy.
87* Enterprise policies should only apply to new security restrictions introduced
88to the browser. Enterprise policies should not be used to relax security
89policies requested by the website themselves. For example, it would not be ok
90to introduce an enterprise policy that bypasses CSP.
91* See the [Chrome Security
92FAQ](https://chromium.googlesource.com/chromium/src/+/master/docs/security/faq.md#Are-enterprise-admins-considered-privileged)
93for more information on enterprise policies.
94
95### Security boundaries
96
97<a name="TOC-security-boundaries"></a>
98#### Security boundaries
99
100> The security team maintains several security boundaries in the WebPlatform:
101origin, site, secure contexts, cross-origin isolated contexts. Before
102introducing a new security boundary to support your design, discuss it with
103the Web Platform Security team to ensure it's equally enforceable.
104
105* Maintaining a security boundary is complex, and might not even be possible
106(e.g. origins and Spectre). An API relying on a new form of security boundary
107should be thoroughly discussed with the Security team to check if the
108boundary is enforceable and the security guarantees can be met. For example,
109it is impossible to create an iframe that is fully isolated from its parent,
110due to the risk of Spectre attacks on platforms that do not support Site
111Isolation (low-end Android).
112
113<a name="TOC-the-origin-boundary"></a>
114#### The origin boundary
115
116> The origin is the security boundary we aim to defend. We may make diverge
117> from that (in both directions) in some cases, but those ought to be done in
118> consultation with security folks.
119
120* The origin is the primary security boundary of the web, as per the
121[Same-origin
122policy](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy).
123* Note that unlike privacy, security is
124concerned with same-site but cross-origin interactions.
125
126* Maintaining a security boundary is complex, and might not even be possible
127(e.g. origins and Spectre). An API relying on a new form of security boundary
128should be thoroughly discussed with the Security team to check if the
129boundary is enforceable and the security guarantees can be met. For example,
130it is impossible to create an iframe that is fully isolated from its parent,
131due to the risk of Spectre attacks on platforms that do not support Site
132Isolation (low-end Android).
133
134<a name="TOC-encryption"></a>
135#### Encryption
136
137> Prefer secure contexts for new features.
138
139* Any data sent over HTTP can be observed by others on the network and opens
140users to on-path attackers.
141* The same-origin policy the web security model is built upon is easily abused
142without cryptographical authentication of the servers we are talking to.
143* See the [Chrome Security
144FAQ](https://chromium.googlesource.com/chromium/src/+/main/docs/security/faq.md#why-are-some-web-platform-features-only-available-in-https-page_loads)
145for more information.
146
147<a name="TOC-timer-resolution"></a>
148#### Timer resolution
149
150> Explicit timers' granularity must be limited based on a context's
151cross-origin isolation status. Currently, isolated contexts can support
152timers coarsened to at least 5 microseconds, while unisolated contexts must
153coarsen timers to 100 microseconds or more. If an API allows the creation of
154timers with a precision higher than allowed in unisolated contexts, it should
155be restricted to crossOriginIsolated contexts.
156
157* High resolution timers open users to timing attacks such as Spectre. This is
158why their precision should be limited.
159* In crossOriginIsolated contexts, cross-origin resources are either loaded
160without credentials, or they opt into being embedded cross-origin into a
161context where they could potentially be read by their embedder. This means
162that cross-origin resources in a crossOriginIsolated context are either ok
163with a Spectre attack (opt-in model), or of no interest to an attacker
164(credentialless model). Because of this, we allow higher precision timers in
165crossOriginIsolated contexts.
166* APIs that can be used to create timers (e.g. SharedArrayBuffers) that are
167more precise than timers available in cross-origin isolated contexts should
168be gated behind crossOriginIsolation, in order to avoid introducing high
169resolution timers to the platform.
170
171<a name="TOC-accessing-data-of-cross-origin-subresources"></a>
172#### Accessing data of cross-origin subresources
173
174> New APIs that can access data from cross-origin subresources should be gated
175> behind an appropriate mechanism depending on their surface:
176> * CORS/TAO for access to a single resource.
177> * crossOriginIsolation for access to the agent cluster.
178> * crossOriginIsolation + frame opt-in mechanism for access to the whole page.
179
180* This kind of API bypasses the same-origin policy, which is the base of the
181Web security model. This is only acceptable if the cross-origin resources opt
182into sharing this data.
183* CORS or TAO are appropriate when divulging information about a single
184resource, e.g. load timings for a single resource.
185* crossOriginIsolation should be used when the API can divulge information
186about cross-origin resources located in the same agent cluster (roughly, the
187API is scoped to same-origin documents). For example, an API that measures
188the memory taken by all same-origin documents and their subresources.
189* If the API can divulge information from the resources located in the whole
190page, we will need an opt-in from documents outside the agent cluster, on top
191of crossOriginIsolation. For example, an API that streams a video of the page
192or takes a screenshot of the page. Alternatively, it might be acceptable to
193gate the API behind user interaction with a sufficiently informative UI
194element.
195
196<a name="TOC-side-channels"></a>
197#### Side channels
198
199> Any new form of cross-origin communication or API should be carefully
200> considered when it comes to side-channel attack risks.
201
202* Cross-origin communication channels and APIs can be abused to leak data from
203cross-origin resources. Any new addition should be carefully reviewed to
204assess the amount of data exposed. Note that unlike privacy, security is
205concerned with same-site but cross-origin communication and APIs.
206
207<a name="TOC-implementation-concerns"></a>
208#### Implementation concerns
209
210> Any new API whose implementation is particularly risky (e.g. requires new
211> parsers, involves new codecs, requires particular isolation) should see the
212> implementation reviewed in detail, in conjunction with the wider Chrome
213> Security team.
214
215* New parsers and codecs are particularly risky pieces of code that are exposed
216to attacker-controlled inputs. Their implementations are subjected to
217particular rules (see the [rule of
218two](https://chromium.googlesource.com/chromium/src/+/HEAD/docs/security/rule-of-2.md)),
219and they must be fuzzed.
220* Proper isolation is hard to deploy, is heavily dependent on implementation
221and might face constraints on some platforms (e.g. low-end Android devices).
222
223<a name="TOC-user-activation"></a>
224#### User activation
225
226> Consider requiring a feature be gated behind user activation if its UX could
227> be abused by a document the user did not interact with.
228
229* Several features should only be available if the user chooses to interact
230with the document. If they could be abused otherwise, consider gating them
231behind user activation. For example, fullscreen is gated behind user
232activation, as it could be used to trick the user into believing they are on
233another page by mimicking the Chrome UI.
234* This helps match the platform with the user’s mental model.
235* Features which are security sensitive will likely need aditional protection
236beyond user activation. User activation is not a security boundary, it is a
237way to protect users from abusive UX behavior from sites.
238
239<a name="TOC-navigation-and-document-lifetime"></a>
240#### Navigation and Document lifetime
241
242> Any feature that impacts the lifetime of documents or that modifies
243> navigation is likely to have far-reaching security implications. Please
244> discuss the implications with the Web Platform Security team as soon as
245> possible.
246
247* Modifying the navigation stack could cause URL spoofing attacks.
248* Modifying the navigation stack or the document lifetime could result in wrong
249origin or security policies being applied to the document.
250
251### Integration with security policies
252
253<a name="TOC-document-load"></a>
254#### Document load
255
256> All changes to how a document is loaded should ensure they uphold the following
257> security policies:
258> [XFO](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options),
259> [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP),
260> [COOP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy),
261> [COEP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy),
262> and [Private Network access](https://wicg.github.io/private-network-access/).
263
264* XFO, CSP, COEP and Private Network access can block document load. This
265should be respected.
266* COOP can trigger a browsing context group switch which should be respected as
267well.
268* CSP, COEP and Private Network access are computed when loading a document and
269may apply to all of the document resources. Failure to integrate properly
270with them could result in the policies being bypassed.
271
272<a name="TOC-subresource-load"></a>
273#### Subresource load
274
275> All changes to how a resource is loaded should uphold the following
276> security policies:
277> [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP),
278> [COEP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy),
279> [CORP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cross-Origin_Resource_Policy_(CORP)),
280> [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS),
281> [CORB](https://fetch.spec.whatwg.org/#corb),
282> [SRI](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity)
283> and [Private Network access](https://wicg.github.io/private-network-access/).
284
285* All of the policies above may block unsafe resource loads and must be
286properly applied to any subresource load.
287
288<a name="TOC-code-execution"></a>
289#### Code execution
290
291> New ways of executing JavaScript code should integrate with CSP script-src.
292
293* New ways of executing JavaScript should defend themselves against XSS attacks
294by supporting CSP.
295
296> New ways of executing code should consider the cross-site scripting (XSS)
297> risks. If any new risk is identified, the new API should integrate with CSP
298> script-src and/or Trusted Types and/or Sanitizer.
299
300* New ways of executing code should consider whether they are open to XSS
301vulnerabilities. If they are, they should defend themselves against attacks
302by supporting CSP and/or Trusted Types and/or Sanitizer.
303* For example, the [import map
304proposal](https://github.com/WICG/import-maps/issues/105) had to be spelled
305as an extension to the
306`<script>` tag to avoid inadvertently creating CSP bypasses.
307
308<a name="TOC-CORS"></a>
309#### CORS
310
311> New types of elements should require CORS when loading resources.
312
313* CORS allows an origin to control how its authenticated data is embedded in
314other origins. In an ideal world, all cross-origin authenticated requests
315would require CORS, but this is impossible for compatibility reasons.
316However, new elements should not add a new source of non CORS requests to the
317platform.
318* Elements that are allowed to make cross-origin authenticated requests without
319CORS introduce a hole in the platform that may be exploited in a MIME
320mismatch attack to bypass CORS protections for resources that are normally
321loaded through Fetch or into elements that require CORS.
322
323<a name="TOC-mime-types"></a>
324#### MIME types
325
326> New resource types should require strict MIME type matching, and avoid
327> relying upon [sniffing](https://mimesniff.spec.whatwg.org/).
328
329* Mismatches between a resource's asserted MIME type and the way it's used by
330the browser can cause security issues. For example, browsers currently
331attempt to execute practically anything via `<script>` tags because of
332widespread mislabeling of script resources as `text/html` or text/plain`,
333which can expose those resources to side-channel attacks like Spectre, and
334more direct XSSI attacks.
335[CORB](https://chromium.googlesource.com/chromium/src/+/HEAD/services/network/cross_origin_read_blocking_explainer.md)
336mitigates some, but not all, of these risks.
337* New resource types should avoid these risks entirely by specifying clear MIME
338types, and accepting only those resources that assert themselves to be of the
339proper type.
340
341### Security UX
342
343<a name="TOC-iframes"></a>
344#### Iframes
345
346> A document element should not be allowed to draw outside its frame.
347
348* A document drawing over its embedding frame allows it to perform clickjacking
349attacks and should never be allowed.
350* Drawing over the browser-controlled UX surface allows to perform all sorts of
351attacks. See the browser-controlled surface guideline below for more
352information.
353
354<a name="TOC-browser-controlled-surface"></a>
355#### Browser-controlled surface
356
357> Browser-controlled surfaces should not be drawn over. Converting a
358> browser-controlled UX surface into a content-controlled surface can only be
359> considered in specific cases and must be gated behind appropriate mechanisms.
360
361* Drawing over the omnibox allows to perform URL spoof attacks and should never
362be allowed. It can also lead to displaying incorrect SSL state information to
363the user.
364* It is possible to consider converting some of the browser-controlled surfaces
365into content-controlled surfaces in cases such as installed PWAs. This should
366still be gated behind explicit signals from the user, such as a permission
367grant or other in-context UI affordances that allow the user to toggle
368between modes.
369* Browser-controlled surfaces include the top browser chrome, but also the
370fullscreen disclosure bubble, Payment Handler dialogs, permission dialogs,
371etc.
372
373<a name="TOC-site-identity-and-security-indicators"></a>
374#### Site identity and security indicators
375
376> Communicating site identity and security indicators should only be done
377> through browser-controlled UI.
378
379* Security state and site identity are state tracked by the browser and it is
380difficult (at best) to show this information inside the content area in a
381trustworthy way. See the [Chrome Security
382FAQ](https://chromium.googlesource.com/chromium/src/+/master/docs/security/faq.md#Certificates-Connection-Indicators)
383for more details.
384* Interstitials (e.g., SSL error pages) are shown in the content area but are
385browser controlled committed navigations.
386* Other security displays overlaid on the content area (e.g., autofill
387warnings) should be handled with care and should be controlled by the
388browser.
389
390<a name="TOC-browser-controlled-ui"></a>
391#### Browser-controlled UI
392
393> Changes to browser-controlled UI or new features that will require new
394> browser-controlled UI should go through Chrome Browser security review.
395
396* Browser-controlled UI has many considerations around spoofing, abuse, etc.
397* New UI needs to be reviewed by various cross-functional groups (not just
398security).
399* This is especially true when the UI involves the user making a decision or
400the UI communicates site identity to the user in any way.
401
402<a name="TOC-permissions"></a>
403#### Permissions
404
405> Powerful new capabilities should in most cases integrate with
406> Permissions-Policy and only be accessible to top-level frames by default.
407> The Permissions Team should be brought in early to consult on new
408> permissions.
409
410* Permissions often require users to make a trust decision about a site. In
411Chrome, the only visible site identity is the top-level frame (whose origin
412is shown in the Omnibox).
413* User confusion about subframe origins was a motivation for permission
414delegation, where top-level contexts must explicitly delegate their
415permissions to subframes, allowing the user to only have to reason about
416top-level frames.
417
418<a name="TOC-mixed-content"></a>
419#### Mixed content
420
421> New features should not be able to relax or work around mixed content
422> restrictions.
423
424* Chrome now upgrades or blocks all mixed content (insecure resources or
425connections embedded in secure contexts). This greatly simplifies Chrome’s
426security state model.
427* Allowing new features to bypass these security restrictions can undermine
428other security features in Chrome which assume no mixed content (such as
429HTTPS-First Mode).
430
431<a name="TOC-foreground-background-execution"></a>
432#### Foreground/background execution
433
434> Consider whether a new feature might be abusable or confusing to a user if a
435> site can use it while in the background. Ensure that the user has sufficient
436> context for something triggering and won’t be caught by surprise.
437
438* This will often co-occur with “Browser-controlled UI” (see above), but it is
439good to think about whether an API should be restricted to foreground tabs
440only if they have a risk of being surprising to the user when used by a page.
441* For example, we restrict HTML fullscreen to foreground contexts (and display
442a disclosure UI). APIs that trigger permission prompts should only show the
443prompts when the tab is in the foreground.
444