Repository navigation
Release 3.1.0: security and load audit fixes - #5
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
tests/test_release_310.pyunless noted)_parse_batch_targetsvalidates format and literal IPs only (resolve_dns=False).run_single_checkalready 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 ifgetaddrinfoor a DNS worker is used)OutboxHeartbeatMetricsNoDns;test_peer_rt_audit_fixes(old 10 s deadline test replaced)push_status_apps: 3 queries for all chats (chat rows, config keys, monitor rows) and oneget_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)_is_dc_adminneedsshow_padlockand 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_*),AdminCommandsNeedEncryptionMAX_MONITORS_PER_HOST(10 per chat) andMAX_MONITORS_PER_SENDER(500, new columnresources.added_by) for non-admins; mirrored targets:PROBE_ONLY_PER_HOST_PER_MINUTE(6) andMAX_PROBE_TARGETS_TOTAL(2000). Existing monitors are never touched.AmplificationLimits/probeignoreread once per batch.PerItemReadsrun_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_capsreads left as they are: they are pooled WAL reads, not writes.WritesOffTheLoopPingBaselinestrim_user_chatshourly.UserChatTrimAdminContactMissBOT_SYNC_DATAhas the command budget, the limits of #6 and a format-onlyis_safe_target_url; HELLO, HELLO_ACK, CHECK_REQ, CHECK_RESP above 16 KB are dropped beforejson.loads; CHECK_BATCH_REQ/RESP above 512 KB are dropped and their sender is verified before the JSON is parsed.SyncAndPayloads,BatchPayloadsNeedAVerifiedSenderredact_urlon name and URL in the status page and app state.test_status_app_and_page_show_redacted_urlsprobe_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,UnencryptedAckDoesNotMoveChatDifferences from the report: #3 as noted above; #13 uses a size cap for the small messages and verify-first for the batches; #15 keeps
urlas primary key and records requesters in a second table instead of re-keyingprobe_targets; #4: a rename shows within 10 minutes.Known limits (left as they are)
typeandexpected_keywordfor 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.admin_chat_idalready points to the admin's chat; the ERROR log line is the reliable signal. Inherent to binding on first use;set_admin.py --fingerprintavoids 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):
Scale tests assert connection, RPC and DNS bounds. I ran
tests/test_release_310.pyagainstmain(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):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 fromprobe_targetswhen 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 testson Python 3.12: 1133 tests, 1 failure:test_rpc_methods.test_used_methods_exist_in_core(init_transports,set_pinned_message_statemissing from the installed core in my venv); it fails the same way onmainand 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