> Agent-ready spec from Diff of the Day (2026-12-04, idea 2). Give this file to your coding agent (Claude Code, Codex, Cursor) and ask it to build the P0 requirements first.

# Spec: Route-sweep detector for API access logs

## Problem Statement
Perplexity describes an autonomous agent that swept about 28,000 guessed routes with about 48,000 requests in 13 minutes, and rotated through more than 40 throwaway accounts and about 290 proxy addresses. Rate limits per account did not group the activity; correlation across accounts did. A small team with plain access logs has no view of this kind of sweep.

## Goals
- Flag bursts where many distinct unknown routes return 404 in a short window.
- Group requests from different accounts and IPs into one campaign by shared traits.
- Report each campaign with start, end, request count and the routes it tried.
- Process one day of logs for a small service in under one minute.

## Non-Goals
- Blocking traffic: the first version only reports, so a false alarm cannot cause an outage.
- A hosted dashboard: a Markdown or JSON report is enough to start.
- Detecting every attack type: the focus is route sweeps and metadata-URL probes.

## User Stories
- As a solo API owner, I want a daily list of sweeps so that I know when an agent is mapping my API.
- As an on-call engineer, I want requests grouped into one campaign so that rotating accounts do not hide it.
- Edge case: a legitimate crawler or a client after a deploy also makes many 404s; the report shows its user agent so a person can allow it.

## Requirements
### P0
- [ ] Parse common access-log formats (nginx combined and JSON lines). Accept: a sample file parses with zero errors.
- [ ] Flag windows where distinct 404 routes exceed a set threshold. Accept: a synthetic sweep of 1,000 routes in 5 minutes is flagged.
- [ ] Write a report with time range, counts and top routes. Accept: the report opens as Markdown.
### P1
- [ ] Group sources into campaigns by user agent, timing and route overlap. Accept: a test with 20 rotating IPs yields one campaign.
- [ ] Flag request parameters that point at cloud metadata addresses or internal hosts. Accept: a test request with a metadata URL is flagged.
### P2
- [ ] Send a short alert to a webhook you choose. Accept: one message per campaign, not per request.

## Success Metrics
- Synthetic sweeps are caught in all test cases.
- Fewer than 2 false campaigns per day on real logs after tuning.
- A real campaign is visible within 15 minutes when run on a schedule.

## Open Questions
- Which fields do the logs keep (account id, user agent, full query string)?
- How long are logs kept, and can a week be replayed for tuning?

## Timeline
- One evening: parser, 404-burst detection and report; grouping if time allows.

## Agent Instructions
- Stack: Python 3 or Go, reading files only; no database needed at first.
- Build order: parser, window counter, report, grouping, metadata-URL check.
- Safety: logs can hold personal data and tokens in query strings; mask query values in the report and keep everything local.
- Done when: all P0 acceptance checks pass on synthetic and one day of real logs.

## Sources
- Perplexity, How Perplexity defended against an autonomous AI attacker, https://www.perplexity.ai/hub/blog/how-perplexity-defended-against-an-autonomous-ai-attacker
