Firefox iOS Security Token Hijack By Overriding window.webkit
Firefox for iOS passed a security token through a JavaScript object that any web page could replace, so a malicious page could intercept the token. An attacker could then read the token and use it to send messages to the app's native handlers.
Originally disclosed on Mozilla
- Fixed in 5 days
- Paid in 46 days
- Disclosed after 5 days
Created attachment 9142622
firefox-reader.html
Firefox Version: v24.1
OS: iOS 13.3.1
Issue: Firefox iOS Security Token Hijack By Overriding window.webkit
Description:
Firefox iOS uses window.webkit.messageHandlers to communicate between WKWebView and ViewController and this communication is now protected by SECUIRTY_TOKEN(UUID).
But in WKWebView A web page can override |window.webkit| with any value(overriding). The below code would get the SECURITY_TOKEN to attacker controlled page when user visit's attacker's site.
'''
<script type="text/javascript">
function getToken(msg) {
alert(msg.securityToken);
originalWebkit.messageHandlers.readerModeMessageHandler.postMessage(msg);
}
originalWebkit = webkit;
webkit = {};
webkit.messageHandlers = {};
webkit.messageHandlers.readerModeMessageHandler = {};
webkit.messageHandlers.readerModeMessageHandler.postMessage = getToken;
</script>
'''
POC:
* Open https://vinothkumar.tech/firefox-reader your iOS firefox browser.
* Alert popup trigered with SECURITY_TOKEN
Root Cause:
A web page can override |window.webkit| with any value.
Fix:
Deleting the object ensures that original and working implementation of window.webkit is restored.
'''
var oldWebkit = window.webkit;
delete window['webkit'];
window.webkit.messageHandlers[handlerName].postMessage(message);
window.webkit = oldWebkit;
'''
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
An attacker-controlled page could obtain the security token and then post messages to the app's native message handlers.
What the attacker needed
Victim visits attacker's site; Firefox for iOS v24.1
The fix
The app should delete the overridden object before posting so the original window.webkit is restored, as the report's suggested code does.
How it was found
- Open the attacker's page in Firefox for iOS.
- The page replaces window.webkit with its own object.
- The app sends the security token to the fake handler.
- An alert shows the stolen token.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Firefox on iPhone uses a hidden bridge to talk to the phone's native code, and it protects that bridge with a secret token. The page's JavaScript can swap out the bridge object with its own version, so the secret token gets handed to the attacker's code instead. With that token, the attacker can pretend to be the app and send messages to native features.
What is Mobile?
Flaws specific to Android and iOS apps: exported components, deep links, WebViews and data left on the device.