Secure Context

May 20, 2023

A Secure Context is a web context that provides a secure environment for running web content. Web content running inside a Secure Context is protected from a range of security threats, including cross-site scripting attacks and malicious code injection.

A web context is a security boundary in the web browser that separates different websites from each other. A Secure Context is a web context that meets a set of security requirements that have been established by the browser vendor. These security requirements help to ensure that web content running inside a Secure Context is protected from a range of security threats.

Security Requirements for a Secure Context

A web context must meet the following security requirements to be considered a Secure Context:

  • Origin Isolation: The web context must have an isolated security origin. This means that resources from different origins cannot access each other’s data without permission.
  • TLS/SSL Encryption: The web context must use HTTPS or another secure protocol to transport data between the server and the client. This ensures that data is encrypted in transit and cannot be intercepted by attackers.
  • Permission Policies: The web context must have a set of permission policies that control what resources can be accessed by web content running inside the context. These policies help to prevent malicious code from accessing sensitive resources, such as the user’s camera or microphone.
  • The Secure Context API: The web context must support the Secure Context API, which provides a set of JavaScript functions that can be used to determine whether a given context is a Secure Context.

Benefits of a Secure Context

There are a number of benefits to running web content inside a Secure Context:

  • Improved Security: Web content running inside a Secure Context is protected from a range of security threats, including cross-site scripting attacks and malicious code injection. This helps to ensure that users are protected from attackers who may try to steal sensitive information or compromise their devices.
  • Better Performance: Web content running inside a Secure Context can take advantage of new web features that are only available in secure contexts. These features can improve performance and provide a better user experience.
  • Improved Privacy: Web content running inside a Secure Context is protected from tracking by third-party scripts and cookies. This helps to ensure that users can browse the web without being tracked by advertisers or other third-party entities.

Examples of Secure Contexts

Some examples of web contexts that meet the security requirements for a Secure Context include:

  • HTTPS Websites: Websites that use HTTPS to encrypt data transport and have an isolated security origin meet the security requirements for a Secure Context.
  • Web Extensions: Web extensions running inside a browser meet the security requirements for a Secure Context.
  • Web Workers: Web workers running inside a browser meet the security requirements for a Secure Context.

Limitations of Secure Contexts

While Secure Contexts provide a secure environment for running web content, there are some limitations to their effectiveness:

  • Insecure Origins: Web content running on an insecure origin (e.g. HTTP) is not protected by the security features of a Secure Context. This means that attackers may be able to compromise the user’s device or steal sensitive information if they are able to inject malicious code into the web content.
  • Policy Violations: Web content running inside a Secure Context can still violate the permission policies established by the browser vendor. This can lead to security vulnerabilities that may be exploited by attackers.
  • Browser Bugs: Secure Contexts rely on the browser to enforce security policies and provide a secure environment for web content. If there are bugs in the browser’s implementation of Secure Contexts, attackers may be able to bypass the security protections provided by the context.