@fanboynz/network-scanner 1.0.43 → 1.0.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/lib/nettools.js +9 -6
  2. package/nwss.js +26 -20
  3. package/package.json +1 -1
package/lib/nettools.js CHANGED
@@ -711,7 +711,7 @@ function createNetToolsHandler(config) {
711
711
  dryRunCallback = null,
712
712
  matchedDomains,
713
713
  addMatchedDomain,
714
- currentUrl,
714
+ isDomainAlreadyDetected,
715
715
  getRootDomain,
716
716
  siteConfig,
717
717
  dumpUrls,
@@ -743,13 +743,16 @@ function createNetToolsHandler(config) {
743
743
  const DIG_CACHE_TTL = 300000; // 5 minutes cache TTL
744
744
  const DIG_MAX_CACHE_SIZE = 400; // Smaller cache for dig due to shorter TTL
745
745
 
746
- return async function handleNetToolsCheck(domain, originalDomain) {
746
+ return async function handleNetToolsCheck(domain, fullSubdomain) {
747
+ // Use fullSubdomain parameter instead of originalDomain to maintain consistency
748
+ // with the domain cache fix approach
749
+ const originalDomain = fullSubdomain;
747
750
  // Helper function to log to BOTH console and debug file
748
751
 
749
752
  // Check if domain was already detected (skip expensive operations)
750
- if (typeof config.isDomainAlreadyDetected === 'function' && config.isDomainAlreadyDetected(domain)) {
753
+ if (typeof isDomainAlreadyDetected === 'function' && isDomainAlreadyDetected(fullSubdomain)) {
751
754
  if (forceDebug) {
752
- logToConsoleAndFile(`${messageColors.highlight('[nettools]')} Skipping already detected domain: ${domain}`);
755
+ logToConsoleAndFile(`${messageColors.highlight('[nettools]')} Skipping already detected subdomain: ${fullSubdomain} (output domain: ${domain})`);
753
756
  }
754
757
  return;
755
758
  }
@@ -1275,13 +1278,13 @@ function createNetToolsHandler(config) {
1275
1278
  // No need to add to matched domains
1276
1279
  } else {
1277
1280
  if (typeof addMatchedDomain === 'function') {
1278
- addMatchedDomain(domain);
1281
+ addMatchedDomain(domain, null, fullSubdomain);
1279
1282
  } else {
1280
1283
  matchedDomains.add(domain);
1281
1284
  }
1282
1285
  }
1283
1286
 
1284
- const simplifiedUrl = currentUrl ? getRootDomain(currentUrl) : 'unknown';
1287
+ const simplifiedUrl = config.currentUrl ? getRootDomain(config.currentUrl) : 'unknown';
1285
1288
 
1286
1289
  if (siteConfig.verbose === 1) {
1287
1290
  const matchType = [];
package/nwss.js CHANGED
@@ -1,4 +1,4 @@
1
- // === Network scanner script (nwss.js) v1.0.43 ===
1
+ // === Network scanner script (nwss.js) v1.0.44 ===
2
2
 
3
3
  // puppeteer for browser automation, fs for file system operations, psl for domain parsing.
4
4
  // const pLimit = require('p-limit'); // Will be dynamically imported
@@ -35,7 +35,7 @@ const { navigateWithRedirectHandling, handleRedirectTimeout } = require('./lib/r
35
35
  const { monitorBrowserHealth, isBrowserHealthy } = require('./lib/browserhealth');
36
36
 
37
37
  // --- Script Configuration & Constants ---
38
- const VERSION = '1.0.43'; // Script version
38
+ const VERSION = '1.0.44'; // Script version
39
39
 
40
40
  // get startTime
41
41
  const startTime = Date.now();
@@ -1481,9 +1481,12 @@ function setupFrameHandling(page, forceDebug) {
1481
1481
  /**
1482
1482
  * Helper function to add domain to matched collection
1483
1483
  * @param {string} domain - Domain to add
1484
+ * @param {string} fullSubdomain - Full subdomain for cache tracking
1484
1485
  * @param {string} resourceType - Resource type (for --adblock-rules mode)
1485
1486
  */
1486
- function addMatchedDomain(domain, resourceType = null) {
1487
+ function addMatchedDomain(domain, resourceType = null, fullSubdomain = null) {
1488
+ // Use fullSubdomain for cache tracking if provided, otherwise fall back to domain
1489
+ const cacheKey = fullSubdomain || domain;
1487
1490
  // Check if we should ignore similar domains
1488
1491
  const ignoreSimilarEnabled = siteConfig.ignore_similar !== undefined ? siteConfig.ignore_similar : ignore_similar;
1489
1492
  const similarityThreshold = siteConfig.ignore_similar_threshold || ignore_similar_threshold;
@@ -1524,8 +1527,8 @@ function setupFrameHandling(page, forceDebug) {
1524
1527
  }
1525
1528
  }
1526
1529
 
1527
- // Mark domain as detected for future reference
1528
- markDomainAsDetected(domain);
1530
+ // Mark full subdomain as detected for future reference
1531
+ markDomainAsDetected(cacheKey);
1529
1532
 
1530
1533
  if (matchedDomains instanceof Map) {
1531
1534
  if (!matchedDomains.has(domain)) {
@@ -1592,6 +1595,10 @@ function setupFrameHandling(page, forceDebug) {
1592
1595
  }
1593
1596
  }
1594
1597
  const reqUrl = request.url();
1598
+
1599
+ // ALWAYS extract the FULL subdomain for cache checking to preserve unique subdomains
1600
+ const fullSubdomain = safeGetDomain(reqUrl, true); // Always get full subdomain for cache
1601
+ const reqDomain = safeGetDomain(reqUrl, perSiteSubDomains); // Output domain based on config
1595
1602
 
1596
1603
  if (allBlockedRegexes.some(re => re.test(reqUrl))) {
1597
1604
  if (forceDebug) {
@@ -1615,7 +1622,7 @@ function setupFrameHandling(page, forceDebug) {
1615
1622
 
1616
1623
  // NEW: Check if even_blocked is enabled and this URL matches filter regex
1617
1624
  if (evenBlocked) {
1618
- const reqDomain = safeGetDomain(reqUrl, perSiteSubDomains);
1625
+ // reqDomain already defined above
1619
1626
  if (reqDomain && !matchesIgnoreDomain(reqDomain, ignoreDomains)) {
1620
1627
  for (const re of regexes) {
1621
1628
  if (re.test(reqUrl)) {
@@ -1634,7 +1641,7 @@ function setupFrameHandling(page, forceDebug) {
1634
1641
  wasBlocked: true
1635
1642
  });
1636
1643
  } else {
1637
- addMatchedDomain(reqDomain, resourceType);
1644
+ addMatchedDomain(reqDomain, resourceType, fullSubdomain);
1638
1645
  }
1639
1646
 
1640
1647
  const simplifiedUrl = getRootDomain(currentUrl);
@@ -1658,8 +1665,7 @@ function setupFrameHandling(page, forceDebug) {
1658
1665
  return;
1659
1666
  }
1660
1667
 
1661
- const reqDomain = safeGetDomain(reqUrl, perSiteSubDomains);
1662
-
1668
+
1663
1669
  if (!reqDomain) {
1664
1670
  if (forceDebug) {
1665
1671
  console.log(formatLogMessage('debug', `Skipping request with unparseable URL: ${reqUrl}`));
@@ -1668,8 +1674,8 @@ function setupFrameHandling(page, forceDebug) {
1668
1674
  return;
1669
1675
  }
1670
1676
 
1671
- // Skip matching if this domain is one of the redirect intermediaries
1672
- if (redirectDomainsToExclude && redirectDomainsToExclude.includes(reqDomain)) {
1677
+ // Skip matching if this full subdomain is one of the redirect intermediaries
1678
+ if (redirectDomainsToExclude && redirectDomainsToExclude.includes(fullSubdomain)) {
1673
1679
  if (forceDebug) {
1674
1680
  console.log(formatLogMessage('debug', `Skipping redirect intermediary domain: ${reqDomain}`));
1675
1681
  }
@@ -1708,9 +1714,9 @@ function setupFrameHandling(page, forceDebug) {
1708
1714
  }
1709
1715
 
1710
1716
  // Check ignoreDomains AFTER regex match but BEFORE domain processing
1711
- if (matchesIgnoreDomain(reqDomain, ignoreDomains)) {
1717
+ if (matchesIgnoreDomain(fullSubdomain, ignoreDomains)) {
1712
1718
  if (forceDebug) {
1713
- console.log(formatLogMessage('debug', `Ignoring domain ${reqDomain} (matches ignoreDomains pattern)`));
1719
+ console.log(formatLogMessage('debug', `Ignoring domain ${fullSubdomain} (matches ignoreDomains pattern)`));
1714
1720
  }
1715
1721
  break; // Skip this URL - domain is in ignore list
1716
1722
  }
@@ -1743,10 +1749,10 @@ function setupFrameHandling(page, forceDebug) {
1743
1749
  }
1744
1750
  } else if (hasNetTools && !hasSearchString && !hasSearchStringAnd) {
1745
1751
  // If nettools are configured (whois/dig), perform checks on the domain
1746
- // Skip nettools check if domain was already detected
1747
- if (isDomainAlreadyDetected(reqDomain)) {
1752
+ // Skip nettools check if full subdomain was already detected
1753
+ if (isDomainAlreadyDetected(fullSubdomain)) {
1748
1754
  if (forceDebug) {
1749
- console.log(formatLogMessage('debug', `Skipping nettools check for already detected domain: ${reqDomain}`));
1755
+ console.log(formatLogMessage('debug', `Skipping nettools check for already detected subdomain: ${fullSubdomain}`));
1750
1756
  }
1751
1757
  break; // Skip to next URL
1752
1758
  }
@@ -1795,14 +1801,14 @@ function setupFrameHandling(page, forceDebug) {
1795
1801
  });
1796
1802
 
1797
1803
  // Execute nettools check asynchronously
1798
- const originalDomain = (new URL(reqUrl)).hostname;
1804
+ const originalDomain = fullSubdomain; // Use full subdomain for nettools
1799
1805
  setImmediate(() => netToolsHandler(reqDomain, originalDomain));
1800
1806
  } else {
1801
1807
  // If searchstring or searchstring_and IS defined (with or without nettools), queue for content checking
1802
- // Skip searchstring check if domain was already detected
1803
- if (isDomainAlreadyDetected(reqDomain)) {
1808
+ // Skip searchstring check if full subdomain was already detected
1809
+ if (isDomainAlreadyDetected(fullSubdomain)) {
1804
1810
  if (forceDebug) {
1805
- console.log(formatLogMessage('debug', `Skipping searchstring check for already detected domain: ${reqDomain}`));
1811
+ console.log(formatLogMessage('debug', `Skipping searchstring check for already detected subdomain: ${fullSubdomain}`));
1806
1812
  }
1807
1813
  break; // Skip to next URL
1808
1814
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fanboynz/network-scanner",
3
- "version": "1.0.43",
3
+ "version": "1.0.44",
4
4
  "description": "A Puppeteer-based network scanner for analyzing web traffic, generating adblock filter rules, and identifying third-party requests. Features include fingerprint spoofing, Cloudflare bypass, content analysis with curl/grep, and multiple output formats.",
5
5
  "main": "nwss.js",
6
6
  "scripts": {