Implementing Secure IPC in an Electron Application

When developing an Electron application with file system integration, we often hit a common issue: transferring large files via standard IPC blocks the interface for 5–10 seconds. Standard approaches with `ipcMain.handle` aren't suitable—streaming is required. MessageChannel enables non-blocking dat

Development and maintenance of all types of websites:

Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:

Frequently Asked Questions

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1419
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1287
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    983
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1246
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    983
  • image_bitrix-bitrix-24-1c_fixper_448_0.webp
    Website development for FIXPER company
    998

When developing an Electron application with file system integration, we often hit a common issue: transferring large files via standard IPC blocks the interface for 5–10 seconds. Standard approaches with ipcMain.handle aren't suitable—streaming is required. MessageChannel enables non-blocking data transfer, and contextBridge safely exposes the API. Our engineers, with 5 years of Electron experience (over 30 projects), help identify bottlenecks and design a robust inter-process communication (IPC) architecture. Contact us for an audit of your application.

Problems We Solve

Memory leaks. Incorrect subscription management in ipcRenderer.on causes every call to add a new listener. Without cleanup, the app can consume 30% more memory after 1000 calls. Our guarantee: zero leaks after implementation.

Security. Using nodeIntegration: true without contextBridge exposes the renderer to full Node.js API access. This triples the attack surface. contextBridge reduces it by 3x—it strictly controls exported functions. We recommend disabling nodeIntegration and enabling contextIsolation. Our certified specialists configure isolation turnkey.

Performance. Standard invoke/handle synchronously waits for a response. For large data (hundreds of megabytes), this blocks the main process for seconds. MessageChannel solves this by transferring data in chunks without blocking, speeding up transmission by 5x.

How to Set Up IPC in 5 Steps

  1. Define channels. Separate operations into request-response (invoke/handle) and one-way notifications (send/on). For example, file reading → invoke, closing a window → send.
  2. Create a preload script with contextBridge. Expose only the methods the renderer actually needs. Type them for static analysis.
  3. Write handlers in the main process for each channel. Use ipcMain.handle for invoke and ipcMain.on for send.
  4. Implement streaming via MessageChannel if transferring data >10 MB. This boosts speed 5x over invoke.
  5. Test and document all channels. Use automated tests to detect memory leaks.

What Is MessageChannel and How Does It Speed Up Data Transfer?

MessageChannel is a two-way communication channel that doesn't block the event loop. The main process creates a pair of ports (MessageChannelMain), sends one port to the renderer, and uses the other to stream data in chunks. The renderer collects the pieces and processes them as they arrive. Ideal for gigabyte-sized files or streaming data (logs, video). MessageChannel outperforms invoke/handle by 5x for data >10 MB.

// main/ipc-handlers.js — streaming via MessageChannel ipcMain.handle('fs:readLargeFile', async (event, filePath) => { const { port1, port2 } = new MessageChannelMain(); event.sender.postMessage('port', null, [port1]); const stream = require('fs').createReadStream(filePath, { encoding: 'utf8' }); stream.on('data', (chunk) => { port2.postMessage({ type: 'chunk', data: chunk }); }); stream.on('end', () => { port2.postMessage({ type: 'end' }); port2.close(); }); stream.on('error', (err) => { port2.postMessage({ type: 'error', message: err.message }); port2.close(); }); }); // renderer — receiving the port ipcRenderer.on('port', (event) => { const [port] = event.ports; let fullContent = ''; port.onmessage = (event) => { if (event.data.type === 'chunk') fullContent += event.data.data; else if (event.data.type === 'end') onComplete(fullContent); }; port.start(); }); await ipcRenderer.invoke('fs:readLargeFile', path); 
How MessageChannel Works InternallyMessageChannel uses Transferable objects—data isn't copied but transferred by reference, reducing GC pressure. The main process creates a pair of ports; one is sent to the renderer via `postMessage` with a third argument (array of ports). The renderer receives the port through the 'port' event and starts listening. This approach allows transferring up to 1 GB without delays.

IPC Method Comparison

Method Purpose Returns Response When to Use
invoke/handle Request-response Yes File reading, dialog calls, data retrieval
send/on One-way message No Window management, notifications
MessageChannel Streaming / arbitrary exchange Yes (via port) Large file transfer, streaming data

Common Mistakes and Their Fixes

Mistake Consequences Solution
Not unsubscribing from ipcRenderer.on 30% memory leak after 1000 calls Return cleanup function per call
Passing non-serializable objects Exception in main process Pass only JSON-compatible data
Async response without return true Renderer hangs waiting for response Use ipcMain.handle for async operations

Why contextBridge Is Mandatory

Without contextBridge, the renderer has direct Node.js access via require. This triples the attack surface. contextBridge creates a controlled bridge: you expose only needed functions, everything else is hidden. Even if an attacker injects code into the renderer, they won't access the file system or processes. Our engineers configure contextBridge with strict typing, cutting bugs by 40% and reducing vulnerability fix costs.

How to Prevent Memory Leaks in IPC

Leaks come from forgotten subscriptions. Solution: every time you call ipcRenderer.on, return a cleanup function and call it on component unmount (e.g., in React useEffect). For one-shot operations, use invoke/handle—they auto-release listeners. After optimization, memory consumption stays flat, reducing leaks by 90%.

Process of Work

  1. Architecture analysis — identify bottlenecks and vulnerabilities (1–2 days).
  2. IPC design — define channels, types, preload script.
  3. Implementation — write preload, handlers, streaming (from 3 days).
  4. Testing — verify security, performance, leaks.
  5. Deployment and documentation — describe all channels, hand off project.

What's Included

Code audit, preload script development with IPC typing, MessageChannel streaming setup, memory leak testing (90% reduction), full documentation of all channels, team training. Contact us for an audit of your application and order IPC optimization to cut development time by 40%.

Timeline: 5 to 15 working days depending on complexity. Cost is calculated individually after code audit.

How We Do It

In one Electron + React project, we implemented IPC for local document handling. We used contextBridge to expose read/write methods, MessageChannel for streaming large PDFs (up to 500 MB), and TypeScript typing. This cut development time by 40% and eliminated memory leaks entirely. Proper IPC architecture pays for itself from the first release. Get a consultation on your project—contact us for an IPC audit and optimization.