Good checklist. The single ipcMain handler that switches on a string and trusts the payload is exactly what we once found during a production security audit, and the fix was the same allowlist approach you describe here. The sender frame validation point is the one I would underline twice. Most teams treat contextIsolation as the security itself instead of just the structure it provides.
Exactly — a single dispatcher that switches on a channel string and trusts whatever the renderer sends is the pattern that shows up again in audits, and the allowlist-per-channel fix is the right direction rather than trying to harden one big handler. I'd second the sender-frame check: validating event.senderFrame.url (and its origin) against the expected set before touching any privileged handler closes the case where a compromised renderer or injected script calls a legitimate channel. And you're correct that contextIsolation is only the structural separation — the actual boundary still comes from payload validation, restricted CSP, and default-deny permissions; isolation alone doesn't make a channel safe.
Agreed on all of it. The sender-frame check is the part most teams skip, and once you validate the frame URL and origin before the handler runs, a compromised renderer can't just call a legitimate channel and get through. And yes, contextIsolation is just the structure, the real boundary is the payload validation, the CSP, and the default-deny permissions around it. The allowlist per channel is the right call too, much easier to reason about than one big handler.
Agreed, and the sender-frame check is where most of the real risk sits. Two additions from debugging this in production.
First, validate on the event object in the main process and never trust what the renderer claims about itself. The sending frame URL and origin are the only values a compromised renderer cannot forge, so the check belongs inside each channel handler, or in a wrapper that refuses to register the channel unless the check is present. That is what makes default-deny actually hold.
Second, keep a schema per channel, not just an allowlist of names. Mapping channel to validator function makes the payload contract explicit and testable, and it makes adding a channel show up in review as a security change instead of a handler tweak.
One thing I would add on top: log rejections with the channel name and the frame that tried. That log is how you tell whether your CSP is doing the work or whether a compromised renderer is probing a channel nobody validated.
Thanks, this is a really useful addition. The wrapper idea stands out to me, because it turns the sender check from something each handler has to remember into something the channel cannot exist without. Same with the per-channel schema, it makes the payload contract visible in review instead of hidden inside a handler. And logging rejections is a good call, that log is the fastest way to tell whether a probe is happening or the policy is just quiet. Appreciate you sharing what you learned from production.
The part that surprised me in production was how much the log format mattered. We write one line per rejection with the channel name, the schema version, and a truncated hash of the payload instead of the payload itself. That keeps device identifiers out of the log and keeps volume manageable when a misconfigured build starts talking. We alert on rejection rate per channel against a 7-day baseline, which separates a probe (one channel, odd hours, payloads that never validate) from config drift (all channels, right after a deploy). The wrapper also let us delete the per-handler sender checks, which was the point: fewer places to forget them.
We're a place where coders share, stay up-to-date and grow their careers.
Good checklist. The single ipcMain handler that switches on a string and trusts the payload is exactly what we once found during a production security audit, and the fix was the same allowlist approach you describe here. The sender frame validation point is the one I would underline twice. Most teams treat contextIsolation as the security itself instead of just the structure it provides.
Exactly — a single dispatcher that switches on a channel string and trusts whatever the renderer sends is the pattern that shows up again in audits, and the allowlist-per-channel fix is the right direction rather than trying to harden one big handler. I'd second the sender-frame check: validating
event.senderFrame.url(and its origin) against the expected set before touching any privileged handler closes the case where a compromised renderer or injected script calls a legitimate channel. And you're correct thatcontextIsolationis only the structural separation — the actual boundary still comes from payload validation, restricted CSP, and default-deny permissions; isolation alone doesn't make a channel safe.Agreed on all of it. The sender-frame check is the part most teams skip, and once you validate the frame URL and origin before the handler runs, a compromised renderer can't just call a legitimate channel and get through. And yes, contextIsolation is just the structure, the real boundary is the payload validation, the CSP, and the default-deny permissions around it. The allowlist per channel is the right call too, much easier to reason about than one big handler.
Agreed, and the sender-frame check is where most of the real risk sits. Two additions from debugging this in production.
First, validate on the event object in the main process and never trust what the renderer claims about itself. The sending frame URL and origin are the only values a compromised renderer cannot forge, so the check belongs inside each channel handler, or in a wrapper that refuses to register the channel unless the check is present. That is what makes default-deny actually hold.
Second, keep a schema per channel, not just an allowlist of names. Mapping channel to validator function makes the payload contract explicit and testable, and it makes adding a channel show up in review as a security change instead of a handler tweak.
One thing I would add on top: log rejections with the channel name and the frame that tried. That log is how you tell whether your CSP is doing the work or whether a compromised renderer is probing a channel nobody validated.
Thanks, this is a really useful addition. The wrapper idea stands out to me, because it turns the sender check from something each handler has to remember into something the channel cannot exist without. Same with the per-channel schema, it makes the payload contract visible in review instead of hidden inside a handler. And logging rejections is a good call, that log is the fastest way to tell whether a probe is happening or the policy is just quiet. Appreciate you sharing what you learned from production.
The part that surprised me in production was how much the log format mattered. We write one line per rejection with the channel name, the schema version, and a truncated hash of the payload instead of the payload itself. That keeps device identifiers out of the log and keeps volume manageable when a misconfigured build starts talking. We alert on rejection rate per channel against a 7-day baseline, which separates a probe (one channel, odd hours, payloads that never validate) from config drift (all channels, right after a deploy). The wrapper also let us delete the per-handler sender checks, which was the point: fewer places to forget them.