Files
hoelee 8925d10424 feat(check): seven checks, and the one picture worth having
Adds mail-transport (MTA-STS + policy file, TLS-RPT, BIMI) and hardening (compression,
CAA vs the issuing CA, cookie flags, version banners). Wiring them exposed a real gap:
net-guard pinned accept-encoding to identity, so the compression question could only ever
be answered 'not measured'. requestOnce now takes acceptEncoding, decompresses, and returns
both the wire size and the decoded size - hoelee.com measures 39.6 KB against 119.4 KB.

The hub gets a CSS trust-flow diagram instead of a picture: four boxes and three arrows
cost no request, stay sharp, and can be corrected without re-exporting anything. The
1200x630 social card is drawn in HTML and screenshotted, because a diffusion model renders
'technical' as soft glyph soup that turns to mud at WhatsApp thumbnail size.
2026-11-10 19:20:16 +08:00

82 lines
4.3 KiB
Markdown

# AGENTS.md — hoelee-check
Public health checks for a domain, served at `https://www.hoelee.com/check/`.
Node 24, **zero npm dependencies**, no build step. Read `SPEC.md` before writing code.
## Directory jail
```
src/server.mjs router + static + HTML render (owned by the parent session)
src/lib/net-guard.mjs THE ONLY network entry point — do not bypass it, do not edit it
src/lib/cache.mjs in-memory TTL cache
src/lib/ratelimit.mjs per-IP counters
src/checks/*.mjs one module per check + its .test.mjs sibling in test/
src/i18n/en.mjs all visitor-facing copy
test/*.test.mjs node:test, fake resolver + fake fetcher, never the real network
```
A check module may import `src/lib/net-guard.mjs`, `src/lib/cache.mjs` and node builtins. It must not
import `node:http`/`node:https` directly, must not use the global `fetch`, and must not open sockets.
## Hard rules
1. **No npm dependencies.** No Fastify, no mailauth, no better-sqlite3, no dotenv. `package.json`
keeps `"dependencies": {}` and the lockfile stays absent.
2. **Every network call goes through `net-guard`.** A `fetch()` anywhere in this repo is a bug: it
cannot pin the resolved IP, which is the whole SSRF defence.
3. **No query log, no analytics, no third-party request.** Not even a font. The about page promises
this and a visitor can verify it in DevTools.
4. **`not-evaluated` is a first-class state.** A WAF answering 403, a timeout, a SERVFAIL — none of
them is a finding against the visitor's site. Render it neutral (slate, no red, no "!"), and count
it separately in the summary ("2 verified, 1 skipped by firewall").
5. **Never claim what the data cannot support.** The exact wording rules are in `SPEC.md` §5; the
seven that get broken most often:
- DKIM: "No key found among the 13 common selectors; a custom selector cannot be found from DNS alone."
Never "DKIM is not configured".
- TLS: judge signature algorithms on the **leaf and intermediates only** — RFC 5280 exempts a
trust anchor, so a SHA-1 root is not a failure.
- HTTP headers: a missing CSP or Permissions-Policy is **"optional hardening not present"**, not
"insecure". Only a broken redirect chain or malformed HSTS is a failure.
6. **No redundant connections.** The certificate comes off the same socket as the HTTPS request
(`requestOnce` already returns `.tls`); when a site redirects, the certificate at the final
address is read from that redirect's own socket rather than a fresh handshake. The only extra
traffic allowed is bounded and named: up to five HEAD hops with no page body to find where a
redirect lands, and one HEAD for the declared `og:image`. If you add a sub-request, say why and
cap it.
7. **Cache before you scan.** A shared report URL is prefetched by WhatsApp/Telegram, so a cached
report is served without touching the target. Negative and warning results cache for 5 minutes;
clean results for 1 hour.
8. **Tests never touch the network.** Inject `lookup` (DNS) and pass fixture objects into the pure
analysers. `npm test` must pass with the machine offline.
## Checks contract
```js
// every check module exports exactly this
export async function check(input, { lookup, now = Date.now(), cache } = {}) -> {
id: 'who-holds' | 'mail-auth' | 'mail-transport' | 'tls' | 'http' | 'host-shape' | 'hardening',
state: 'ok' | 'warn' | 'fail' | 'not-evaluated',
summary: string, // one plain-English line for a non-technical owner
evidence: Array<{label, value, note?}>,
findings: Array<{level: 'ok'|'info'|'warn'|'fail', code, message, fix?}>,
checkedAt: string, // ISO
fromCache: boolean
}
```
Export the pure analysers too (`parseSpf`, `summariseTls`, `analyseHttp`, …) so tests can hit them
directly. `state` is the worst finding level, and `not-evaluated` wins over everything.
## Commands
```
npm test # node --test "test/*.test.mjs"
node src/server.mjs # http://127.0.0.1:8088
```
## Deployment
Docker image `node:24-alpine`, no host port; `nginx-www-hoelee` proxies `location ^~ /check/` to
`http://hoelee-check:3000`. The nginx location must carry `access_log off;` — an access log of
`/check/report/<domain>` would be exactly the query log the site promises not to keep.