Skip to content

Release 3.1.0: security and load audit fixes - #5

Merged
mrgluek merged 3 commits into
mainfrom
mrgluek/uptime-audit-fixes
Nov 30, 2026
Merged

mrgluek merged 3 commits into
mainfrom
mrgluek/uptime-audit-fixes

Conversation

@mrgluek

@mrgluek mrgluek commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

Release 3.1.0. Fixes findings 1-11 and 13-15 of the 2026-11-30 security and load audit (12 and 16 are not part of it). CHANGELOG has the full list; below is the review summary.

What changed, per finding

# Change Test (tests/test_release_310.py unless noted)
1 _parse_batch_targets validates format and literal IPs only (resolve_dns=False). run_single_check already resolves asynchronously, pinned, under the 30 s deadline; a name that resolves to a private address still gets no connection and is answered as a skip. BatchParseHasNoDns (fails if getaddrinfo or a DNS worker is used)
2 "outbox" watchdog heartbeat: beats before every job and every 30 s while idle, so it ages only while a send never returns. OutboxHeartbeat
3 Telemetry metrics: format and literal-IP check only, no DNS per metric (the probe resolves at connect time). Chosen over a negative cache: it removes the lookups and the busy-vs-blocked ambiguity. MetricsNoDns; test_peer_rt_audit_fixes (old 10 s deadline test replaced)
4 push_status_apps: 3 queries for all chats (chat rows, config keys, monitor rows) and one get_existing_msg_ids; name and member count cached 10 min; a chat whose inputs are unchanged since its last full evaluation (which found nothing to send) is skipped with no query and no RPC. It is evaluated again every 30-40 min (30 min plus a per-chat offset) whatever its last send time, and when its 30-minute full-state refresh becomes due. Name and member count come from the core every 10-20 min per chat (10 min plus a hashed offset); when only that cache expired and the name is the same, no state is built (review fixes: the first version skipped only chats sent within 30 min, and built a state for every chat whose name cache expired, in clusters). StatusAppsAtScale, StatusAppsOldLastSend (200 chats, last send 4,000 s ago), StatusAppsOverSeveralCacheLifetimes (50 passes, peaks per pass)
5 _is_dc_admin needs show_padlock and a stored fingerprint. Address-only admin: the key of the first encrypted message from that address is bound; the notice goes to the binder's chat and to the stored admin chat, and the bind is logged at ERROR with the address (AdminBindNotice). Existing fingerprint setups unaffected. test_audit4_security.py (test_f02_*), AdminCommandsNeedEncryption
6 MAX_MONITORS_PER_HOST (10 per chat) and MAX_MONITORS_PER_SENDER (500, new column resources.added_by) for non-admins; mirrored targets: PROBE_ONLY_PER_HOST_PER_MINUTE (6) and MAX_PROBE_TARGETS_TOTAL (2000). Existing monitors are never touched. AmplificationLimits
7 Quorum context (peers, alert mode, share scope) cached 10 s and reset on mode/scope/admin/peer change; stale check hourly per monitor; status page peer measurements in one query; /probeignore read once per batch. PerItemReads
8 Peer activity stamp via run_db; held-report writes on a one-thread background writer (order kept); ping baselines batched, the ping dictionaries are written on the loop only (read on a thread, cached on the loop, the dirty queue is taken in one step, so a value written during a store is kept; PingBaselineThreading). _own_peer_caps reads left as they are: they are pooled WAL reads, not writes. WritesOffTheLoop
9 Baselines written in one transaction every 10 s, 30-day prune in the cleanup (steady baselines re-stamped daily), four dicts bounded. PingBaselines
10 trim_user_chats hourly. UserChatTrim
11 Negative cache (5 min, keyed by admin email and key). AdminContactMiss
13 BOT_SYNC_DATA has the command budget, the limits of #6 and a format-only is_safe_target_url; HELLO, HELLO_ACK, CHECK_REQ, CHECK_RESP above 16 KB are dropped before json.loads; CHECK_BATCH_REQ/RESP above 512 KB are dropped and their sender is verified before the JSON is parsed. SyncAndPayloads, BatchPayloadsNeedAVerifiedSender
14 redact_url on name and URL in the status page and app state. test_status_app_and_page_show_redacted_urls
15 New table probe_target_requesters(url, peer, last_seen): every peer that asks for a URL is recorded and gets this node's results for it; the check settings stay with the first (owning) peer while its own request for the URL is less than a day old, a second peer only keeps the target alive, and takes the settings over once the owner has been silent for a day (staleness comes from the owner's requester row, in the one batched upsert); the 200 cap is counted per requester, a URL some peer already asked for costs no slot of the 2,000 total; rows are renamed with a peer's address, removed with a peer (targets another peer also asked for survive) and pruned with the targets. Telemetry reads all requesters in one query per pass. Unencrypted HELLO and HELLO_ACK matched by address no longer move a peer's chat. RequestersGetResults, MirroredTargets, UnencryptedAckDoesNotMoveChat

Differences from the report: #3 as noted above; #13 uses a size cap for the small messages and verify-first for the batches; #15 keeps url as primary key and records requesters in a second table instead of re-keying probe_targets; #4: a rename shows within 10 minutes.

Known limits (left as they are)

  • The per-sender and per-host caps (Release 3.1.1: stable vote order in the status hash; 300 s interval for chats with 30+ monitors #6) 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 (v2.25.0: deploy and publish releases by tag #3). Their lookup is answered from the DNS cache within its TTL, so it is one bounded lookup a minute at most; no extra negative cache was added.
  • The first peer to send a URL picks its type and expected_keyword for as long as it keeps asking for it; once it has been silent for a day the next peer takes over. It cannot take the others' results.
  • 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. Inherent to binding on first use; set_admin.py --fingerprint avoids it.

Load gate

What runs how often over how many items (production: about 150 targets, 8 peers, 7 status-app chats, journal 1-2k rows a day):

  • every 30 s: status-app audit, now 3 queries and 1 RPC call for any chat count (was about 13 reads and 3 RPC calls per chat); plus one JSON parse of the vote list per status-app monitor (at most 3,000);
  • every 10 s: ping baseline flush (does nothing when nothing changed);
  • every 30 s idle: the outbox thread wakes once (one dictionary write);
  • per failing check: no database read for the quorum context within 10 s, none for the stale check within an hour;
  • per telemetry message / batch request: no DNS lookup, no per-item connection.

Scale tests assert connection, RPC and DNS bounds. I ran tests/test_release_310.py against main (3.0.9): most of its tests fail there (the others are regression guards for behaviour that must stay: private literals refused, private-resolving names abstain, the per-peer cap follows an address change, existing monitors survive new limits, a changed admin key is looked up at once, a taken-over target after 3 days, etc.).

Before/after on a generated dataset (python -m tools.loadbench.release310, same Mac, DNS stubbed at 5 ms):

Path 3.0.9 3.1.0
Status apps, 200 chats, steady 30 s pass, last sent 10 min ago: connections / RPC / CPU 2,001 / 600 / 162 ms 2 / 1 / 9 ms
Same, last sent 66 min ago, nothing changed: connections / RPC / CPU 2,001 / 600 / 171 ms 2 / 1 / 9 ms
Same chats over 61 min of passes, first pass after a start: connections / RPC 2,001 / 600 802 / 401
Same, later passes: connections median / average / peak 2,001 / 2,100 / 2,201 2 / 10.3 / 67 (bcf594e..74704e9: 2 / 43.4 / 537)
Same, later passes: RPC calls average / peak 600 / 600 13.2 / 65 (74704e9: 17.6 / 215)
Peer batch of 100 targets: DNS lookups on the DB pool / time on one worker 100 / 724 ms 0 / 1 ms
Telemetry of 200 metrics: DNS lookups / time 200 / 1,416 ms 0 / 5 ms
150 failing targets, one check each: connections / CPU 450 / 179 ms 7 / 58 ms
Status page, 300 monitors: connections 301 2
1,000 pinged addresses, first sample: write transactions / CPU 1,000 / 31 ms 1 / 10 ms
User chat trim, 500 chats: RPC per hour 6,000 1,000
Admin key contact unknown: RPC per hour 12,240 1,224

A py-spy comparison on de2 and ru against the saved baseline, and the CPU checks 1 h and 24 h after deploy, follow after the release (done by the owner's coordinator; nothing was run on production here).

Peer protocol compatibility

No change on the wire: same messages, same fields. 3.0.9 and 3.1.0 nodes work together in either order. The database gets one new table (probe_target_requesters, filled from probe_targets when a 3.0.9 database is opened; tested) and one column (resources.added_by); a rollback to 3.0.9 ignores both. When two peers mirror the same URL, a 3.1.0 node sends results to both whatever their versions (3.0.9 gave them to one). Behaviour differences on the receiving side only: a 3.1.0 node answers a batch target whose name resolves privately with a skip (3.0.9 answered "Target refused", also a skip); a second peer's version of a target another peer still sends is ignored; HELLO/CHECK payloads above 16 KB are dropped (real ones are a few hundred bytes).

Tests

python -m unittest discover -s tests on Python 3.12: 1133 tests, 1 failure: test_rpc_methods.test_used_methods_exist_in_core (init_transports, set_pinned_message_state missing from the installed core in my venv); it fails the same way on main and is not related. Existing tests changed because behaviour changed on purpose: admin tests (encryption and key binding), the DNS-deadline metrics test (replaced by a no-DNS test), stale-check and ping-baseline tests (throttle and batched writes), the status-app rename test (10-minute name cache), the cleanup count test, the watchdog heartbeat list.

Owner decisions

  • Admin commands in an unencrypted group chat are refused from now on.
  • Defaults 10 per host per chat and 500 per sender: the admin is exempt; say if de2 users legitimately need more.

Security: no DNS in batch cross-check parsing, admin commands need an encrypted message and a stored key (address-only admins bind the key on the first encrypted message), per-host and per-sender monitor limits, per-host rate for mirrored targets, command budget and target checks on BOT_SYNC_DATA, size caps before parsing HELLO and check payloads, redacted URLs on the status page and app, mirrored targets cannot be taken over by another peer.

Load: status app audit from 2 queries and 1 RPC call for any number of chats (was 2001 connections and 600 RPC calls for 200 chats), no DNS per telemetry metric, outbox heartbeat in the watchdog, batched ping baselines with pruning, cached quorum context, hourly user chat trim, negative cache for the admin contact.
…luation period, batch payloads verified before parsing, admin bind notice, HELLO_ACK guard, ping state on the loop

- probe_target_requesters: every peer that asks for a URL gets results; settings stay with the owning peer; the cap is counted per requester
- status apps: unchanged chats are evaluated again once per 30 minutes whatever their last send time (was every pass after 30 min without a send)
- CHECK_BATCH_REQ/RESP: sender verified before json.loads, 512 KB cap
- admin key bind: notice also to the stored admin chat, logged at ERROR with the address
- unencrypted HELLO_ACK no longer moves a peer's chat
- ping baselines: dictionaries written on the loop only, dirty queue taken atomically, no database read on the loop
…t status-app cost across name-cache expiries

- probe_targets: the owner of a mirrored target is replaced when its own requester row is older than a day, not when probe_targets.last_seen is (other requesters refresh that)
- status apps: when only the name cache expired and the name is unchanged no state is built; cache expiry and periodic re-evaluation are scattered per chat
@mrgluek
mrgluek merged commit be762bf into main Nov 30, 2026
1 check passed
@mrgluek
mrgluek deleted the mrgluek/uptime-audit-fixes branch November 30, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant