Skip to content

fix(crypto): validate ciphertext length before nonce extraction in AES Decrypt - #7227

Open
Siraryansingh wants to merge 2 commits into
pipe-cd:masterfrom
Siraryansingh:fix/aes-decrypt-nonce-check
Open

fix(crypto): validate ciphertext length before nonce extraction in AES Decrypt#7227
Siraryansingh wants to merge 2 commits into
pipe-cd:masterfrom
Siraryansingh:fix/aes-decrypt-nonce-check

Conversation

@Siraryansingh

Copy link
Copy Markdown

What this PR does / why we need it:

Validates that base64-decoded ciphertext is at least gcm.NonceSize() bytes long before extracting the nonce slice in Decrypt() (pkg/crypto/aes.go).

If the decoded ciphertext is shorter than gcm.NonceSize(), Decrypt() now returns an error gracefully instead of causing an out-of-range slice panic.

Which issue(s) this PR fixes:

Fixes #7215

How was this tested?:

  • Added TestAESDecryptShortCiphertext unit tests in pkg/crypto/aes_test.go covering short base64 ciphertext and empty input
  • Verified all unit tests pass with go test -v ./pkg/crypto

…S Decrypt

Validate that the base64 decoded ciphertext length is at least gcm.NonceSize() in Decrypt before attempting to extract the nonce slice. Returning an error prevents potential runtime panics on truncated or malformed ciphertext inputs.

Fixes pipe-cd#7215

Signed-off-by: Aryan Singh <aryansingh.as1012@gmail.com>
Copilot AI lite review requested due to automatic review settings August 23, 2026 12:26
@Siraryansingh
Siraryansingh requested a review from a team as a code owner August 23, 2026 12:26
@netlify

netlify Bot commented Aug 23, 2026

Copy link
Copy Markdown

Deploy Preview for pipecd-site canceled.

Name Link
🔨 Latest commit b3ec8f2
🔍 Latest deploy log https://app.netlify.com/projects/pipecd-site/deploys/6a8aeb0cb0bef60008cbecbf

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi @Siraryansingh, welcome to PipeCD and thanks for opening your first pull request!

We’re really happy to have you here

Before your PR gets merged, please check a few important things below.


Helpful resources


DCO Sign-off

All commits must include a Signed-off-by line to comply with the Developer Certificate of Origin (DCO).

In case you forget to sign-off your commit(s), follow these steps:

For the last commit:

git commit --amend --signoff
git push --force-with-lease

For multiple commits:

git rebase --signoff origin/master
git push --force-with-lease

Run checks locally

Before pushing updates, please run:

make check

This runs the same checks as CI and helps catch issues early.


💬 Need help?

If anything is unclear, feel free to ask in this PR or join us on the CNCF Slack in the #pipecd channel.
You can get your Slack invite from: https://communityinviter.com/apps/cloud-native/cncf

Thanks for contributing to PipeCD! ❤️

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the AES-GCM decryption path in pkg/crypto by validating the decoded ciphertext length before slicing out the nonce, preventing a runtime panic on malformed/truncated inputs (per #7215).

Changes:

  • Added a nonce-size length guard in AESEncryptDecrypter.Decrypt() to return an error instead of panicking on short ciphertext.
  • Added a regression unit test covering short and empty base64 ciphertext inputs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/crypto/aes.go Adds decoded-ciphertext length validation before nonce extraction in AES-GCM decrypt.
pkg/crypto/aes_test.go Adds regression coverage for short/empty ciphertext inputs to ensure decrypt returns an error instead of panicking.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/crypto/aes.go
Comment on lines +88 to +91
nonceSize := gcm.NonceSize()
if len(encrypted) < nonceSize {
return "", fmt.Errorf("ciphertext is shorter than nonce size")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey @Siraryansingh , I noticed your PR also addresses #7215. I had previously worked on the same AES-GCM short ciphertext panic, and the fixes seem quite similar. Just wanted to mention the overlap so we can avoid duplicating efforts.

Comment thread pkg/crypto/aes_test.go Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Aryan Singh <siraryansingh2005@gmail.com>
@vanshika2720

Copy link
Copy Markdown
Contributor

@Siraryansingh This issue is already fixed on master by #7217, which also addresses #7215.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent panic when decrypting short AES-GCM ciphertext

4 participants