projectdiscovery / projectdiscovery/alterx

DankEncoder: Add context support and max results limit to prevent hanging on complex patterns

Open
#285 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
1k
Forks
78
PR merge metrics
No merged PRs in 30d

Description

Problem

When running pattern mining in discover mode on certain inputs with many domains (~900+), the subdomain generation step can hang indefinitely. The hang occurs in GenerateAtFixedLength() when processing patterns that cause exponential recursion in the DFS traversal.

Example Input

Input file with 898 subdomains under .tstaging.tools domain causes hanging around pattern 400-500 during generation phase. Sample domains that contribute to problematic patterns:

mobile-prod-genymotion-64.ue1.mobile.tstaging.tools
grafana.ue1.s11.tstaging.tools
kibana-logging.eck.ue1.cloudhub.tstaging.tools
gateway.ue1.stg1.tstagingsub-97-35-127.gateway.ue1.stg1.tstaging.tools

The issue is that certain discovered patterns, when fed to DankEncoder's GenerateAtFixedLength(), trigger deep recursion that takes an impractical amount of time to complete.

Root Cause

The internal/dank/dank.go library's GenerateAtFixedLength() function:

  1. Uses pure recursive DFS without any exit conditions
  2. Has no way to be interrupted or cancelled
  3. Has no limit on number of results generated

Requested Features

1. Context Support for Early Cancellation

Add context parameter to allow graceful cancellation:

func (d *DankEncoder) GenerateAtFixedLengthWithContext(ctx context.Context, fixedLen int) ([]string, error)

This would allow the caller to set timeouts and cancel expensive operations.

2. Max Results Limit

Add parameter to limit maximum results and exit early:

func (d *DankEncoder) GenerateAtFixedLengthWithLimit(fixedLen int, maxResults int) []string

This would prevent runaway recursion by stopping once a threshold is reached.

Benefits

  • Prevents hanging on complex patterns
  • Allows reasonable timeouts for pattern generation
  • Makes discover mode viable for larger input sets
  • Maintains backwards compatibility (keep existing functions, add new variants)

Workaround

Currently using a conservative NumWords() estimate check, but it's not accurate enough to prevent all problematic patterns from being processed.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with internal/dank/dank.go and read GenerateAtFixedLength(), focusing on how its recursive DFS currently traverses patterns. Add the requested context-aware and max-results variants while keeping the existing functions available. Done means cancellation can stop generation, result generation respects the configured limit, and the existing API remains compatible.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.