AI powered OSINT engine to discover and map 840+ social media identities across the web
Python aiartificial-intelligencedebainhackhackerhackinghackingtoolsinformationinformation-gatheringlinuxlinux-desktoposintpythonpython-scriptpython3social-mediasocialmediahackingtermuxtermux-tool
fix: a long Retry-After could stall a whole scan; cancel workers with the scan
arxhr007623c09461921
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 86b8749..d33fe6b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,6 +1,15 @@# Changelog-## 2.6.0 (2026-10-07)+## 2.6.0 (2026-10-08)++### Fixed+- **One site could stall a whole scan.** A site answering `429` or `503` with a long+ `Retry-After` was obeyed in full, so `Retry-After: 3600` held the scan at that request+ for an hour (and the wait was applied twice). The header is the server's to set, so it is+ now honoured only up to the retry backoff cap (8 seconds); a site asking for longer is+ reported as an error and not asked again.+- Cancelling a scan from code that uses the API (for example with a timeout) left its+ worker tasks running.### Security- **The address check on scraped URLs could be bypassed with a redirect.** Since 2.4.0,diff --git a/src/aliens_eye/core/http.py b/src/aliens_eye/core/http.pyindex 1429db6..a5addd5 100644--- a/src/aliens_eye/core/http.py+++ b/src/aliens_eye/core/http.py@@ -49,13 +49,21 @@ def _should_retry(status: int) -> bool:def _parse_retry_after(headers: dict[str, str]) -> float | None:+ """Seconds the server asked us to wait, when it gave a usable number.++ The date form is treated as absent, as are zero, negative and NaN values.+ Infinity is kept: it is a (very) long wait, which the caller refuses.+ """value = headers.get("Retry-After")if not value:return Nonetry:- return float(value)+ seconds = float(value)except ValueError:return None+ if seconds != seconds or seconds <= 0:+ return None+ return secondsasync def fetch_url(@@ -129,12 +137,22 @@ async def fetch_url(except Exception as exc:error_message = str(exc)+ if retry_after and retry_after > config.backoff_cap:+ # The header is the server's to set, so obeying it lets one site stall+ # a whole scan: "Retry-After: 3600" held a scan of 858 sites at its+ # last request for an hour. Asking again sooner than the site said+ # would only be refused again, so this site is done.+ break+if attempt < config.retries:backoff = min(config.backoff_base * (2 ** attempt), config.backoff_cap)backoff += random.uniform(0.0, config.jitter)if retry_after:backoff = max(backoff, retry_after)await asyncio.sleep(backoff)+ # That sleep was the wait the site asked for. Left set, the rate+ # limiter would sleep for it a second time before the next attempt.+ retry_after = Nonelogger.debug("Fetch failed for %s: %s", url, error_message)return FetchResult(diff --git a/src/aliens_eye/core/scanner.py b/src/aliens_eye/core/scanner.pyindex a821913..b63f640 100644--- a/src/aliens_eye/core/scanner.py+++ b/src/aliens_eye/core/scanner.py@@ -297,10 +297,15 @@ class UsernameScanner:)for _ in range(conn_limit)]- await queue.join()- for worker in workers:- worker.cancel()- await asyncio.gather(*workers, return_exceptions=True)+ try:+ await queue.join()+ finally:+ # Also when the scan itself is cancelled (a caller's timeout):+ # otherwise the workers outlive it, blocked on requests and a+ # queue that nothing will ever drain.+ for worker in workers:+ worker.cancel()+ await asyncio.gather(*workers, return_exceptions=True)finally:view.stop()diff --git a/tests/test_http.py b/tests/test_http.pyindex 50a3632..96c3f2c 100644--- a/tests/test_http.py+++ b/tests/test_http.py@@ -73,3 +73,55 @@ async def test_fetch_still_honours_the_size_cap(dribble_server, logger):config, DomainRateLimiter(), logger,)assert len(result.content.encode()) == 10_000+++# --- Retry-After: the server does not get to decide how long a scan sleeps ----------------+#+# Found in a real scan that sat at 1715 of 2574 checks for over ten minutes: one+# site answered 429 with a long Retry-After, and the scanner slept for all of it.+++async def busy_server():+ app = web.Application()+ hits = []++ async def busy(request):+ hits.append(asyncio.get_running_loop().time())+ return web.Response(status=429, text="slow down",+ headers={"Retry-After": request.query["wait"]})++ app.router.add_get("/busy", busy)+ server = TestServer(app)+ await server.start_server()+ server.hits = hits+ yield server+ await server.close()+++async def fetch_busy(server, logger, wait, **config):+ cfg = ScannerConfig(rate_limit_delay=0.0, jitter=0.0, **config)+ url = f"http://{server.host}:{server.port}/busy?wait={wait}"+ async with aiohttp.ClientSession() as session:+ return await asyncio.wait_for(fetch_url(session, url, cfg, DomainRateLimiter(), logger), 5)++[email protected]("wait", ["3600", "86400", "inf", "1e308"])+async def test_a_long_retry_after_does_not_stall_the_scan(busy_server, logger, wait):+ result = await fetch_busy(busy_server, logger, wait, retries=2, backoff_base=0.0)+ assert result.status == 429 and result.error+ # Asking again sooner than the site said would only be refused again.+ assert len(busy_server.hits) == 1++[email protected]("wait", ["-5", "nan", "soon", "Wed, 21 Oct 2026 07:28:00 GMT"])+async def test_a_meaningless_retry_after_is_ignored(busy_server, logger, wait):+ result = await fetch_busy(busy_server, logger, wait, retries=1, backoff_base=0.0)+ assert result.status == 429+ assert len(busy_server.hits) == 2 # retried on the normal backoff+++async def test_a_short_retry_after_is_honoured_once_not_twice(busy_server, logger):+ await fetch_busy(busy_server, logger, "0.4", retries=1, backoff_base=0.0)+ first, second = busy_server.hits+ assert 0.35 <= second - first < 0.7diff --git a/tests/test_scanner.py b/tests/test_scanner.pyindex c43cbde..8b61d5f 100644--- a/tests/test_scanner.py+++ b/tests/test_scanner.py@@ -204,3 +204,29 @@ async def test_a_challenge_page_is_capped_at_maybe(found_html, tmp_path, logger)# The suffix is only added when the uncapped verdict was Found, so this also# proves the cap is what changed the result.assert result["ai_analysis"]["method"].endswith("-botwall-capped")+++async def test_a_cancelled_scan_leaves_no_workers_behind(tmp_path, logger):+ """Regression: cancelling a scan (a caller's timeout) left its workers pending forever."""+ import asyncio++ app = web.Application()++ async def stall(request):+ await asyncio.sleep(30)+ return web.Response(text="late")++ app.router.add_get("/slow/{username}", stall)+ server = TestServer(app)+ await server.start_server()+ try:+ base = f"http://{server.host}:{server.port}"+ scanner = make_scanner({f"s{i}": base + "/slow/{}" for i in range(4)}, tmp_path, logger)+ before = asyncio.all_tasks()+ with pytest.raises(asyncio.TimeoutError):+ await asyncio.wait_for(scanner.scan_all_sites("torvalds"), 0.3)+ await asyncio.sleep(0.05)+ left = [t for t in asyncio.all_tasks() - before if "_worker" in repr(t.get_coro())]+ assert left == []+ finally:+ await server.close()