Sprint 014 — API Discovery & API Attack-Surface Intelligence: Implementation Plan

1. Objective

Add a Wave-8 intelligence capability that discovers, classifies, models, correlates and historically tracks the API attack surface of authorized assets. It consumes the intelligence already produced by Wave-1..7 (web crawl, JavaScript, technology fingerprinting, live-host, DNS, topology, recon) and the historical TIDB surface, and produces a canonical, evidence-backed API inventory persisted to the TIDB, projected into the existing topology, emitted as api.* events, and exposed through a reporting query service.

Non-negotiable boundaries: discovery and intelligence only. No exploitation, no auth bypass, no credential handling, no unbounded crawling, no state-changing probes. Scope is enforced at target admission and per-observation persist.

2. Guiding constraints (from the mission brief)

3. Pipeline architecture

ApiService.run() orchestrates the phases below; phases publish api.phase.started events; failure publishes api.intelligence.failed.

  1. Scope admissionApiScopeEnforcer.allows_target(); reject out-of-scope.
  2. Collection — run each selected registered tools/api adapter through the ExecutionEngine; each adapter yields canonical APIObservation records under the pipeline payload key apis.
  3. Existing intelligence fold-in — convert web crawl endpoint/websocket/ graphql/auth-boundary observations, JS endpoint/route hints, technology observations (framework/api-style), and previously persisted TIDB records.
  4. ClassificationApiClassifier assigns ApiKind (REST, GraphQL, WebSocket, SOAP, RPC, Unknown) + API surface form (OpenAPI spec, Swagger, undocumented, GraphQL SDL, WSDL, etc.) with deterministic confidence.
  5. OpenAPI/Swagger modeling — in-process parser normalizes OpenAPI 2/3/3.1 into canonical operations/parameters/schemas/auth; GraphQL SDL + schema shape analysis; WebSocket endpoint modeling; WSDL → SOAP operations.
  6. ValidationApiValidator filters invalid/empty records; drops out-of-scope observations.
  7. CorrelationApiCorrelator groups observations into canonical APIs and hosts; merges duplicate endpoints; resolves version/identity conflicts.
  8. Confidence scoringApiConfidenceEngine per-observation deterministic score combining evidence strength, source weight, corroboration.
  9. History diffingApiHistory.compare(historical, current) yields added/removed/changed events (ApiChange).
  10. Persistence — write API/version/operation/parameter/schema/auth/rate-limit /evidence/conflict/change/run entities to the TIDB.
  11. Topology projection — derive EXPOSES/SERVES/ROUTES_TO edges (host → API/endpoint, origin → API, URL → endpoint).
  12. Events + summary — emit api.* events; publish api.intelligence.completed.

ApiQueryService reads the TIDB and answers the reporting queries (inventory, by-host, versions, endpoints, undocumented, historical, spec, auth, changes, conflicts, run history).

4. Implementation order

# Area Files
1 TIDB entities + ORM + migration + registry domain/entities/tidb/api.py (extend), new domain/entities/tidb/api_intelligence.py, infrastructure/db/sql/tidb_models/api_intelligence_models.py, tidb_models/__init__.py, alembic/versions/...api_intelligence_tables.py
2 Events domain/events/enums.py (add API), catalog.py, types.py (typed constructors)
3 Domain models domain/api/models.py, classification.py, scope.py, confidence.py, correlator.py, conflicts.py, history.py, strategy.py, validator.py, parsers/ (openapi.py, graphql.py, websocket.py, soap.py, postman.py, hints.py)
4 Tool adapters tools/api/{base,openapi,swagger,graphql,websocket,soap,hints,registry,tip,__init__}.py
5 Application service application/api.py (ApiService, ApiQueryService)
6 Wiring platform/assembler.py, platform/platform.py, config/capabilities/api-intelligence.json
7 Docs docs/v7-api-intelligence.md, this plan, TIDB gap report
8 Golden + tests tests/golden/api/, tests/unit/test_api_*.py, tests/integration/test_api_platform.py, tests/acceptance/test_api_acceptance.py, tests/security/test_api_security.py, tests/performance/test_api_benchmarks.py

5. Key contracts

5.1 TIDB entities (canonical inventory)

New entities (full list + columns in the gap report):

Extensions to existing domain/entities/tidb/api.py: no breaking changes; the existing API, RESTEndpoint, GraphQLEndpoint, SOAPEndpoint, RPCService, AuthenticationScheme, AuthorizationModel entities are kept and reused by the service when mapping documented surfaces, while the new api_intelligence entities carry the full Wave-8 canonical inventory. The gap report documents exactly which columns are added.

5.2 Events (api.*)

API = "api" category. Specs + typed constructors (see catalog patch):

5.3 Domain model summary

5.4 Tool adapters (all in-process)

Registry ids under API_TOOL_IDS: api-openapi, api-swagger, api-graphql, api-websocket, api-soap, api-hints (web-crawl + JS fold-in). All extend a shared ApiToolAdapter; in-process variants implement run() (no CLI) and parse_output() returns []. The api-hints adapter is the fold-in path that maps already-persisted web/JS observations (no network). api-openapi/api-soap fetch the spec document through the existing injectable FetchFn seam (like tools/tech/signature.py) with a cache TTL; api-graphql/api-websocket derive shape from existing web/JS observations + optional fetched SDL.

TIP: register_api_tools(tip) registers the six specs, reusing capability id api-discovery from the taxonomy.

5.5 Application service

ApiService.__init__ mirrors FingerprintService: engine, stores, event_bus, cache, scope, strategy_builder, classifier, parser, correlator, conflicts, validator, history, confidence. run() performs the phase pipeline above. ApiQueryService mirrors TechnologyQueryService (inventory, by_host, versions, endpoints, undocumented, historical, spec, auth, changes, conflicts, runs).

5.6 Platform wiring

6. Scope & security behavior

7. Performance targets

8. Quality gates (all must pass)

9. Risks / mitigations