How Coco AI Ensures Data Privacy and Security When Connecting to Enterprise Applications

Coco AI enforces enterprise-grade data privacy through a dual-adapter runtime architecture that isolates privileged native operations from web environments, combined with token-based HTTPS communication, automatic auth expiration handling, and minimal client-side credential storage.

The infinilabs/coco-app repository implements a defense-in-depth security model designed specifically for enterprise deployments. By separating sensitive system interactions into a sandboxed Tauri native layer while keeping the web runtime completely isolated, Coco AI prevents unauthorized data access and ensures that authentication credentials never leak through client-side code or browser vulnerabilities.

Runtime Isolation Through Dual Adapter Architecture

Coco AI maintains two distinct runtime environments—Tauri for native desktop and Web for browser-based access—each with strictly controlled capabilities. This separation ensures that only the trusted native environment can access the file system or request OS permissions, while the web version remains fully sandboxed.

Tauri Native Adapter for Privileged Operations

The Tauri adapter (src/utils/tauriAdapter.ts) acts as a secure bridge to the operating system, utilizing sandboxed Tauri plugins to handle sensitive functions. File system operations route through tauri-plugin-fs-pro-api and tauri-plugin-dialog, exposing only controlled methods like metadata, openFileDialog, and revealItemInDir through the privileged Tauri bridge.

OS-level features such as window management and screen capture interface directly with native APIs via @tauri-apps/api/window and tauri-plugin-macos-permissions-api. When requesting screen recording or microphone permissions, the adapter invokes native macOS permission dialogs through checkScreenRecordingPermission() and checkMicrophonePermission(), returning boolean results that prevent UI fallbacks to insecure alternatives.

Web Adapter Sandboxing

The web adapter (src/utils/webAdapter.ts) deliberately stubs out all privileged APIs, logging warnings and returning null for file system calls while simulating window operations with console.log statements. Since the web version always returns false for permission checks, no privileged APIs are exposed in browser environments, eliminating attack vectors from malicious scripts or cross-site scripting attempts.

Token-Based Authentication and HTTPS Enforcement

All outbound API requests flow through a centralized Axios wrapper (src/api/axiosRequest.ts) that enforces authentication via request interceptors.

Dynamic Header Injection

The handleConfigureAuth interceptor in src/api/tools.ts retrieves authentication tokens from localStorage rather than hardcoded values, merging custom headers into the request configuration at runtime:

// src/api/tools.ts – dynamic authentication header injection
export const handleConfigureAuth = (config: any) => {
  const headersStr = localStorage.getItem("headers") || "{}";
  const headers = JSON.parse(headersStr);
  config.headers = { ...config.headers, ...headers };
  return config;
};

This pattern ensures that sensitive tokens like X-API-TOKEN remain outside the source code and are only injected when explicitly stored by the user after authentication.

HTTPS-Only Communication

The application enforces encrypted connections by defaulting to secure endpoints in src/stores/appStore.ts:

// src/stores/appStore.ts – secure endpoint configuration
endpoint: "https://coco.infini.cloud/",
endpoint_http: "https://coco.infini.cloud",

All enterprise data transmission occurs exclusively over HTTPS, preventing man-in-the-middle attacks or credential interception.

Automatic Token Expiration and Error Handling

Coco AI implements proactive token lifecycle management through response interceptors that detect authentication failures before they expose data.

Auth Error Detection

The handleAuthError function in src/api/tools.ts maps specific server error codes—10031 (login expired) and 10032 (session timeout)—to immediate handling logic:

// src/api/tools.ts – authentication error mapping
const authErrMap = {
  "10031": "Login expired, please login again",
  "10032": "Session timeout, please login again",
  // …
};

When these codes appear in API responses, the interceptor triggers logout flows and prevents stale tokens from being reused in subsequent requests.

Network Error Sanitization

