fix(ciphers): chunk RSA plaintext by bytes not runes to prevent OAEP overflow on UTF-8 input#319
Closed
simple-container-forge[bot] wants to merge 7 commits into
Conversation
…d-4b65-affb-3d6f61fb8f82 init idempotency: 99171cbe-7c27-4976-a999-931b834b5d62:d97cc852-279d-4b65-affb-3d6f61fb8f82:init
idempotency: pm:run Co-authored-by: Max Warner (pm) <forge-agent+pm@simple-forge.com>
idempotency: architect:run Co-authored-by: Dan Johnson (architect) <forge-agent+architect@simple-forge.com>
…P overflow on UTF-8 input EncryptLargeString was splitting the plaintext using lo.ChunkString, which operates on rune count. For a 2048-bit key the chunk size was 128 runes — safe for ASCII (128 bytes ≤ 190-byte OAEP-SHA256 limit) but wrong for multi-byte UTF-8: a 128-rune box-drawing string encodes to 384 bytes, blowing past the limit and producing "crypto/rsa: message too long for RSA key size". Replace the rune-based loop with a byte-slice loop using the correct OAEP-SHA256 maximum plaintext size: k − 2·hLen − 2 = 256 − 64 − 2 = 190 bytes for a 2048-bit key. Existing ciphertext is unaffected — DecryptLargeString is chunk-size agnostic. Also add a TODO comment on EncryptWithPublicRSAKey noting its SHA-512 / SHA-256 inconsistency with EncryptLargeString; no behavioural change there. Adds three regression tests covering box-drawing characters (U+2500, 3 B each), emoji (U+1F600, 4 B each), and a mid-rune byte-boundary split. Fixes: sc secrets add/hide failing with UTF-8 secret files.
simple-container-forge
Bot
requested review from
Cre-eD,
Laboratory,
smecsia and
universe-ops
as code owners
June 12, 2026 17:07
idempotency: developer:run Co-authored-by: David Black (developer) <forge-agent+developer@simple-forge.com>
Semgrep Scan ResultsRepository:
Scanned at 2026-06-12 17:23 UTC |
Security Scan ResultsRepository:
Scanned at 2026-06-12 17:24 UTC |
idempotency: qa:run Co-authored-by: Maria Currie (qa) <forge-agent+qa@simple-forge.com>
idempotency: devops:run Co-authored-by: William Smith (devops) <forge-agent+devops@simple-forge.com>
smecsia
approved these changes
Jun 12, 2026
universe-ops
approved these changes
Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
EncryptLargeStringwas chunking plaintext withlo.ChunkString(rune-count), but RSA-OAEP enforces a byte limit. A 128-rune chunk of 3-byte UTF-8 characters = 384 bytes — well above the 190-byte OAEP-SHA256 limit for a 2048-bit key — causingcrypto/rsa: message too long for RSA key size.maxPlain = k − 2·hLen − 2 = 190 bytesfor 2048-bit / SHA-256.DecryptLargeStringis chunk-size agnostic.// TODO:comment onEncryptWithPublicRSAKeynoting its SHA-512/SHA-256 inconsistency withEncryptLargeString; no functional change to that function.Changed files
pkg/api/secrets/ciphers/encryption.golo.ChunkStringRSA branch with byte-slice loop; add TODO comment onEncryptWithPublicRSAKeypkg/api/secrets/ciphers/encryption_test.goTest plan
go test ./pkg/api/secrets/ciphers/... -count=1— all tests pass (green locally)TestRSAEncryptionDecryption/RSA_encrypt/decrypt_UTF-8_multi-byte_string_(box-drawing)— was failing before fix (360 B > 190 B limit)TestRSAEncryptionDecryption/RSA_encrypt/decrypt_emoji-dense_string— was failing before fix (400 B > 190 B limit)TestRSAEncryptionDecryption/RSA_chunk_boundaries_do_not_corrupt_multi-byte_sequences— verifies mid-rune byte splits round-trip correctlyRSA encrypt/decrypt large string(ASCII) still passesWorkflow run
https://app.simple-forge.com/agent-workflow-runs/d97cc852-279d-4b65-affb-3d6f61fb8f82
🤖 Generated with Claude Code