Skip to content

[SECURITY] Agent API keys stored as plaintext in database - database dump leaks all agent credentials #152

Description

@anshul23102

Description

The database table that stores agent registration API keys persists the full plaintext key value as issued. A database backup, a SQL injection vulnerability, or direct database access exposes all agent API keys. Compromised keys allow unauthorized agents to ingest traces or access observability data.

Steps to Reproduce

  1. Register an agent and obtain an API key.
  2. Query the database directly (or exploit any SQL injection): SELECT * FROM api_keys;
  3. Observe the full API key value is stored as plaintext.

Root Cause

API keys are stored without hashing, making the database the sole source of truth for the key value itself.

Impact

A database breach exposes all agent credentials simultaneously. Leaked keys allow unauthorized trace ingestion and data pollution.

Proposed Fix

Store only a SHA-256 hash of the key, return the plaintext once at issuance only:

import { createHash, randomBytes } from "crypto";
const rawKey = randomBytes(32).toString("hex");
const keyHash = createHash("sha256").update(rawKey).digest("hex");
await db.apiKeys.insert({ keyHash, agentId, createdAt: new Date() });
// return rawKey to agent once; never stored again

On verification, hash the incoming key and compare to stored hash.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions