Repository navigation
fix(extractor): match the target domain literally and reject partial hosts - #1811
Conversation
…hosts NewSubdomainExtractor interpolated the raw domain into the regex, so the dots in the domain were treated as "any character" (e.g. "example.com" also matched "exampleXcom"). The pattern was also unbounded on the right, so text such as "foo.example.com.evil.org" yielded the bogus subdomain "foo.example.com", which passes the runner's HasSuffix check and reaches the output. This affects every source that extracts hosts from free text (crtsh, waybackarchive, commoncrawl, hackertarget, digitorus, rapiddns, urlscan, sitedossier, ...). Escape the domain with regexp.QuoteMeta and drop matches that are only a prefix of a longer hostname, while still accepting the trailing-dot FQDN form. Add table-driven tests for the extractor.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe subdomain extractor now treats supplied domains literally, detects hostname continuation boundaries, and lowercases indexed matches. New table-driven tests cover valid extraction, normalization, trailing dots, wildcard prefixes, and false-positive rejection. ChangesSubdomain Extraction
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/subscraping/extractor.go (1)
37-37: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winClone the extracted substring before appending it.
strings.ToLowercan return the original slice when the match is already lowercase, which keeps the fulltextbacking array alive. Wrapping the result instrings.Clone(...)breaks that reference for large response bodies.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/subscraping/extractor.go` at line 37, Update the match append logic in the extractor to wrap the strings.ToLower result with strings.Clone before appending to matches, ensuring extracted substrings do not retain the full text backing array.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/subscraping/extractor.go`:
- Line 37: Update the match append logic in the extractor to wrap the
strings.ToLower result with strings.Clone before appending to matches, ensuring
extracted substrings do not retain the full text backing array.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8cdb345b-c382-4c0d-89f4-c10bf7ffb913
📒 Files selected for processing (2)
pkg/subscraping/extractor.gopkg/subscraping/extractor_test.go
|
Thanks — wrapped the extracted match in |
subfinder 2.16.0 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre><!-- Release notes generated using configuration in .github/release.yml at main --> ## What's Changed * feat(sources): honor -max-results across paginating sources by @Gerijacki in projectdiscovery/subfinder#1810 * fix(extractor): match the target domain literally and reject partial hosts by @Gerijacki in projectdiscovery/subfinder#1811 * fix(subscraping): cap untrusted source response bodies with a size limit by @adamsjack711-ux in projectdiscovery/subfinder#1809 * fix(subscraping): use DialContext instead of the deprecated Dial by @jonaslejon in projectdiscovery/subfinder#1835 * feat: add scanmalware passive source by @jonaslejon in projectdiscovery/subfinder#1834 * fix(crtsh): set statement_timeout via SQL query to avoid PgBouncer handshake rejection (#1828) by @gcoinstash-cmd in projectdiscovery/subfinder#1832 ## New Contributors * @J12934 made their first contribution in projectdiscovery/subfinder#1823 * @adamsjack711-ux made their first contribution in projectdiscovery/subfinder#1809 * @gcoinstash-cmd made their first contribution in projectdiscovery/subfinder#1832 **Full Changelog**: https://github.com/projectdiscovery/subfinder/compare/v2.15.0...v2.16.0</pre> <p>View the full release notes at <a href="https://github.com/projectdiscovery/subfinder/releases/tag/v2.16.0">https://github.com/projectdiscovery/subfinder/releases/tag/v2.16.0</a>.</p> </details> <hr> See merge request: Harmonybrew/homebrew-core!17505
Summary
NewSubdomainExtractorbuilds its regex by interpolating the raw domain:This has two problems:
example.comthe regex also matches text likeexampleXcom, producing false positives.foo.example.com.evil.orgyields the bogus subdomainfoo.example.com, which then passes the runner'sHasSuffix("."+domain)check and reaches the output.This affects every source that extracts hosts from free text (
crtsh,waybackarchive,commoncrawl,hackertarget,digitorus,rapiddns,urlscan,sitedossier, ...).Fix
regexp.QuoteMetaso its dots (and any other metacharacters) match literally.host.example.com.).Tests
Added table-driven tests for the extractor covering literal dots, right-boundary rejection, wildcards, trailing dots, and case-insensitivity. The package had no extractor test before.
Summary by CodeRabbit