Skip to content

fix(security): bind platform credential decryption to aad - #951

Open
AlanSyue wants to merge 2 commits into
ChatbotXIO:mainfrom
AlanSyue:fix/platform-credential-aad-binding
Open

fix(security): bind platform credential decryption to aad#951
AlanSyue wants to merge 2 commits into
ChatbotXIO:mainfrom
AlanSyue:fix/platform-credential-aad-binding

Conversation

@AlanSyue

@AlanSyue AlanSyue commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • derive the expected AAD from trusted PlatformCredential row identity for both platform- and user-scoped credentials
  • pass that row-derived AAD into decryption so AES-GCM rejects ciphertext moved to a different credential context
  • add regression coverage for both credential scopes

Root cause

PlatformCredential write paths encrypt values with row-specific AAD, but the shared read path did not pass the expected context back into decryption. Without caller-provided context, decryption could fall back to the AAD embedded in the encrypted blob instead of binding the blob to the database row being read.

The shared encryption utility now gives caller-provided AAD precedence while retaining its generic fallback when no AAD is supplied. This PR completes that contract by making the credential service always provide the expected row-derived AAD.

Impact

  • valid platform- and user-scoped credentials decrypt with their matching row identity
  • ciphertext copied between credential contexts fails AES-GCM authentication
  • generic encryption callers that intentionally omit AAD retain upstream compatibility
  • no schema or data migration is required

Validation

  • pnpm lint
  • pnpm --filter @chatbotx.io/encryption check-types
  • pnpm --filter @chatbotx.io/business check-types
  • pnpm --filter @chatbotx.io/encryption test -- encryption — 22 tests passed
  • pnpm --filter @chatbotx.io/business test -- platform-credential-service.test.ts — 872 tests passed
  • git diff --check

The repository-wide coverage threshold was not bypassed. This PR does not claim a passing full coverage gate because the existing package baselines remain below the configured threshold.

@github-actions github-actions Bot added the bug Something isn't working as expected label Aug 13, 2026
@AlanSyue
AlanSyue marked this pull request as ready for review August 13, 2026 16:04
…tial-aad-binding

# Conflicts:
#	packages/encryption/src/encryption.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant