Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,60 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.1.0] - 2026-11-30

Fixes of the security and load audit of 2026-11-30 (findings 1-11 and 13-15; 12 and 16 are not part of this release).

### Security
- **Batch cross-check requests no longer resolve DNS on the database pool.** `_parse_batch_targets` checks the format and literal addresses only; the name is resolved, validated and pinned by `run_single_check` (asynchronous, under the 30 s check deadline), and a name that resolves to a private address still never gets a connection and is answered as a skip. Before, one peer sending batches of slow-DNS names could hold all 10 database workers (about 5 s per target) and starve every check, alert and the scheduler's own database calls.
- **Admin commands need an encrypted message and a stored key.** `_is_dc_admin` refuses a message without a padlock, also when a fingerprint is stored (a forged mail from the admin's address carries no key, but the core still has the contact's key). When only the admin's address is stored (`set_admin.py --email`, `ADMIN_DC_EMAIL`, a `/initadmin` before the key was known), the key of the **first encrypted message from that address** is bound as the admin's key and the admin is told in the reply and in the stored admin chat, and the bind is logged at ERROR with the address; from then on only that key counts. Setups that already have a fingerprint (de2) are not locked out. Unencrypted admin commands (an unencrypted group) are refused now.
- **Limits against amplification** for every sender but the admin: at most `MAX_MONITORS_PER_HOST` (10) monitors of one host per chat and `MAX_MONITORS_PER_SENDER` (500) monitors per sender over all chats (new column `resources.added_by`, the sender's address). Existing monitors are never removed or paused. Targets mirrored from peers are checked at most `PROBE_ONLY_PER_HOST_PER_MINUTE` (6) times a minute per host, and at most `MAX_PROBE_TARGETS_TOTAL` (2,000) of them are active over all peers (the per-peer cap of 200 stays).
- **`BOT_SYNC_DATA`** has the per-sender command budget (30 a minute, like a command), the per-host and per-sender limits, and refuses private and local targets (`is_safe_target_url`, format only). HELLO, HELLO_ACK, CHECK_REQ and CHECK_RESP payloads above 16 KB are dropped before `json.loads`; CHECK_BATCH_REQ and CHECK_BATCH_RESP above 512 KB are dropped, and their sender is verified before the JSON is parsed (they were parsed up to 8 MB first). An unencrypted HELLO or HELLO_ACK matched to a peer by address alone no longer moves that peer's chat.
- **Status page and status app show `redact_url(url)`** (credentials and secret query values are removed); a status link is made to be shared.
- **Mirrored probe targets cannot be taken over:** a second peer sending a URL that another peer still sends (seen in the last day) no longer changes how it is checked. Every peer that asks for a URL is recorded (new table `probe_target_requesters`, filled from `probe_targets` when a 3.0.9 database is opened) and gets this node's results for it; the 200-per-peer cap is counted per requester, and a URL some peer already asked for costs no slot of the 2,000 total. Telemetry reads the requesters in one query per pass. The first peer to send a URL keeps its `type` and `expected_keyword` for as long as it asks for the URL itself (its own request seen in the last day, whatever other peers send); once it has been silent for a day the next peer that sends the URL takes the settings over. A peer that sends a URL first can therefore pick how it is checked while it keeps asking; it cannot redirect the results of the others.

### Fixed
- **Outbox in the watchdog.** A fourth heartbeat, "outbox", beats before every job and every 30 s while the queue is empty, so it ages only while a send never returns (`rpc.send_msg` has no timeout). Before, one stuck send stopped all alerts and replies silently while the scheduler, audit and probe kept the process "alive".
- **Telemetry:** a message with up to 200 metrics did one blocking DNS lookup per metric (10 s deadline, failures not cached, overload dropped the metrics as "unsafe"). Metrics are now checked for format and literal addresses only; the probe resolves and validates at connect time.
- `_admin_contact_id` caches "not found" for 5 minutes (a changed admin or key is looked up at once). Before, an admin key contact the core did not know made every 30 s telemetry tick read all contacts (2 RPC calls each).

### Changed
- **Status apps (`push_status_apps`, every 30 s):** one query for all chats' rows and settings, one `get_existing_msg_ids` for all apps, name and member count from a 10-minute cache, and a chat whose inputs (dirty revision, monitor states, node votes, sent hash and time) are unchanged since its last full evaluation, which found nothing to send, is skipped without a query or an RPC call, and is evaluated again every 30 to 40 minutes (`STATUS_REFRESH_SECONDS` plus a per-chat offset of up to 10 minutes, so the chats of one pass do not come due together), whenever it was last sent, and at the moment its 30-minute full-state refresh becomes due. Name and member count are read from the core every 10 to 20 minutes per chat (10 minutes plus a hashed offset), and when only that cache has expired and the name is unchanged no state is built. Without that spread the first version of 3.1.0 built a full state for every chat in one pass about every 10 minutes (peaks of 537 connections and 215 RPC calls with 200 chats). A chat rename shows up within 10 to 20 minutes (it was noticed on the next 30 s pass).
- `trim_user_chats` runs hourly (was every 10 minutes; about 2 RPC calls per chat per pass over every chat the bot ever had). The peer-chat, hidden-update and app-retire trims keep their 10 minutes.
- Cached for 10 s (and reset at once when the alert mode, share scope, admin chat or a peer changes): peer list, chat alert mode and share scope in `_quorum_resource_ids` (they were read per failing target on every check). The stale-downtime evaluation runs once an hour per monitor (it ran after every failed check; its thresholds are days). The status page reads the peer measurements of all monitors in one query (one per monitor before). A batch answer reads the `/probeignore` list once (once per target before).
- Writes that ran on the event loop go to the database pool or a background writer: the peer activity stamp of a cross-check request, the held-report state and the ping baselines. The ping dictionaries are written on the loop only (the baseline is read on a thread and cached on the loop, the dirty queue is taken in one step before it is stored), so a value written during a store is kept.
- **Ping baselines** are written in one transaction every 10 s (one transaction per ping check that moved the average by 0.5 ms before), rows not updated for 30 days are deleted in the daily cleanup (a steady baseline is re-stamped daily), and `_ping_baseline_cache`, `_ping_bad_streaks`, `_path_traces` and `_path_trace_tasks` are bounded (5,000 / 5,000 / 2,000 / 200).

### Wire
- No change to the peer protocol or the app: every message and field is as in 3.0.9, so 3.0.9 and 3.1.0 nodes work together in any order. A 3.0.9 peer asking for a URL that a 3.1.0 node already probes for another peer now gets this node's results for it too (3.0.9 gave them only to the last writer); the 3.1.0 node needs nothing from the peer for that, and a 3.0.9 node receiving them is unchanged. What changes is behaviour on the receiving side: 3.1.0 answers a batch target whose name resolves to a private address with a skip (3.0.9 refused it at parse and answered "Target refused", also a skip), and ignores a second peer's version of a target another peer still sends. A 3.0.9 peer that sends a CHECK_REQ/HELLO above 16 KB (none does; real ones are a few hundred bytes) would be ignored by 3.1.0.

### Known limits
- The notice of a first-use admin key bind reaches the real admin only when `admin_chat_id` already points to the admin's chat; the ERROR log line is the reliable signal. This is inherent to binding the key on first use; set the fingerprint with `set_admin.py --fingerprint` to avoid it.
- The per-sender and per-host monitor caps can be got around with many sender addresses or a wildcard domain (the host is the name, not the IP). They raise the cost of amplification; they are not a hard bound. Names that resolve to private addresses are kept as mirrored targets; their lookup is cached by the DNS cache and bounded by the per-host rate.

### Configuration
- New: `MAX_MONITORS_PER_HOST`, `MAX_MONITORS_PER_SENDER`, `MAX_PROBE_TARGETS_TOTAL`, `PROBE_ONLY_PER_HOST_PER_MINUTE` (defaults above; passed by `docker-compose.yml`). Documented in the README.

### Load
Generated dataset (`python -m tools.loadbench.release310`, run on 3.0.9 and on 3.1.0, same Mac, 200 status-app chats of 3 monitors, 150 failing targets, 100-target batches, 200 metrics, 300-monitor page, 1,000 pinged addresses, 500 chats; DNS stubbed at 5 ms a lookup):

| Path | 3.0.9 | 3.1.0 |
|---|---|---|
| Status apps, 200 chats, steady 30 s pass, last sent 10 min ago: database connections / RPC calls / CPU | 2,001 / 600 / 162 ms | 2 / 1 / 9 ms |
| Status apps, 200 chats, steady 30 s pass, last sent 66 min ago (nothing changed, nothing sent): connections / RPC calls / CPU | 2,001 / 600 / 171 ms | 2 / 1 / 9 ms |
| Same chats over 61 minutes of 30 s passes, first pass after a start: connections / RPC calls | 2,001 / 600 | 802 / 401 (every chat is evaluated once and its name read) |
| Same, later passes: connections median / average / peak | 2,001 / 2,100 / 2,201 | 2 / 10.3 / 67 |
| Same, later passes: RPC calls average / peak | 600 / 600 | 13.2 / 65 |
| Peer batch of 100 targets: DNS lookups on the database pool / time on one worker | 100 / 724 ms | 0 / 1 ms |
| Telemetry message of 200 metrics: DNS lookups / handling time | 200 / 1,416 ms | 0 / 5 ms |
| 150 failing targets, one check each: database connections / CPU | 450 / 179 ms | 7 / 58 ms |
| Status page of 300 monitors: database connections | 301 | 2 |
| First ping sample of 1,000 addresses: write transactions / CPU | 1,000 / 31 ms | 1 / 10 ms |
| User chat trim, 500 chats: core RPC calls per hour | 6,000 | 1,000 |
| Admin key contact unknown (100 contacts): core RPC calls per hour | 12,240 | 1,224 |

Production size (about 150 targets, 8 peers, 7 status-app chats, journal 1-2k rows a day) is far below these; the status-app pass costs the same 2 queries and 1 RPC call for 7 or 200 chats. `tests/test_release_310.py` has a scale test for each path that fails on 3.0.9. New work per timer: the outbox thread wakes every 30 s when idle (one dictionary write); the ping baseline flush runs with the 10 s transport flush and does nothing when nothing changed; the new status-app signature parses the vote JSON of all status-app monitors once per 30 s (at most 3,000 rows in total). A py-spy profile of de2 and ru against the saved baseline, and the CPU checks 1 h and 24 h after deploy, follow the release.

## [3.0.9] - 2026-11-29

### Fixed
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Additionally, it automatically generates a secure, beautiful web status dashboar

## Features

- 🛡️ **Secure Administration:** Claim ownership with `/initadmin` via private chat when no owner is configured in the database or environment. Once an admin fingerprint is configured, commands require that exact key; an unavailable sender fingerprint is refused and logged at most once per sender per hour. Email-only matching applies while no fingerprint is configured.
- 🛡️ **Secure Administration:** Claim ownership with `/initadmin` via private chat when no owner is configured in the database or environment. Once an admin fingerprint is configured, commands require that exact key; an unavailable sender fingerprint is refused and logged at most once per sender per hour. Admin commands also need an end-to-end encrypted message (a forged mail from the admin's address is refused). While only the admin's address is configured, the key of the first encrypted message from it is bound as the admin's key and the admin is told.
- 💬 **Per-Chat Isolation:** Each chat (private or group) maintains its own separate list of monitored resources.
- 🚨 **Incident-Based Alerting & In-Place Dynamic Updates:**
- Instead of flooding the chat with dozens of separate DOWN/UP messages, outages trigger a unified **Incident** per chat.
Expand Down Expand Up @@ -310,12 +310,14 @@ You can customize the bot's name, avatar, and status text by passing environment
- `AVATAR_PATH` — Path to an image file (PNG/JPG) to use as the bot's profile avatar (default: falls back to `icon.png` or `icon.jpg` in the project root).
- `MAX_MONITORS_PER_CHAT` — Maximum monitors when adding to a chat (default: `300`).
- `MAX_MONITORS_TOTAL` — Maximum monitors when adding across the bot (default: `3000`). Existing monitors keep running if either limit is lowered below the current count; these settings never delete or pause monitors.
- `MAX_MONITORS_PER_HOST` — Maximum monitors of one host per chat for senders other than the admin (default: `10`). `MAX_MONITORS_PER_SENDER` — Maximum monitors one sender added over all chats (default: `500`). Neither removes existing monitors, and the admin is exempt. `/sync` data from another bot counts too.
- `PROBE_ONLY_PER_HOST_PER_MINUTE` — Checks per minute against one host for targets that peers asked this node to probe (default: `6`); `MAX_PROBE_TARGETS_TOTAL` — active mirrored targets over all peers (default: `2000`, at most 200 per peer).
- `UPTIME_CPUS` — CPU cap of the container, read by `docker-compose.yml` (default: `1`). On a host with 2 or more cores, `2` is recommended: at a cap of 1 core the container was throttled about 23 periods a minute on de2 and peer votes timed out; at 2 the throttling dropped to near zero. Docker refuses a cap above the number of cores of the host, so the default stays `1`.
- `UPTIME_WATCHDOG_SECONDS` — Watchdog limit, read by `docker-compose.yml` (default: `900`). When the scheduler loop, the 30-second audit or the Delta Chat core (probed once a minute) is silent for this long, the bot writes the stacks of all threads to the log and exits with code 70, and Docker restarts it. `0` turns the watchdog off. `docker kill -s USR1 deltachat_uptime_bot` dumps the stacks on demand (also with the watchdog off). A core start that takes longer than the limit (a very long database migration) would be restarted in a loop: raise the limit then.
- `UPTIME_WATCHDOG_SECONDS` — Watchdog limit, read by `docker-compose.yml` (default: `900`). When the scheduler loop, the 30-second audit, the outbox thread (stuck inside a send) or the Delta Chat core (probed once a minute) is silent for this long, the bot writes the stacks of all threads to the log and exits with code 70, and Docker restarts it. `0` turns the watchdog off. `docker kill -s USR1 deltachat_uptime_bot` dumps the stacks on demand (also with the watchdog off). A core start that takes longer than the limit (a very long database migration) would be restarted in a loop: raise the limit then.
- `UPTIME_AUDIT_TIMEOUT_SECONDS` — Deadline of one 30-second audit pass, read by `docker-compose.yml` (default: `120`, `0` = no deadline). A pass that does not finish (a stuck core call) is abandoned and retried after a growing pause (60 s up to 10 min).
- `TRUSTED_PROXIES` — Comma-separated proxy IPs/CIDRs allowed to supply `X-Forwarded-For` (default: `127.0.0.0/8,::1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16`). The right-most untrusted address in that chain identifies the client. Headers from other socket peers are ignored; an empty setting disables forwarding-header trust.

New monitor inputs are limited to 2,048 characters for URLs, 100 for names and 200 for keywords, including sync and peer inputs. Automatically derived names are shortened to 100 characters. Incoming sync JSON is capped at 64 KiB; peer protocol messages at 8 MiB, enough for the largest 200-entry telemetry batch with maximum-length Unicode fields escaped by JSON. Non-admin senders can run 30 commands per minute per chat (sliding window); excess commands are silently dropped after one “Slow down” reply per minute per chat. Admins are exempt, and `/ping` checks its existing 15-second chat cooldown before validation or DNS.
New monitor inputs are limited to 2,048 characters for URLs, 100 for names and 200 for keywords, including sync and peer inputs. Automatically derived names are shortened to 100 characters. Incoming sync JSON is capped at 64 KiB; peer protocol messages at 8 MiB (HELLO, HELLO_ACK and single cross-check messages at 16 KB), enough for the largest 200-entry telemetry batch with maximum-length Unicode fields escaped by JSON. Non-admin senders can run 30 commands per minute per chat (sliding window); excess commands are silently dropped after one “Slow down” reply per minute per chat. Admins are exempt, and `/ping` checks its existing 15-second chat cooldown before validation or DNS.

Web client rate buckets expire after inactivity and retain at most 10,000 keys. Dashboard HTML is rendered in a background database worker, cached per token for 15 seconds (up to 1,000 entries), and limited to four concurrent renders; excess requests receive `503` with `Retry-After: 15`. Status responses retain their no-store and other security headers.

Expand All @@ -338,7 +340,7 @@ sudo systemctl reload caddy

## Development

`python3 -m unittest discover -s tests` runs the test suite. `tools/loadbench` builds a synthetic database of production size (10,000 monitors, 300 chats, 20 peers, 90 days of history) and measures what the periodic and per-check work costs per simulated minute (CPU time, database connections, write transactions, rows read). Use it before and after a change that touches a timer path:
`python3 -m unittest discover -s tests` runs the test suite. `python -m tools.loadbench.release310` prints queries, RPC calls, DNS lookups and CPU per pass for the paths changed in 3.1.0 (run it before and after a change). `tools/loadbench` builds a synthetic database of production size (10,000 monitors, 300 chats, 20 peers, 90 days of history) and measures what the periodic and per-check work costs per simulated minute (CPU time, database connections, write transactions, rows read). Use it before and after a change that touches a timer path:

```bash
python -m tools.loadbench.gen_db --db /tmp/lb.db
Expand Down
Loading
Loading