Add configurable keytext byte-limit guard for /pks/add and document proxy limits - #143
Merged
Merged
Conversation
Agent-Logs-Url: https://github.com/bmarwell/java-keyserver/sessions/5c450da0-f6c9-49c8-839d-d5c15d84ca1b Co-authored-by: bmarwell <1413391+bmarwell@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix keytext size limit to guard against oversized upload DoS
Add configurable keytext byte-limit guard for May 25, 2026
/pks/add and document proxy limits
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #143 +/- ##
============================================
- Coverage 59.80% 52.15% -7.65%
- Complexity 58 69 +11
============================================
Files 16 21 +5
Lines 204 278 +74
Branches 22 32 +10
============================================
+ Hits 122 145 +23
- Misses 68 115 +47
- Partials 14 18 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an application-layer byte-size guard for POST /pks/add key submissions (to reduce oversized-upload DoS risk) and documents complementary reverse-proxy request body limits.
Changes:
- Enforces a configurable UTF-8 byte limit on
keytextinAddKeyToVerificationQueueCommandHandler(default 128 KiB). - Wires MicroProfile Config (
keyserver.pks.max-key-bytes) into the application-core module. - Adds unit tests for “over limit” and “exactly at limit” behavior; updates README with app + proxy limits.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| README.adoc | Documents the new application-level limit and recommends proxy body-size limits (nginx/Caddy examples). |
| pom.xml | Adds MicroProfile Config API to dependency management (provided scope). |
| application/application-core/pom.xml | Declares MicroProfile Config API dependency for application-core. |
| application/application-core/src/main/java/.../AddKeyToVerificationQueueCommandHandler.java | Implements the byte-size guard and config plumbing (with default + fallback). |
| application/application-core/src/test/java/.../AddKeyToVerificationQueueCommandHandlerTest.java | Adds focused tests covering over-limit rejection and equal-to-limit behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
119
to
+125
| if (command.keyText() == null || command.keyText().isBlank()) { | ||
| throw new KeyParsingException("keytext must not be null or blank"); | ||
| } | ||
| int keyTextBytes = command.keyText().getBytes(StandardCharsets.UTF_8).length; | ||
| if (keyTextBytes > effectiveMaxKeyBytes()) { | ||
| throw new KeyParsingException("Key submission exceeds maximum allowed size"); | ||
| } |
Comment on lines
+109
to
+110
| @ConfigProperty(name = MAX_KEY_BYTES_CONFIG_KEY, defaultValue = "131072") | ||
| int maxKeyBytes = DEFAULT_MAX_KEY_BYTES; |
Comment on lines
+252
to
+258
| void setMaxKeyBytes(int maxKeyBytes) { | ||
| this.maxKeyBytes = maxKeyBytes; | ||
| } | ||
|
|
||
| private int effectiveMaxKeyBytes() { | ||
| return maxKeyBytes > 0 ? maxKeyBytes : DEFAULT_MAX_KEY_BYTES; | ||
| } |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment on lines
+123
to
+128
| int maxKeyBytes = effectiveMaxKeyBytes(); | ||
| if (keyText.length() > maxKeyBytes) { | ||
| throw new KeyParsingException("Key submission exceeds maximum allowed size"); | ||
| } | ||
| byte[] keyTextBytes = keyText.getBytes(StandardCharsets.UTF_8); | ||
| if (keyTextBytes.length > maxKeyBytes) { |
Comment on lines
+94
to
+112
| For defense in depth, also enforce request/body limits at your reverse proxy. | ||
| Example snippets: | ||
|
|
||
| .nginx | ||
| [source,nginx] | ||
| ---- | ||
| server { | ||
| client_max_body_size 128k; | ||
| } | ||
| ---- | ||
|
|
||
| .Caddy | ||
| [source,caddyfile] | ||
| ---- | ||
| example.com { | ||
| request_body { | ||
| max_size 128KB | ||
| } | ||
| } |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.
POST /pks/addaccepted unboundedkeytext, allowing oversized payloads to be read and parsed fully in memory. This change adds an early byte-size guard before OpenPGP parsing and documents HTTP-layer limits for defense in depth.Application-layer DoS guard in add command handler
AddKeyToVerificationQueueCommandHandler#doExecute.Key submission exceeds maximum allowed size.keyserver.pks.max-key-bytes131072(128 KiB)Config wiring
microprofile-config-apias provided dependency where needed.@ConfigPropertyinto the handler.Focused tests for size-limit behavior
Operational documentation (defense in depth)
README.adocwith: