Problem
UIDs are capped at MAX_EMAIL_UIDS = 20, but subkeys are not capped. A key with tens of thousands of subkeys:
- Is parsed in full by Bouncy Castle during
POST /pks/add.
- Triggers one
stripToVerifiedUids() call per verified UID during publishVerifiedUid — each of which rebuilds the entire key ring including all subkeys.
This is a DoS vector independent of UID count.
Fix
After obtaining masterKey, count the subkeys and reject the submission if it exceeds a limit:
static final int MAX_SUBKEYS = 50;
int subkeyCount = 0;
for (Iterator<PGPPublicKey> it = keyRing.getPublicKeys(); it.hasNext(); it.next()) {
if (++subkeyCount > MAX_SUBKEYS) {
throw new KeyValidationException("Key has too many subkeys (limit: " + MAX_SUBKEYS + ")");
}
}
Legitimate keys carry 1–5 subkeys. 50 is generous headroom.
Note
The existing MAX_EMAIL_UIDS pattern is the template for this.
Problem
UIDs are capped at
MAX_EMAIL_UIDS = 20, but subkeys are not capped. A key with tens of thousands of subkeys:POST /pks/add.stripToVerifiedUids()call per verified UID duringpublishVerifiedUid— each of which rebuilds the entire key ring including all subkeys.This is a DoS vector independent of UID count.
Fix
After obtaining
masterKey, count the subkeys and reject the submission if it exceeds a limit:Legitimate keys carry 1–5 subkeys. 50 is generous headroom.
Note
The existing
MAX_EMAIL_UIDSpattern is the template for this.