Joey (NostrComments) on Nostr: If your browser extension draws its UI inside the page, check this one. I had it ...
If your browser extension draws its UI inside the page, check this one. I had it wrong for months.
My comment panel lives in an open shadow root in the page, so any script on the page can reach every control in it. I guarded the ones that matter — granting consent, adding a relay — by checking the event's isTrusted, which only the browser can set. That felt like enough.
It is not, and I only found out because I tried to break it myself instead of assuming.
A page can skip the event entirely: take the element, call its onclick directly, and hand it an object it made up. isTrusted is just a property on that object. It can also act while a real click of yours is being delivered elsewhere in the panel, which is long enough for a naive "was that trusted" flag to still be true.
Against my own build that meant a page could open settings, press "Show private key" and read the nsec straight out of the field. And separately, type a comment and post it under my key. Without me clicking anything.
What works instead is to never trust what the caller passed. A capture listener on the shadow root records which element a real gesture is activating, in a closure the page cannot reach, and each sensitive handler asks only whether that element is itself. Dispatching an event sets nothing. Calling a handler sends no event at all. Piggybacking on a real click leaves some other element as the target.
It is still a mitigation and not a boundary, and I would rather say so: the panel is in the page's DOM, so a page can read the thread, read what I am typing, and read a key I choose to display while I am on it. Moving those controls onto the extension's own surface is the actual fix, and that is the next thing I build.
Fixed in 23.3.1 — out on Firefox, in review at Chrome.
Published at
2026-09-18 10:07:32 UTCEvent JSON
{
"id": "3c05f0ba0209ba80eef318ea0ae5133f2d79ac7d73bd91b0b7d2646818af5790",
"pubkey": "cb8db3a901199d6b94029f784c934c71b4a36561870d108e7b6b6c4cb3b0ead1",
"created_at": 1789726052,
"kind": 1,
"tags": [],
"content": "If your browser extension draws its UI inside the page, check this one. I had it wrong for months.\n\nMy comment panel lives in an open shadow root in the page, so any script on the page can reach every control in it. I guarded the ones that matter — granting consent, adding a relay — by checking the event's isTrusted, which only the browser can set. That felt like enough.\n\nIt is not, and I only found out because I tried to break it myself instead of assuming.\n\nA page can skip the event entirely: take the element, call its onclick directly, and hand it an object it made up. isTrusted is just a property on that object. It can also act while a real click of yours is being delivered elsewhere in the panel, which is long enough for a naive \"was that trusted\" flag to still be true.\n\nAgainst my own build that meant a page could open settings, press \"Show private key\" and read the nsec straight out of the field. And separately, type a comment and post it under my key. Without me clicking anything.\n\nWhat works instead is to never trust what the caller passed. A capture listener on the shadow root records which element a real gesture is activating, in a closure the page cannot reach, and each sensitive handler asks only whether that element is itself. Dispatching an event sets nothing. Calling a handler sends no event at all. Piggybacking on a real click leaves some other element as the target.\n\nIt is still a mitigation and not a boundary, and I would rather say so: the panel is in the page's DOM, so a page can read the thread, read what I am typing, and read a key I choose to display while I am on it. Moving those controls onto the extension's own surface is the actual fix, and that is the next thing I build.\n\nFixed in 23.3.1 — out on Firefox, in review at Chrome.",
"sig": "b53c30c0b3f3681d3d8b0d2aff732aedf284ca69e7f4b7a98fe850a04f759b369b9c8f7a6628c5a970ee77071f763e77343e30ec75f6523e096b657b6e926581"
}