Architecture
ShorSighted is a one-way pipeline. Each layer hands the next a typed model
(src/shorsighted/models.py, src/shorsighted/sources/inventory.py), so each
can be tested alone. Adding a discovery source means adding one collector that
returns an Inventory and, if it has configuration to judge, one config check.
Pipeline
flowchart TD S["<b>1 · Sources</b><br/>args · files · stdin · config<br/>AWS · Azure · GCP · MCP configs"] T["<b>2 · Targets</b><br/>normalize · mail discovery · dedupe"] P["<b>3 · Probes</b><br/>DNS · STARTTLS · ClientHello<br/>chain fetch · SSH KEXINIT"] C["<b>4 · Checks</b><br/>probe checks + config checks"] E["<b>5 · Engine</b><br/>deadlines · escalation · grades"] R["<b>6 · Reports</b><br/>table · json · jsonl · csv<br/>sarif · markdown · html · exit code"] S -- "RawInput" --> T T -- "Target" --> P P -- "ProbeResult" --> C S -. "Fact (config only, no network)" .-> C C -- "Finding" --> E E -- "ScoredFinding" --> R
| Stage | What it does | Code |
|---|---|---|
| 1. Sources | Turn CLI args, target files, stdin and shorsighted.yaml into RawInputs. Cloud and MCP collectors also return Facts (configuration that is judged without probing). | sources/args.py, files.py, stdin.py, configured.py, aws/, azure.py, gcp.py, cloud/, mcp.py |
| 2. Targets | Lowercase and IDNA-encode hosts, resolve ports and protocol (TLS, SSH, STARTTLS), expand mail:// / mx:// into MX and SRV hosts, and dedupe on protocol + host + port + SNI while keeping provenance. | targets/normalize.py, mail.py, dedupe.py, and the top-level protocols.py |
| 3. Probes | An async scheduler (global, per-host and per-IP limits, rate, resume) resolves each target and runs, per IP: the STARTTLS upgrade if needed, the raw ClientHello key-exchange probe, the chain fetch with trust-store verification and interception detection, or the SSH banner + KEXINIT read. | probe/scheduler.py, resolve.py, starttls.py, kexprobe.py, clienthello.py, parser.py, chain.py, truststore.py, interception.py, ssh.py |
| 4. Checks | Pure functions. Probe checks (SSD-KEX, SSD-CHAIN, SSD-LIFE, SSD-TLS, SSD-SSH) read a ProbeResult; config checks (SSD-AWS-CONFIG, SSD-CLOUD-CONFIG, SSD-MCP) read an Inventory. | checks/base.py (registry), one module per check |
| 5. Engine | Attach the nearest matching deadline, escalate severity as it approaches, grade each target A–F, and add catalog remediations. | engine/deadlines.py, scoring.py, remediations.py, clock.py, data/deadlines.yaml, data/remediations.yaml |
| 6. Reports | Render the Report in the requested format and set the exit code. | report/registry.py, one module per format |
Design rules
- Discovery never probes, and probes never know about clouds. A collector
returns an
Inventory:RawInputs that become probe targets, andFacts that config checks read. The probe layer only sees hosts and ports. - Checks are pure functions with no I/O. Probe checks take a
ProbeResult, config checks take anInventory, and both get aCheckContext(deadlines and the evaluation instant). Both kinds register inchecks/base.py, so the CLI runs whatever is registered and does not import individual checks. - Read-only by construction. AWS calls are Describe/List/Get. Azure and
GCP go through one GET-only HTTPS client that never follows redirects, so a
bearer token cannot be forwarded to another host; the only POST is the OAuth
token request in
sources/cloud/auth.py. MCP config values are redacted to scheme, host and port before anything is stored; the only MCP request is one GET of/.well-known/oauth-protected-resourceper server origin. - The engine owns time. Only
shorsighted.engine.clockreads the date, through an injectablenow(), and checks receive “now” as data. (Cloud credential caching insources/cloud/auth.pyusestime.time()for token expiry, which never affects findings.) - Reporters are plugins registered by format name in
shorsighted.report.registry. Adding a format means adding one module and listing it in_BUILTIN. - Failure isolation. A target’s DNS or TLS error becomes a
ProbeResultwith an error status, never an exception that stops the batch. One cloud service’s access-denied becomes a warning. Errors the user can fix (SourceError,ConfigError,CredentialError, …) exit 2 with a message; anything else is a bug: a traceback and exit 3.
Why the KEX probe does not use ssl
The OpenSSL linked into Python differs by platform (python.org builds for
Windows and macOS have shipped OpenSSL 3.0.x, which cannot negotiate ML-KEM).
To get the same verdict everywhere, SSD-KEX sends a hand-built TLS 1.3
ClientHello (probe/clienthello.py) and parses the ServerHello /
HelloRetryRequest itself (probe/parser.py). A test asserts the KEX path never
imports ssl.
The chain fetch (probe/chain.py) does use ssl, because it only needs the
certificates the server presents, which every OpenSSL version can retrieve.
Verification is done with cryptography against the selected trust store, not
by the platform’s OpenSSL.
SSH
SSH targets (ssh://host, host:22, protocol: ssh in files, or EC2
instances whose security groups open port 22 to the internet) go through
probe/ssh.py. RFC 4253 has both sides send an identification string, and the
server then sends its SSH_MSG_KEXINIT in plaintext. That lists every
key-exchange, host-key, cipher and MAC algorithm it supports. ShorSighted reads
that one packet and closes the connection, so it never authenticates, never
completes a key exchange, and needs no credentials.
SSD-SSH maps mlkem768x25519-sha256 (OpenSSH 9.9+, the default from 10.0) to a
pass, sntrup761x25519 to low (post-quantum, but not FIPS 203), and
classical-only to high, attached to the same KEX deadlines as TLS.
STARTTLS and mail
Targets whose protocol is smtp, imap, pop3, ftp, ldap, postgres,
xmpp or xmpp-server (set by scheme, by well-known port, or by protocol:
in a file; table in protocols.py) go through the same TLS path with one
extra step. probe/starttls.py runs the protocol’s plaintext upgrade dialogue
on the open socket, and the raw ClientHello is written to that same
connection. Like the rest of the KEX path, starttls.py doesn’t import ssl.
The chain fetch performs the same dialogue and then calls
StreamWriter.start_tls.
STARTTLS failures are distinct NetError kinds (starttls_not_offered,
_rejected, _protocol, _closed). not_offered is a definite answer: the
service speaks plaintext only, which SSD-TLS reports as high. The others are
inconclusive, like any network error. Each failure stops after a single
ClientHello attempt.
ALPN: web endpoints offer h2, http/1.1. STARTTLS and implicit-TLS mail
ports offer no ALPN, because RFC 7301 lets a server abort with
no_application_protocol when none of the offered protocols is its own, and
Dovecot 2.4 does exactly that. If any target answers with that alert, the
probe retries once without ALPN and keeps it off for the rest of that target.
mail://domain and mx://domain are placeholders. After normalisation,
targets/mail.py replaces them with MX hosts (SMTP/25) and, for mail://,
RFC 6186 SRV services. It runs before scheduling, so the expanded endpoints go
through the usual dedupe, per-host limits and resume. Route53 MX records
become SMTP targets directly.
Deadline engine
- All dates live in
src/shorsighted/data/deadlines.yaml; users can merge or replace them with--deadlines FILE [--replace-deadlines]. - A finding either names a
deadline_idor a category (applies_to). The engine picks the nearest upcoming deadline in that category whoserulematches the finding. days_untildrives escalation: frommax(base, severity_before)the severity rises one level at each threshold crossed (180, 90, 30 days by default), capped atseverity_after, which applies on and after the date.- Unverified deadlines are shown with
(unverified)and are excluded from--fail-onunless--include-unverified. - Computed consequences (for example “a 90-day certificate from a P-256 CA
issued on or after 2026-12-15 outlives the Chrome distrust date”) are derived
from
rule.cutoff_lifetimes_days, not stored as separate deadlines.