The handleNetworkError implementation maps HTTP status codes like 401 (Unauthorized) to user-friendly messages without exposing raw server responses. This error sanitization prevents internal system details from leaking to the client interface, reducing the attack surface for reconnaissance-based exploits.

Secure OS Feature Access and Permission Gating

Sensitive capabilities require explicit user consent through native permission workflows available only in the Tauri build.

Permission-Gated Screen Capture

Screen recording functionality depends on checkScreenRecordingPermission() and requestScreenRecordingPermission() methods defined in src/utils/tauriAdapter.ts (lines 25–70). These functions invoke native macOS security dialogs rather than browser prompts, ensuring that OS-level consent mechanisms govern access to sensitive display data.

When permissions are denied, the adapter returns false, allowing the UI to gracefully disable features without attempting less-secure fallbacks. These checks are completely absent from the web adapter, guaranteeing that browser-based deployments cannot accidentally trigger privileged operations.

Minimal Client-Side Storage Strategy

Coco AI deliberately limits persistent storage to non-sensitive UI state, mitigating risks from local disk access or browser storage inspection.

Segregated State Management

The app-store (defined in src/stores/appStore.ts) persists only interface preferences like tooltip visibility and language settings via zustand. Conversely, the auth-store (src/stores/authStore.ts) explicitly excludes tokens from persistence, storing only a boolean isCurrentLogin flag:

// src/stores/authStore.ts – minimal credential persistence
persist(
  (set) => ({
    isCurrentLogin: true,
    setIsCurrentLogin: (isCurrentLogin) => set({ isCurrentLogin }),
  }),
  { 
    name: "auth-store", 
    partialize: (state) => ({ isCurrentLogin: state.isCurrentLogin }) 
  }
);

By using partialize to strip sensitive fields before storage, Coco AI ensures that authentication tokens remain only in memory or secure localStorage containers (for custom headers), never written to disk in recoverable formats.

Summary

  • Dual runtime isolation separates privileged native operations (Tauri) from sandboxed web environments, preventing unauthorized file system or OS access.
  • Token-based authentication dynamically injects credentials via Axios interceptors in src/api/tools.ts, keeping secrets out of source code.
  • HTTPS-only endpoints default to https://coco.infini.cloud, ensuring encrypted enterprise data transmission.
  • Automatic expiration handling for error codes 10031 and 10032 prevents stale token reuse and triggers secure logout flows.
  • OS permission gating restricts screen recording and microphone access to native Tauri builds with explicit user consent.
  • Minimal persistence strategy stores only UI state in app-store and login flags in auth-store, eliminating disk-based credential leakage risks.

Frequently Asked Questions

How does Coco AI prevent unauthorized file system access in browser deployments?

The web adapter (src/utils/webAdapter.ts) completely stubs out file system APIs, returning null and logging warnings instead of executing disk operations. This ensures that browser-based instances cannot read or write local files, while the Tauri adapter maintains exclusive control over file dialogs through sandboxed plugins like tauri-plugin-fs-pro-api.

Where does Coco AI store authentication tokens, and are they encrypted?

Authentication tokens are stored as JSON in localStorage under the "headers" key, injected into requests via handleConfigureAuth in src/api/tools.ts. While localStorage provides same-origin isolation, the auth-store deliberately avoids persisting tokens to disk using zustand's partialize feature, keeping only a boolean login flag in persistent storage.

What happens when an enterprise user's session expires?

When the server returns error codes 10031 (login expired) or 10032 (session timeout), the handleAuthError interceptor in src/api/tools.ts detects the failure and can trigger automatic logout flows. This prevents the client from sending subsequent requests with invalid credentials, ensuring that expired sessions cannot access enterprise data.

Does Coco AI support secure streaming API connections?

Yes, the src/api/streamFetch.ts implementation respects the same header injection flow as standard REST calls, ensuring that streaming connections to enterprise backends also carry authentication tokens and follow HTTPS-only communication patterns established in the Axios wrapper configuration.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →