crypto/rsa: bound public modulus size to prevent verify-path CPU-exhaustion DoS#81
Merged
Merged
Conversation
…ustion DoS checkKeySize is intentionally permissive about the RSA modulus size so that weak/odd keys found in the wild can still be parsed and inspected. That leaves the modular-exponentiation cost during public-key operations — O(bitlen(E) · bitlen(N)^2) — otherwise unbounded: a malicious certificate/key presenting a multi-megabit modulus can force tens of seconds to minutes of CPU per signature check (e.g. ~60s for a 2,000,000-bit modulus), which during a TLS scan can pin a worker on a single connection — a CPU-exhaustion DoS. Add MaxPublicModulusBitLen (default 16384), enforced in checkPublicKeySize alongside the existing MaxPublicExponentBitLen, so VerifyPKCS1v15 / VerifyPSS / EncryptPKCS1v15 / EncryptOAEP reject an oversized modulus *before* the modexp. Parsing functions and crypto/x509 do not consult it, so inspecting an oversized key remains safe; setting it to 0 restores the previous unbounded behavior. Addresses runZero platform audit finding TLS-01. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.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.
Summary
checkKeySizeis intentionally permissive about the RSA modulus size (so weak/odd keys found in the wild can still be parsed and inspected). That leaves the modular-exponentiation cost during public-key operations —O(bitlen(E) · bitlen(N)²)— otherwise unbounded: a malicious certificate/key presenting a multi-megabit modulus can force tens of seconds to minutes of CPU per signature check (≈60s for a 2,000,000-bit modulus). During a TLS scan that can pin a worker on a single connection — a CPU-exhaustion DoS.This adds
MaxPublicModulusBitLen(default 16384), enforced incheckPublicKeySizenext to the existingMaxPublicExponentBitLen, soVerifyPKCS1v15/VerifyPSS/EncryptPKCS1v15/EncryptOAEPreject an oversized modulus before the modexp runs.crypto/x509do not consult the variable — inspecting an oversized key remains safe (consistent withMaxPublicExponentBitLen).0to disable the bound and restore the previous unbounded behavior.Test
crypto/rsa/rsa_test.goaddsTestMaxPublicModulusBitLen: a ~2,000,000-bit modulus is rejected byVerifyPKCS1v15in <2s (vs ~60s unmitigated), andMaxPublicModulusBitLen = 0does not gate. Fullgo test ./crypto/rsa/passes.🤖 Generated with Claude Code