Securing OAuth Tokens in the Database Layer
Published on January 07, 2026 by remii team
AI agents require access to your business tools to be useful. An agent that cannot read your emails, query your database, or post to your Slack channels is little more than a toy. However, granting an AI agent access to these systems usually involves generating OAuth 2.0 Access Tokens or Personal Access Tokens (PATs).
If a malicious actor gains access to the database where these tokens are stored, they gain unrestricted access to your connected applications. Securing these credentials at the database layer is the single most important security responsibility of any agentic framework.
At remii, we utilize a robust vault architecture with strict cryptographic boundaries to ensure your OAuth tokens are never exposed in plaintext.
### The Danger of Plaintext Storage
Many early-stage applications store API keys in plaintext in a standard `users` or `integrations` table. If an attacker discovers a SQL injection vulnerability, or if a disgruntled employee dumps the database backup, the attacker instantly possesses valid session tokens for every connected GitHub, Slack, and Salesforce account across the entire customer base.
To mitigate this, tokens must be encrypted at rest.
### Symmetric Encryption with AES-256 GCM
remii encrypts all integration credentials using AES-256 GCM (Galois/Counter Mode). We chose GCM because it is an authenticated encryption algorithm. It not only ensures that the token data is encrypted (confidentiality) but also provides an authentication tag that guarantees the data has not been tampered with (integrity). If a hacker manages to modify the encrypted string in the database, the decryption process will fail instantly, preventing the system from using a maliciously altered token.
### The Key Management Service (KMS) Vault
Encryption is only as strong as the key used to encrypt the data. If the encryption key is stored in the same database or the same environment variables as the web application, a server compromise will expose both the ciphertext and the key.
To prevent this, remii uses an isolated Key Management Service (KMS) architecture: - **Separation of Concerns**: The database stores the encrypted tokens (ciphertext). The database does not know the encryption key. - **The Vault**: The master encryption keys are stored in a highly secure, isolated hardware security module (HSM) or a managed KMS (like AWS KMS or HashiCorp Vault). - **Just-in-Time Decryption**: When the agent needs to make an API call to GitHub, the orchestrator pulls the ciphertext from the database, sends it securely to the KMS isolation layer, decrypts it in memory, executes the HTTP request to GitHub, and immediately garbage-collects the plaintext token from RAM.
### Zero-Trust Frontend Architecture
A common vulnerability in web applications occurs when developers accidentally serialize API tokens and send them to the frontend React or Vue application. Even if the tokens are encrypted in the database, if they are sent to the user's browser, they are vulnerable to Cross-Site Scripting (XSS) attacks.
remii employs a strict zero-trust frontend architecture. The `remii.space` dashboard never receives your raw OAuth tokens. The UI only receives boolean status flags (e.g., `github_connected: true`). All API calls utilizing those tokens are strictly proxied through our secure backend servers.
### Conclusion
By implementing AES-256 GCM encryption, isolating keys in a dedicated KMS vault, and enforcing a zero-trust frontend, remii ensures that your integration credentials remain locked down. This military-grade security architecture allows enterprise teams to deploy autonomous AI agents with complete confidence that their connected digital ecosystems are safe from credential exfiltration.