docs/security/web-platform-security-guidelines.md
[TOC]
The Open Web Platform (OWP) is a fast evolving platform, with new features continuously expanding the scope of what the platform can do. It is also a particularly rich target for would-be attackers. In this context, all new features should be reviewed with particular care when it comes to their security implications. The goal of this document is to help feature teams go through the Security part of the S&P review process which ensures that their features meet the security requirements expected of a new Web Platform feature.
The guidelines in this document provide insight on how the Security teams think about the security implications of new Web Platform features. They are here to help feature teams think about security early on when designing their APIs. As new threats and new mitigations arise, we will update this document to reflect our updated recommendations.
Currently, this document is divided into three sets of guidelines: security boundaries, integration with security APIs and security UX. We have written those based on the Web Platform Security team experience of conducting security reviews, in partnership with other security teams at Google. This is based on concerns that have come up in security reviews, and a few items that we envision could be problematic.
The goal of this document is not to provide a checklist, where if every item in the list is checked a feature can be considered secure. If you find that your feature cannot meet some of the security guidelines on this list, please reach out to the Web Platform Security team earlier rather than later, and we can work together on how to support your feature’s needs in a secure manner.
Beyond the guidelines in this document, we also have [specific guidance on avoiding leaks] (https://chromium.googlesource.com/chromium/src/+/master/docs/security/stop-leaks-policy.md) that you can check. We also have a [web platform security questionnaire] (https://chromium.googlesource.com/chromium/src/+/master/docs/security/web-platform-security-questionnaire.md) to help you do a first assessment of potential security issues in your web API.
<a name="TOC-safe-api-guidelines"></a>
Prefer simple APIs.
<a name="TOC-design-with-the-web-ecosystem-in-mind"></a>
Consider how your feature will interact with the whole web ecosystem. In particular, consider the interactions with workers (ServiceWorkers, SharedWorkers, DedicatedWorkers), Fenced Frames and with the back/forward cache.
<a name="TOC-enterprise-policies"></a>
New enterprise policies are not allowed to bypass existing web security policies/protections. Enterprise policies can only be added to bypass newly introduced security restrictions, to maintain compatibility of existing enterprise web apps. Enterprise policies should only ever bypass policy decisions made by the browser, and not policies requested by websites.
<a name="TOC-security-boundaries"></a>
The security team maintains several security boundaries in the WebPlatform: origin, site, secure contexts, cross-origin isolated contexts. Before introducing a new security boundary to support your design, discuss it with the Web Platform Security team to ensure it's equally enforceable.
<a name="TOC-the-origin-boundary"></a>
The origin is the security boundary we aim to defend. We may make diverge from that (in both directions) in some cases, but those ought to be done in consultation with security folks.
The origin is the primary security boundary of the web, as per the Same-origin policy.
Note that unlike privacy, security is concerned with same-site but cross-origin interactions.
Maintaining a security boundary is complex, and might not even be possible (e.g. origins and Spectre). An API relying on a new form of security boundary should be thoroughly discussed with the Security team to check if the boundary is enforceable and the security guarantees can be met. For example, it is impossible to create an iframe that is fully isolated from its parent, due to the risk of Spectre attacks on platforms that do not support Site Isolation (low-end Android).
<a name="TOC-encryption"></a>
Prefer secure contexts for new features.
<a name="TOC-timer-resolution"></a>
Explicit timers' granularity must be limited based on a context's cross-origin isolation status. Currently, isolated contexts can support timers coarsened to at least 5 microseconds, while unisolated contexts must coarsen timers to 100 microseconds or more. If an API allows the creation of timers with a precision higher than allowed in unisolated contexts, it should be restricted to crossOriginIsolated contexts.
<a name="TOC-accessing-data-of-cross-origin-subresources"></a>
New APIs that can access data from cross-origin subresources should be gated behind an appropriate mechanism depending on their surface:
- CORS/TAO for access to a single resource.
- crossOriginIsolation for access to the agent cluster.
- crossOriginIsolation + frame opt-in mechanism for access to the whole page.
<a name="TOC-side-channels"></a>
Any new form of cross-origin communication or API should be carefully considered when it comes to side-channel attack risks.
<a name="TOC-implementation-concerns"></a>
Any new API whose implementation is particularly risky (e.g. requires new parsers, involves new codecs, requires particular isolation) should see the implementation reviewed in detail, in conjunction with the wider Chrome Security team.
<a name="TOC-user-activation"></a>
Consider requiring a feature be gated behind user activation if its UX could be abused by a document the user did not interact with.
<a name="TOC-navigation-and-document-lifetime"></a>
Any feature that impacts the lifetime of documents or that modifies navigation is likely to have far-reaching security implications. Please discuss the implications with the Web Platform Security team as soon as possible.
<a name="TOC-document-load"></a>
All changes to how a document is loaded should ensure they uphold the following security policies: XFO, CSP, COOP, COEP, and Local Network access.
<a name="TOC-subresource-load"></a>
All changes to how a resource is loaded should uphold the following security policies: CSP, COEP, CORP, CORS, CORB, SRI and Local Network access.
<a name="TOC-code-execution"></a>
New ways of executing JavaScript code should integrate with CSP script-src.
New ways of executing code should consider the cross-site scripting (XSS) risks. If any new risk is identified, the new API should integrate with CSP script-src and/or Trusted Types and/or Sanitizer.
<script> tag to avoid inadvertently creating CSP bypasses.<a name="TOC-CORS"></a>
New types of elements should require CORS when loading resources.
<a name="TOC-mime-types"></a>
New resource types should require strict MIME type matching, and avoid relying upon sniffing.
<script> tags because of
widespread mislabeling of script resources as text/html or text/plain`,
which can expose those resources to side-channel attacks like Spectre, and
more direct XSSI attacks.
CORB
mitigates some, but not all, of these risks.<a name="TOC-iframes"></a>
A document element should not be allowed to draw outside its frame.
<a name="TOC-browser-controlled-surface"></a>
Browser-controlled surfaces should not be drawn over. Converting a browser-controlled UX surface into a content-controlled surface can only be considered in specific cases and must be gated behind appropriate mechanisms.
<a name="TOC-site-identity-and-security-indicators"></a>
Communicating site identity and security indicators should only be done through browser-controlled UI.
<a name="TOC-browser-controlled-ui"></a>
Changes to browser-controlled UI or new features that will require new browser-controlled UI should go through Chrome Browser security review.
<a name="TOC-permissions"></a>
Powerful new capabilities should in most cases integrate with Permissions-Policy and only be accessible to top-level frames by default. The Permissions Team should be brought in early to consult on new permissions.
<a name="TOC-mixed-content"></a>
New features should not be able to relax or work around mixed content restrictions.
<a name="TOC-foreground-background-execution"></a>
Consider whether a new feature might be abusable or confusing to a user if a site can use it while in the background. Ensure that the user has sufficient context for something triggering and won’t be caught by surprise.