Context isolation bypass via nested unserializable return value
Electron's contextBridge could leak privileged access when an exposed API returned an unserializable object or a value whose getter threw an exception. Code in the main world could then reach into the isolated context and perform privileged actions.
Originally disclosed on HackerOne
- Triaged in 21 hours
- Fixed in 27 hours
- Paid in 27 hours
- Disclosed after 31 days
Summary by the program
###Context isolation bypass via nested unserializable return value
Impact Apps using contextIsolation and contextBridge are affected.
This is a context isolation bypass, meaning that code running in the main world context in the renderer can reach into the isolated Electron context and perform privileged actions.
Workarounds This issue is exploitable under either of two conditions:
If an API exposed to the main world via contextBridge can return an object or array that contains a JS object which cannot be serialized, for instance, a canvas rendering context. This would normally result in an exception being thrown Error: object could not be cloned. If an API exposed to the main world via contextBridge has a return value that throws a user-generated exception while being sent over the bridge, for instance a dynamic getter property on an object that throws an error when being computed. The app side workaround is to ensure that such a case is not possible. Ensure all values returned from a function exposed over the context bridge are supported and that any objects returned from functions do not have dynamic getters that can throw exceptions.
Auditing your exposed API is likely to be quite difficult so we strongly recommend you update to a patched version of Electron.
Fixed Versions 25.0.0-alpha.2 24.0.1 23.2.3 22.3.6
The report
This issue is exploitable under either of two conditions:
- If an API exposed to the main world via contextBridge can return an object or array that contains a JS object which cannot be serialized, for instance, a canvas rendering context. This would normally result in an exception being thrown
Error: object could not be cloned. - If an API exposed to the main world via contextBridge has a return value that throws a user-generated exception while being sent over the bridge, for instance a dynamic getter property on an object that throws an error when being computed.
In both of these cases the context that receives the exception may be able to (via the exception) obtain privileged access to the context on the other side of the bridge.
Impact
This is a context isolation bypass, meaning that code running in the main world context in the renderer can reach into the isolated Electron context and perform privileged actions.
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
Root cause
Likely the contextBridge serialisation path did not safely handle unserializable return values or exceptions thrown by getters, allowing the exception object to carry a reference across the isolation boundary.
Impact
Code in the main world could bypass context isolation and perform privileged actions, though only when an exposed API returns an unserializable object or a value whose getter throws.
What the attacker needed
App uses contextIsolation and contextBridge; exposed API returns unserializable object or throwing getter
The fix
It was fixed in Electron 25.0.0-alpha.2, 24.0.1, 23.2.3 and 22.3.6; as a workaround, ensure bridged functions only return supported values without throwing dynamic getters.
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.
Electron apps often run untrusted web code in one part of the app and keep privileged code in a separate, isolated part. A bridge lets the web code call specific privileged functions. This bug meant that if such a function returned something the bridge could not copy, or threw an error while being copied, the web code could use that error to break out of its sandbox and act with the privileged side's powers.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.