Securing Third-Party Credentials in Headless Architectures

Storing and executing API keys, OAuth tokens, and server-to-server credentials securely within a server-side proxy gateway.
In modern headless and composable development, our applications are essentially a collection of web hooks and remote integrations. A typical enterprise web app regularly communicates with HubSpot for CRM lead trapping, Brevo or Mailchimp for marketing workflows, Stripe for payment processing, and Cloudinary for edge media delivery.
However, this architecture introduces a severe, widespread security vulnerability: credential exposure.
Too many lightweight headless CMS platforms and visual page builders delegate integration calls directly to the browser or embed integration client SDKs directly into client-side bundles. This exposes raw API keys, private tokens, and service credentials to reverse engineering via the browser dev tools, leaving the organization exposed to data breaches, API rate-limit exhaustion, and financial liability.
When we designed the architecture for Whoobe, our open-source application platform, our non-negotiable security requirement was absolute credential isolation.
Here is the blueprint of how to implement a secure, zero-trust Federated API Gateway Proxy that completely walls off sensitive enterprise keys from the browser.
The Blueprint: Server-Side Proxy Isolation
The core rule of a secure headless architecture is absolute: The client browser and the visual editing canvas must never see, hold, or transmit a raw third-party credential.
Instead of letting client frontend frameworks (like Next.js or Nuxt) call external APIs directly, all integration traffic must be routed through an isolated server-side API Gateway Proxy.
[Client App / Browser] │ (Unauthenticated or Session-Based Public Request) ▼ [Whoobe API Gateway Proxy] ── (AES-256-GCM Decryption Server-Side) │ (Injects Secure Authorization Headers: Bearer / OAuth) ▼ [External Vendor API (HubSpot / Brevo)]
When an action occurs (e.g., a user submits a visually mapped lead form or pushes a content snippet as an email campaign), the client hits an internal gateway endpoint, such as /api/gateway/hubspot/contacts.
The client has no idea how the external vendor authenticates; it simply transmits a clean, unauthenticated data payload.
Cryptographic Security: AES-256-GCM at Rest
To guarantee full data sovereignty in a self-hosted environment, credentials cannot be stored as plain text inside environment files or standard database fields.
Within the Whoobe ecosystem, every third-party integration credential is dynamically encrypted at rest using an isolated server-side master key via AES-256-GCM (Authenticated Encryption with Associated Data). This ensures that even in the case of a raw database snapshot leak, your enterprise tokens remain completely secure.
Here is a simplified blueprint of our Node.js cryptographic service provider:
import crypto from 'crypto';
const ALGORITHM = 'aes-256-gcm';
const IV_LENGTH = 12;
const TAG_LENGTH = 16;
export function encryptCredential(text: string, masterKey: string): string {
const iv = crypto.randomBytes(IV_LENGTH);
const cipher = crypto.createCipheriv(ALGORITHM, Buffer.from(masterKey, 'hex'), iv);
let encrypted = cipher.update(text, 'utf8', 'hex');
encrypted += cipher.final('hex');
const authTag = cipher.getAuthTag().toString('hex');
// Package IV, Auth Tag, and Encrypted Payload into a unified string
return `${iv.toString('hex')}:${authTag}:${encrypted}`;
}
export function decryptCredential(encryptedText: string, masterKey: string): string {
const [ivHex, authTagHex, encryptedPayload] = encryptedText.split(':');
const iv = Buffer.from(ivHex, 'hex');
const authTag = Buffer.from(authTagHex, 'hex');
const decipher = crypto.createDecipheriv(ALGORITHM, Buffer.from(masterKey, 'hex'), iv);
decipher.setAuthTag(authTag);
let decrypted = decipher.update(encryptedPayload, 'hex', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
}
Automating Token Lifecycle Management
Static API keys are slowly being deprecated by major enterprise vendors in favor of stricter OAuth2 client-credentials or authorization-code grants. While this drastically improves security, it introduces a major headache for developer workflows: managing token lifecycles, expiration matching, and seamless background refreshes.
The Whoobe API Gateway solves this by acting as an automated token lifecycle manager.
When a proxy request is received, the Gateway executes a fast 3-step internal pipeline:
- Validation Check: It interrogates the integration metadata record on Postgres. If the current access token is valid, it proceeds immediately.
- Background Refresh: If the token has expired, the Gateway transparently catches the request, halts the client pipeline, executes a server-to-server OAuth call using the encrypted refresh credentials, stores the fresh token back into Postgres, and automatically completes the original user request.
- Granular Rate Limiting: Because multiple public frontends or mobile apps (compiled via Capacitor) use the same centralized gateway proxy, the server applies an in-memory token bucket rate-limiter (defaulting to 10 Requests Per Second per IP) to prevent malicious clients from exhausting the enterprise vendor's API limits.
The Takeaway for Security Architects
Securing a headless architecture requires eliminating client-side trust. By offloading integration logic to an encrypted, server-side gateway proxy, you achieve:
- Zero Credential Leaks: Browser reverse engineering is completely neutralized.
- Complete Audit Trails: Every external read and write (GET/POST) is centrally logged, tracked, and throttled at the gateway layer.
- Decoupled Client Code: Frontends and mobile apps remain incredibly lightweight, dealing exclusively with clean, predictable JSON schemas rather than vendor-specific SDK packages and authentication quirks.
Security is not a feature you bolt onto an enterprise content and data platform after the fact—it is the foundation upon which your entire external application fabric must be built.