July 8th, 2024

Universal Code Execution by Chaining Messages in Browser Extensions

Researchers demonstrate universal code execution in browser extensions by exploiting messaging APIs, bypassing security measures. Vulnerabilities in extensions can compromise millions of users, allowing access to sensitive data and enabling arbitrary command execution.

Read original articleLink Icon
Universal Code Execution by Chaining Messages in Browser Extensions

Universal code execution through chaining messages in browser extensions is demonstrated, bypassing Same Origin Policy and browser sandbox restrictions. Vulnerabilities in messaging APIs allow for the exploitation of extensions, potentially affecting millions of users. By leveraging content scripts and background scripts, malicious web pages can breach security boundaries and access sensitive information like cookies. The use of postMessage and sendMessage methods can lead to code execution, especially when combined with native messaging capabilities. The process involves passing messages from the extension to native applications, enabling attackers to execute arbitrary commands. Vulnerability hunting at scale is facilitated by querying Chrome extensions for specific patterns and scanning for insecure message handling. Additionally, the integration of PKI smart cards through browser extensions poses a significant risk, as demonstrated by a specific extension with a large user base. The extension's design flaw allows for the execution of arbitrary code, potentially leading to severe security breaches.

Link Icon 4 comments
By @modeless - 4 months
The idea of searching a database of extension manifests to find exploitation targets is pretty interesting. I am curious about this though:

> by first triggering a download of a malicious DLL file followed by sending a message with the GetCertLib action and PKCS11Lib pointing to the download location

I see two problems here. The download location contains the username of the current user which is unknown, right? Also, I thought Windows blocked loading of downloaded DLLs the same way as it blocks running of downloaded executables until you click through the warning dialog box. I don't see how this would work in practice.

Extension security is definitely concerning, and it is definitely true that the recommended ways for extensions to communicate with content are error-prone. But I think Manifest v3's security precautions like the restrictive CSP help a lot.

By @Andrews54757 - 4 months
Requirements as listed by the article:

1. Browser extension has a wildcard pattern for content script.

2. Content script passes postMessage messages to the background script using sendMessage.

3. Background script passes the message to native application using sendNativeMessage.

4. Native application handles the message dangerously, leading to code execution.

Requirement 2 seems to be the most important. postMessage messages should never be passed to sendMessage raw without validation. Fortunately, this should be a rare occurrence in the wild. It only provides very specific benefits to use postMessage in an extension to begin with, and developers who do need to use it are more likely to be aware of the potential vulnerability.

By @hajimuz - 4 months
Background script permission and universal url access permission, I doubt you can pass web store validation with these two.
By @pizzalife - 4 months
Very nice research.