Skip to content

fix: add subkey count cap in AddKeyToVerificationQueueCommandHandler #136

Description

@bmarwell

Problem

UIDs are capped at MAX_EMAIL_UIDS = 20, but subkeys are not capped. A key with tens of thousands of subkeys:

  1. Is parsed in full by Bouncy Castle during POST /pks/add.
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions