Commit Graph
6 Commits
Author SHA1 Message Date
bobbanandClaude Sonnet 5.5 f71756b119 Fix editing and deleting DNS records from the cached list
The records endpoint returned raw cache rows, whose `id` is this app's own row number
(12, 13, ...). The DNS page sends `r.id` back when a record is edited or deleted, so the
provider was handed a row number instead of its record id. That only worked straight after
a manual Sync, whose response carries the provider's ids; after any save or delete the page
reloads from the cache and the problem came back. The ID check added for connected systems
now refuses such an id with "That isn't a valid record ID".

The list now returns records shaped like a sync's: `id` is the provider's record id. Editing
and deleting work from the cached list for every DNS provider.

The test checks the list hands out the provider's id, and that deleting with it reaches
Cloudflare at the right address; with the old shape it fails.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-06 23:45:06 +02:00
bobbanandClaude Sonnet 5.5 2dac273b1d Harden the login flow: new session at sign-in, signed ID tokens, same-origin requests, headers
From an audit of the Authentik login, run against a fake OIDC provider:

- Session fixation: the session id wasn't changed at sign-in, so one planted beforehand
  (from another page on the domain) became signed in as the victim. It is regenerated now.
- Requests from another origin: SameSite=Lax doesn't stop another app on the same parent
  domain, and a body-less POST (stop a guest, rotate a token) needs no preflight. Every
  POST/PUT/PATCH/DELETE, and GET /auth/logout, is refused when Sec-Fetch-Site (or, for older
  browsers, Origin) says it came from elsewhere. The agent endpoint is exempt: it uses a token.
- ID token signature: openid-client checks a token's claims but, as OIDC allows for a token
  from the token endpoint, not its signature, so the login rested on HTTPS to Authentik
  alone. The signature is now verified against the provider's published keys (jose, now a
  declared dependency).
- SESSION_SECRET: production refuses to start without one (the fallback is in the source
  code) and warns when it is the .env.example placeholder or short.
- Response headers: frame-ancestors 'none', X-Frame-Options, nosniff, Referrer-Policy; the
  framework name is no longer sent.
- A failed sign-in shows a plain page and is audited (session / login_failed, with address
  and reason, no tokens); sign-in is limited to 20 attempts a minute per address so the
  audit log and session store can't be flooded.
- A failed OIDC discovery (provider down at the first sign-in) was remembered until restart;
  it is retried now.

Tests run the real app against the fake provider; switching each fix off in turn makes
the matching tests fail.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-06 23:35:34 +02:00
bobbanandClaude Sonnet 5.5 73b86d88de Move the web application into createApp() so tests can run the real middleware order
index.ts builds the app, runs migrations and starts the schedulers in one go, so nothing
could exercise the app without also starting all that. The app itself (middleware order,
session store, routers) is now createApp() in app.ts; index.ts keeps the startup work and
calls it. No change in behaviour. The test that checks the agent endpoint is mounted ahead
of the 100 KB JSON parser reads app.ts instead.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-06 23:35:33 +02:00
bobbanandClaude Sonnet 5.5 5c70956f78 Linux agent unit: keep only the root powers it uses; make unit files readable
The systemd unit now bounds the agent's capabilities to the three jobs it does as root --
reading every user's crontab (DAC_OVERRIDE, DAC_READ_SEARCH), running "crontab -l -u"
(SETUID, SETGID) and naming the program behind each socket (SYS_PTRACE) -- and adds
ProtectClock, ProtectHostname, MemoryDenyWriteExecute and DevicePolicy=closed. It does not
use PrivateDevices, which would hide /dev/log (crontab logs each read there), nor anything
that hides other processes or users, since the agent needs both.

The installer's umask 077 (for the token file) also left the unit files readable by root only;
they now get chmod 644, so "systemctl cat" works for any user.

The test renders the unit through the installer's own heredoc, so a stray backtick or $ would
show up, and pins the capability list: tightening it silently drops tasks or process names.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-06 22:48:50 +02:00
bobbanandClaude Sonnet 5.5 dbbe4180e0 Refuse loopback and metadata targets; check the agent's token before reading its report
Certificate check, WHOIS lookup and port scanner connect to hosts that are typed in
or named by a plain-text reply. utils/networkGuard.ts now refuses loopback, link-local
(cloud metadata) and similar addresses for all three -- and a WHOIS server on a private
network -- and the connection goes to the address that was checked rather than looking
the name up again (no DNS rebinding). LAN hosts remain fine for certificate checks and
scans.

Agent endpoint: the token is checked before the body is read, the route is mounted ahead
of the 100 KB JSON parser so a real agent can send a large report (up to 4 MB), and
overlong text is trimmed instead of costing the host its whole report. An oversized or
malformed body is answered with 413 / 400 instead of a generic 500.

Tests (npm test --workspace server): the guard, the secrets route, the agent endpoint, the
Linux upload run against a fake server (token never on curl's arguments, private temp dir
removed), the systemd unit's directives, and the Windows folder permissions read back by
SID. 19 of the 26 new tests fail against the previous code.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-06 22:05:18 +02:00
bobbanandClaude Sonnet 5.5 a641211484 Stop IDs in a request from being turned into other calls to connected systems
The Tailscale device, Proxmox node, Cloudflare zone/record and Azure record/zone IDs
were put into the outgoing request path as typed. An operator could send a crafted ID
("x/../../tailnet/-/keys/k1") and make the app call a different endpoint than the button
meant -- delete an auth key instead of a device, stop every guest on a node, delete a whole
DNS zone -- under the integration's own credential. Gitea and Dockhand encoded their IDs but
still passed "..".

- utils/pathSegment.ts: checks an ID against what a real one looks like, then encodes it
  (encodeURIComponent alone leaves ".." untouched). Used by the Tailscale, Proxmox,
  Cloudflare, Azure, Gitea and Dockhand adapters.
- The routes refuse a bad ID with a 400 before anything is sent, and the DNS routes turn the
  adapters' refusal into a 400. A server's Proxmox node name is validated when saved.
- Azure: a zone ID without "::" is now refused instead of being cut into two bogus pieces.
- Regression tests (npm test --workspace server, Node's built-in runner): the crafted IDs
  are refused for every adapter and route, real IDs still work, viewers are still refused.
  Against the old code 13 of the 22 tests fail.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-06 21:02:22 +02:00