Files
BetterDesk/docs/security
UNITRONIX 790b65fd32 fix(enrollment): keep stock clients and Support Agents able to enroll (C1 follow-up)
Hardening device registration must not lock out the clients the product is built
for. Stock RustDesk clients and Support Agents cannot produce an Ed25519
signature, so `POST /api/bd/register` now accepts three equivalent proofs of
admission instead of demanding a signature:

1. an `approved` row in `pending_registrations` for this exact device id
   (operator clicked Approve in the Registrations tab),
2. a single-use enrollment token issued by `POST /api/bd/enroll`,
3. an Ed25519 proof of possession of the key being bound.

Banned and soft-deleted ids are still refused before any write, and an existing
device's key/uuid can only be rotated by the key it already has — admission
proves identity, not ownership of an established identity. The refusal is a
single neutral error (`403 enrollment_proof_required`) so a caller cannot probe
which admission method is missing.

Verified end to end on the test host: register before approval -> 403
enrollment_proof_required; register-request -> pending; operator approval;
register with no signature -> 200; template + enroll -> 200; register with the
token -> 200; a second device reusing the same token -> 403.

Also fixed, because it silently broke this same model:

- `POST /api/bd/enroll` and the agent-template tab called `db.get()` /
  `db.query()`, which the database facade never exposed, so every enrollment
  token answered 401. Added `listAgentTemplates` / `getAgentTemplateByToken` /
  `createAgentTemplate` to both adapters and `lib/agentTemplates.js`.
- PostgreSQL installs had no `agent_templates` table (it only existed in SQLite
  auth.db). It is now created by the adapter schema on both backends with
  `enrolled_device_id` / `enrolled_at`, so a token is single-use and bound to one
  device.

Tests: `tests/bd-register.enrollment.test.js` (8 cases covering approval,
pending, rejected, token, token reuse, no-admission, later heartbeats and
removed devices) plus the existing hardening suite (11 cases).

Thanks: INSOLVE (Honorary); Marco Jakobs (@jacotec); MyNameisStitch (@MyNameisStitch); Redspin (@playerumpknow); muopc (@muopc)
2026-11-13 21:45:07 +01:00
..