projectdiscovery / projectdiscovery/alterx
DankEncoder: Add context support and max results limit to prevent hanging on complex patterns
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:
- Uses pure recursive DFS without any exit conditions
- Has no way to be interrupted or cancelled
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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