Skip to content

-permute builds ~93 candidates per source name in memory, before any budget #400

Closed

Description

@TMHSDigital

Summary

-permute builds about 93 candidates for every name any source proposed (CT, Wayback, AXFR), keeps up to three copies of them in memory, and does all of this before -max-queries applies. With a large CT footprint, that means hundreds of MB and a second pass of millions of queries that -dry-run does not estimate.

Where

  • internal/candidates/candidates.go:96-98, 131-150, 159-166 (every source name becomes a permutation seed)
  • internal/permute/permute.go:28-65 (Generate: 3 × len(Words) + 3 variants per seed in one map, then a sorted slice)
  • internal/cli/permute.go:44-50, 67-72 (wordlist.NotIn and wordlist.Build make further copies)

Details

Set.Add puts every proposed name into the seeds, and RelativeSeeds turns all of them into permutation seeds. For each seed, Generate adds 90 word combinations plus 3 numbered variants to a map, then copies them into a slice. Permutations builds a second map of the same size in wordlist.NotIn(generated, entries), then a third structure in wordlist.Build. All of this happens before scanTarget, so -max-queries caps only what is admitted, not what is built. finishedPermutation (resume) rebuilds the whole list only to count it.

Impact

crt.sh often returns 10k-100k names for a large organisation. At 50k seeds that is about 4.6M candidates and a peak of roughly 0.5 GB per target, plus a 4.6M-query second pass (about 77 minutes at 1000 qps). This is an estimate from the data structures, not a measurement.

Steps to reproduce

Run subenum -ct -permute <target with a large CT footprint> and watch RSS at the "Permutation pass for X: N candidates from M seed names" line.

Suggested fix

  • Seed -permute from found names (and -seeds) by default, and make source-proposed names opt-in. Or cap seeds or candidates and print a notice.
  • Generate into one deduplicated set and drop wordlist entries in the same pass, so only one structure is live.
  • Have finishedPermutation count without building the full list.
  • Include the permutation pass in the -dry-run estimate.

Acceptance criteria

  • Peak memory of the permutation pass is bounded, or scales with found names rather than with source names
  • -dry-run reports the permutation pass size
  • A benchmark with 50k seeds in internal/permute or internal/cli

Getting started


Filed by repo-audit/full-audit at dd5b156. Severity: medium. Effort: M. audit-key: performance|internal/permute/permute.go|Generate

Activity

  1. added
    help wanted
    performance
    severity: medium
    on Nov 17, 2026
  2. TMHSDigital commented on Nov 18, 2026

    @TMHSDigital
    OwnerAuthor

    Fixed in 3d8c23d.

    • One structure: candidates.Permutations generates into a single set (permute.GenerateSet), deletes wordlist entries from it in place and copies the survivors out sorted. NotIn and Build are no longer used here, so the generated map, sorted copy, NotIn set and Build index are no longer all held at once.
    • Bounded: a target's pass builds at most 1,000,000 candidates (candidates.MaxPermutations). Seeds are taken in sorted order, so a resumed pass rebuilds the same list, and the CLI prints a note when the cap is hit.
    • -dry-run: the found names are not known before a scan, so the plan can't give the pass's exact size. Its notes now give the bound instead: up to 93 candidates per name, at most 1,000,000 per target.
    • Benchmark: BenchmarkPermutations50k in internal/candidates. For 50,000 seeds the old pipeline took about 11 s with 1.8 GB allocated. The new one takes 0.9 s with 148 MB, capped at 1M candidates.

    I left source-proposed names as seeds rather than making them opt-in, since the cap bounds the cost either way. TestPermutationsCapped checks that the cap holds and that builds are reproducible. The full suite, vet and golangci-lint pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedperformanceseverity: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions