Skip to content

fix(crypto): validate encrypted payload before decrypt - #4

Closed
haskou wants to merge 2 commits into
masterfrom
codex/propose-fix-for-unbounded-payload-parsing-zj5ii3
Closed

haskou wants to merge 2 commits into
masterfrom
codex/propose-fix-for-unbounded-payload-parsing-zj5ii3

Conversation

@haskou

@haskou haskou commented May 20, 2026

Copy link
Copy Markdown
Owner

Motivation

  • The decryption path accepted attacker-controlled EncryptedPayload strings with no format or size validation, which allowed malformed input or very large base64 fields to trigger uncaught exceptions or large allocations before cryptographic authentication.
  • The intent is to prevent availability and DoS issues by validating the payload early while preserving the existing decryption semantics for valid inputs.

Description

  • Add strict validation in PrivateKey.decrypt() requiring exactly 4 dot-separated parts and performing per-field base64 checks.
  • Enforce decoded-length checks for ephemeral public key (32 bytes), IV (12 bytes), and auth tag (16 bytes), and cap ciphertext size to 1 MiB before decryption.
  • Implement a local decodeBase64 helper and keep the existing shared-secret derivation and AES-GCM decryption path intact.
  • Add regression tests in tests/value-objects/crypto/PrivateKey.spec.ts for malformed payloads, invalid field lengths, and oversized ciphertext.

Testing

  • Ran yarn test tests/value-objects/crypto/PrivateKey.spec.ts and the suite passed.
  • The test run executed 1 test suite with 24 tests and all tests passed, including the new regression cases.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 043e66bb1c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/value-objects/crypto/PrivateKey.ts Resolved
Comment thread src/value-objects/crypto/PrivateKey.ts Resolved
@haskou

haskou commented May 22, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

haskou commented Jun 7, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #9, which uses the fix/* release branch prefix and a squash-merge-ready conventional commit title with gitmoji.

@haskou haskou closed this Jun 7, 2026
@haskou
haskou deleted the codex/propose-fix-for-unbounded-payload-parsing-zj5ii3 branch June 7, 2026 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant