IPC security and Microsoft Graph APIs
This system protects the boundary between the Teams web page and the Electron main process while exposing a small set of Microsoft Graph actions to the application. IPC requests pass through an allowlist and payload checks before they reach privileged handlers. Graph handlers then use the signed-in Teams session to read or change user data without sending the access token to the renderer.
System role
The IPC and Graph layers connect application features to privileged desktop and web services. IPC carries requests across the renderer–main boundary. The Graph layer turns selected requests into Microsoft Graph calls and returns safe result objects to application features.
The main process installs IPC protection during startup. Graph handlers are registered after the main window is ready, and they remain inactive when the graphApi.enabled setting is off. This makes the security layer a gate for all renderer requests and the Graph setting a second gate for Graph access. See Platform services for the wider service lifecycle.
IPC boundary
Channel allowlist
The channel allowlist defines which named IPC routes are part of the product contract. A request on any other route is rejected before its handler runs. This applies to both request/response calls and one-way events, so a renderer cannot create a new main-process entry point by choosing an arbitrary channel (app/…/ipcValidator.js• L8-170, app/…/ipcSecurity.js• L87-119).
The allowlist also records channels used for main-to-renderer messages. Those entries document the complete channel vocabulary even though the validator wraps renderer-to-main registration methods. New routes must therefore be treated as security-sensitive API changes rather than as local event names.
References: app/…/ipcValidator.js• L8-170 app/…/ipcSecurity.js• L87-119
Payload sanitization
Allowed channels do not make payloads trusted. Before a handler receives the first payload value, the validator removes prototype-pollution properties from nested objects and stops at a bounded depth. Primitive and missing payloads remain valid when the channel itself is valid (app/…/ipcValidator.js• L172-214).
This check reduces risk from renderer-controlled object data. Individual handlers still own checks that are specific to their operation, such as the required user ID and non-empty message text for chat sending (app/…/ipcHandlers.js• L79-94).
References: app/…/ipcValidator.js• L172-214 app/…/ipcHandlers.js• L79-94
Registration hardening
The main process wraps ipcMain.handle(), ipcMain.on(), and ipcMain.once() at startup. The wrapper validates the channel and first payload before it calls the real handler. Invalid request/response calls reject with an unauthorized-channel error. Invalid events are dropped and logged (app/index.js• L213-217, app/…/ipcSecurity.js• L31-119).
The wrapper also preserves listener removal. This matters for short-lived windows such as security-key prompts. Without matching removal behavior, those windows could leave handlers attached to destroyed windows and slowly increase process memory and listener counts (app/…/ipcSecurity.js• L11-18, app/…/ipcSecurity.js• L121-139).
References: app/index.js• L213-217 app/…/ipcSecurity.js• L11-18 app/…/ipcSecurity.js• L31-139
Microsoft Graph access
Teams session token
The Graph client uses the access token that the embedded Teams web app already holds for Microsoft Graph. It does not create a second application identity or show a second consent flow. The main process keeps the token in memory and refreshes it before expiry, while the renderer receives Graph results rather than credentials (app/…/index.js• L3-87, docs-site/…/030-graph-api-teams-session-token.md• L27-51).
This design keeps Graph access tied to the signed-in Teams session. It also limits the available data to the permissions that Teams requested. A missing permission is therefore an account or scope limit, not an IPC routing problem.
References: app/…/index.js• L3-87 docs-site/…/030-graph-api-teams-session-token.md• L27-51
Graph request client
The client sends approved operations to Microsoft Graph v1.0 and returns a common success or failure result. It checks whether Graph is enabled, obtains a usable token, applies a request timeout, and maps HTTP or transport errors to an error result (app/…/index.js• L89-173).
The client supports user profile, calendar, mail, People API, and chat work. The IPC layer exposes only the operations that the application currently needs. Calendar update and delete exist inside the client but are not exposed as IPC operations (app/…/index.js• L208-305, app/…/index.js• L409-458, docs-site/…/030-graph-api-teams-session-token.md• L36-51).
References: app/…/index.js• L89-173 app/…/index.js• L208-305 app/…/index.js• L409-458 docs-site/…/030-graph-api-teams-session-token.md• L36-51
Graph feature gate
The graphApi.enabled setting controls whether the client is created. When the setting is off, handlers still exist as stable IPC endpoints but return an explicit not-enabled result. This gives callers a predictable response and prevents disabled features from acquiring a token or making a network request (app/index.js• L604-615, app/…/ipcHandlers.js• L10-22).
The client is connected to the main window because token acquisition depends on the Teams page. If the window is not ready or the Teams authentication service cannot provide a token, the operation fails without exposing a credential to the renderer (app/…/index.js• L27-87).
References: app/index.js• L604-615 app/…/ipcHandlers.js• L10-22 app/…/index.js• L27-87
Privileged operations
Handler surface
The Graph IPC handlers are the application-facing contract for privileged Graph work. Each handler checks for an enabled client, calls one client operation, logs a concise error on failure, and returns a structured result. The seven channels are also present in the IPC allowlist, so the security gate and the handler surface must stay aligned (app/…/ipcHandlers.js• L10-100, app/…/ipcValidator.js• L96-103).
| IPC channel | Application capability | External effect |
|---|---|---|
graph-api-get-user-profile | Read the signed-in user profile | Reads /me |
graph-api-get-calendar-events | Read calendar events with query options | Reads calendar event data |
graph-api-get-calendar-view | Read events in a time range | Reads a calendar view |
graph-api-create-calendar-event | Add a calendar event | Creates a calendar event |
graph-api-get-mail-messages | Read mail messages with query options | Reads mailbox data |
graph-api-search-people | Find people for contact features | Reads ranked People API results |
graph-api-send-chat-message | Send a message to a selected user | Resolves a one-to-one chat and sends a message |
References: app/…/ipcHandlers.js• L10-100 app/…/ipcValidator.js• L96-103
Chat message flow
Chat sending has two parts because Microsoft Graph can send to a known chat but does not find or create the one-to-one chat from a user ID. The client first asks Teams to open or create the conversation, finds candidate thread IDs in the Teams page, checks their members through Graph, and then sends the message to the matching chat (app/…/index.js• L307-407, app/…/index.js• L409-458).
The handler validates the target user ID and message text before this flow starts. This protects the bridge from empty messages and limits conversation resolution to the expected user ID format (app/…/ipcHandlers.js• L79-94, app/…/index.js• L307-324).
The diagram shows how a renderer request moves through IPC validation and the two services before a result returns to the application.
flowchart LR
R[Application renderer] --> V[IPC channel and payload checks]
V --> H[Graph IPC handler]
H --> C[Graph API client]
C --> T[Teams session token]
C --> G[Microsoft Graph]
H --> O[Structured result]
O --> R
C -. chat resolution .-> W[Teams web page]
References: app/…/ipcHandlers.js• L79-94 app/…/index.js• L307-458 app/…/ipcSecurity.js• L87-119
Related application surfaces
Graph handlers support application features that need Teams data without granting those features direct token access. Quick Chat uses people search and chat sending. Other application services can use the same controlled Graph contract for calendar or mail actions when their feature is enabled.
The IPC controls apply to more than Graph. Browser tools that interact with the Teams page and desktop integration features that control windows or menus use the same main-process boundary. See Browser integration and tools and Desktop integration and menus for those neighboring surfaces.
Change checklist
When these files or sections are changed, remember to consider these:
- Add every new literal
ipcMain.handle(),ipcMain.on(), oripcMain.once()channel to the allowlist. The source scan treats a missing entry as a contract failure. - Keep the Graph handler count, channel names, and client methods aligned. A handler without an allowlist entry is blocked before it runs.
- Preserve the disabled-feature result when changing Graph initialization. Callers depend on a stable response when
graphApi.enabledis false. - Check the Teams session scopes before adding a Graph operation. The reused token cannot grant permissions that Teams did not request.
- Keep credentials inside the main process. New renderer-facing results must contain operation data or errors, not access tokens.
- Treat changes to Teams React service names or chat DOM markers as Graph integration changes. Token acquisition and one-to-one chat resolution depend on those web-app contracts.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A new IPC channel is not in the allowlist | The request is rejected or the event is dropped before the handler runs | Keep literal registrations and allowedChannels synchronized; the validator test scans all app registrations |
graphApi.enabled is false | Every Graph handler returns Graph API not enabled and no Graph request starts | Enable the feature before using Graph-backed application features |
| The main window or Teams auth service is unavailable | Token acquisition fails and the Graph operation returns an error result | Initialize the client after the main window is ready and handle the returned failure |
| Teams did not request the needed Graph scope | Microsoft Graph returns an authorization failure such as 403 | Use only endpoints covered by the Teams session grant or change the authentication design |
| A chat target has an invalid user ID or the message is empty | The message is rejected without conversation lookup or send | Validate the user ID and trimmed message content at the IPC handler |
| Graph does not respond within the request limit | The operation returns Request timed out | Treat the result as failed and allow the caller to retry |
| Teams changes its internal auth or chat page contract | Token acquisition or chat resolution stops working even though IPC remains valid | Keep the integration checks and failure results clear when updating Teams compatibility |
Key files
| File | Why to read it |
|---|---|
| app/index.js | Shows when IPC hardening is installed and when the Graph client and handlers enter the application lifecycle |
| app/…/ipcValidator.js | Defines the channel contract and payload safety boundary |
| app/…/ipcSecurity.js | Shows how the boundary covers handler registration, event delivery, and listener removal |
| app/…/ipcHandlers.js | Defines the seven Graph operations exposed to application code |
| app/…/index.js | Explains token use, Graph request behavior, supported data actions, and chat resolution |
| app/…/reactHandler.js | Shows the bridge to the Teams web app's existing authentication service |
| tests/…/ipcValidator.test.js | Demonstrates the allowlist, payload sanitization, and registration completeness guarantees |
| tests/…/ipcSecurity.test.js | Demonstrates blocked calls and safe listener cleanup across short-lived IPC users |
| docs-site/…/030-graph-api-teams-session-token.md | Records why the system reuses the Teams session token and what scope limits follow from that choice |