fix(secrets): chunk EncryptLargeString by bytes not runes to fix UTF-8 overflow#321
Open
simple-container-forge[bot] wants to merge 7 commits into
Conversation
…c-4162-abc6-60b46e7a89c5 init idempotency: 99171cbe-7c27-4976-a999-931b834b5d62:08762da2-22ac-4162-abc6-60b46e7a89c5: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>
…8 overflow lo.ChunkString counts runes; for multi-byte UTF-8 a 128-rune chunk can be up to 384 bytes, exceeding the RSA-OAEP-SHA256 limit of 190 bytes for a 2048-bit key and causing "crypto/rsa: message too long for RSA key size". Replace the rune-based lo.ChunkString loop with a byte-slice loop using maxPlain = rsaKey.Size() - 2*sha256.Size - 2 (the exact RFC 8017 §7.1.1 formula). DecryptLargeString is chunk-size agnostic and needs no change; existing ciphertexts decrypt correctly. Also add a TODO comment to EncryptWithPublicRSAKey documenting the latent SHA-512 vs SHA-256 hash inconsistency with EncryptLargeString. Adds regression tests covering: box-drawing flood (120 × U+2500 = 360 B), mixed multi-byte, 190/191-byte ASCII boundaries, empty string, 4096-bit key.
idempotency: developer:run Co-authored-by: David Black (developer) <forge-agent+developer@simple-forge.com>
Semgrep Scan ResultsRepository:
Scanned at 2026-06-12 18:35 UTC |
Security Scan ResultsRepository:
Scanned at 2026-06-12 18:36 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>
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.
Closes #318
Summary
EncryptLargeStringusedlo.ChunkString(rune-based) to split the input before callingrsa.EncryptOAEP. For multi-byte UTF-8 characters a 128-rune chunk can encode to up to 384 bytes, exceeding the OAEP-SHA256 limit of 190 bytes for a 2048-bit key, causingcrypto/rsa: message too long for RSA key size.maxPlain = rsaKey.Size() - 2*sha256.Size - 2(the exact RFC 8017 §7.1.1 formula: 190 bytes for a 2048-bit key).TODOcomment onEncryptWithPublicRSAKeydocumenting the latent SHA-512 vs SHA-256 hash inconsistency withEncryptLargeString.Changes
pkg/api/secrets/ciphers/encryption.go— replacelo.ChunkStringblock inEncryptLargeStringRSA branch with byte-slice loop; addTODOtoEncryptWithPublicRSAKeypkg/api/secrets/ciphers/encryption_test.go— addTestEncryptLargeStringUTF8with 6 sub-tests covering: box-drawing flood (120 × U+2500 = 360 B), mixed multi-byte, 190/191-byte ASCII boundaries, empty string, 4096-bit key round-tripBackward Compatibility
DecryptLargeStringis chunk-size agnostic — it decrypts whatever list it receives. Existing secrets encrypted with the old rune-based chunking still decrypt correctly.Test Plan
go test ./pkg/api/secrets/ciphers/...— all tests pass (including 6 new UTF-8 regression tests)Forge workflow run
https://app.simple-forge.com/agent-workflow-runs/08762da2-22ac-4162-abc6-60b46e7a89c5