Skip to content

fix(crypto): 🔒 Use raw Media bytes for cryptographic operations - #10

Merged
haskou merged 4 commits into
masterfrom
fix/raw-media-bytes-crypto
Jun 7, 2026
Merged

haskou merged 4 commits into
masterfrom
fix/raw-media-bytes-crypto

Conversation

@haskou

@haskou haskou commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Close a canonicalization vulnerability where Media converted Buffer input to UTF-8 strings and later reconstructed bytes with Buffer.from(this.value), causing distinct binary sequences to collide during hash/sign operations.
  • Preserve cryptographic integrity by ensuring crypto and hash operations consume the original raw bytes when Media is provided.

Description

  • Treat Media payloads as raw bytes by using Media.getBuffer() instead of valueOf() when building message buffers for signing, verification, and encryption in PrivateKey and PublicKey. (src/value-objects/crypto/PrivateKey.ts, src/value-objects/crypto/PublicKey.ts).
  • Update hash factory methods to hash Media.getBuffer() when a Media instance is passed to MD5Hash.from, SHA256Hash.from, and SHA512Hash.from so digests reflect original bytes. (src/value-objects/hashes/MD5Hash.ts, src/value-objects/hashes/SHA256Hash.ts, src/value-objects/hashes/SHA512Hash.ts).
  • Preserve existing behavior for string, StringValueObject, and Buffer payloads; change affects only Media inputs.

Testing

  • Ran the full test suite with npm test -- --runInBand, which completed successfully and reported all test suites passing.
  • Linting and unit tests executed as part of the test run and passed (project test run shows all suites and tests passing).

Supersedes #5.

Codex Task

@codecov-commenter

codecov-commenter commented Jun 7, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/value-objects/media/Media.ts 71.42% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@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: 322c0d49fa

ℹ️ 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/media/Media.ts Resolved

haskou commented Jun 7, 2026

Copy link
Copy Markdown
Owner Author

Note on the Codecov warning: the app installation is repository setup rather than a code change in this PR. The uploaded Codecov report says all modified and coverable lines are covered.

@haskou
haskou merged commit bdd7b76 into master Jun 7, 2026
2 checks passed
@haskou
haskou deleted the fix/raw-media-bytes-crypto branch June 7, 2026 08:23
github-actions Bot added a commit that referenced this pull request Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants