Repository navigation
security: Tor delivery, deleted-content scrubbing, DNS rebinding pin - #155
Merged
Merged
Conversation
check_download_target resolved a download's hostname and required public addresses, but the connection resolved again, so a rebinding DNS server could answer a public address to the check and 127.0.0.1 to the connection. In DIRECT mode download_to_file (and DocumentCloud's asset text fetch) now run under net.public_addresses_only(): egress_client's own transport routes those requests to a separate pool whose network backend resolves the name, requires every address to be public, and opens the socket to an address from that same answer. TLS SNI, certificate verification and Host still use the hostname. Tor mode is unchanged (the exit resolves the name). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016LaGpHLuSRHzGARb38X7YS
Deleted rows stayed in free pages, a delete copied the deleted text into the
rollback journal, and SQLite unlinked that journal after every transaction,
leaving it in the filesystem's free space. FTS5 kept a deleted page's words
(with positions) in older index segments.
Every connection the app opens (get_engine, the plaintext alembic engine,
SQLCipher) now sets secure_delete=ON, journal_mode=PERSIST and
temp_store=MEMORY. After each get_session (and after migrations and seeding)
the persistent -journal file is overwritten with zeros, fsynced and truncated
under an EXCLUSIVE lock, and when page text was deleted or replaced (seen by
a per-connection TEMP trigger) the FTS5 index is merged ('optimize') so the
old segments are freed and zeroed.
Measured on ext4: ingest +15% (200 pages 190->220 ms; 10k pages 9.2->10.6 s),
deleting a 20-page document 9->25 ms at 200 pages, 11->291 ms at 10k pages.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016LaGpHLuSRHzGARb38X7YS
request send warned in Tor mode that email (SMTP), Twilio fax and Lob mail all went direct, then sent anyway; a non-interactive run sent silently. - SMTP goes through the Tor SOCKS proxy: net.open_tor_stream is a small stdlib SOCKS5 client (hostname sent as DOMAINNAME, resolved at the exit; stream-isolation credentials) and _TorSMTP uses it as smtplib's socket. STARTTLS still verifies the certificate against the SMTP host. - Twilio Fax and Lob Letters are called over their REST APIs through egress_client (gateways/http.py) instead of their SDKs, which make their own connections outside the egress policy. POST is not retried. Tor mode without socksio refuses (TorUnavailableError), never goes direct. - SendGrid is refused in Tor mode. - request send checks the Tor proxy before sending and exits if it is down. --direct sends one request without Tor (warned); --tor forces Tor. - twilio and lob are no longer needed by the fax and mail extras. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016LaGpHLuSRHzGARb38X7YS
…pinning THREAT_MODEL: request send over Tor and what still identifies the user (login, API key, the name on the request); Known Limitations 2 and 6 rewritten to say what the persistent-journal scrub, secure_delete and the full-text merge do and do not reach; new limitation 9 on download pinning. CHANGELOG Security entries, GUIDE delivery section, README privacy note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016LaGpHLuSRHzGARb38X7YS
…ends 'rcpt TO:') Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016LaGpHLuSRHzGARb38X7YS
Merged
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.
This PR closes three privacy gaps that
docs/THREAT_MODEL.mdused to list as known limitations.1.
request sendrespects Tor modeBefore: in Tor mode, sending by email (SMTP), Twilio fax or Lob mail warned that it would go direct, then sent anyway. A non-interactive run sent with no warning at all.
Now:
net.open_tor_streamis a small SOCKS5 client written with the standard library only._TorSMTPgives that socket to smtplib. STARTTLS still checks the certificate against the SMTP host.egress_client(gateways/http.py). Their SDKs made their own connections, outside the egress policy.socksio, sending is refused rather than sent direct.request sendchecks the Tor proxy before sending and exits if it is down.--directsends one request without Tor, with a warning;--torforces Tor.faxandmailextras no longer need thetwilioorlobSDKs.2. Deleted text no longer lingers in the database files
Before: deleted text survived in three places:
Now:
secure_delete=ON,journal_mode=PERSISTandtemp_store=MEMORY. That coversget_engine, the plaintext Alembic engine and SQLCipher.-journalfile is zeroed after each session, and after migrations and seeding. It is overwritten, fsynced and truncated under an EXCLUSIVE lock.3. Downloads are pinned against DNS rebinding
Before:
check_download_targetresolved the hostname and required public addresses, but the connection then resolved the name again. A rebinding DNS server could answer the check with a public address and the connection with 127.0.0.1.Now: in direct mode,
download_to_fileand DocumentCloud's asset text fetch run undernet.public_addresses_only().Docs
### Securityentries.Not verified
--directis the explicit escape hatch.Checks
socksioinstalled locally. In CI the SOCKS-dependent tests skip without it.test_security_sqlite_remnants.py, plus Tor delivery and rebinding tests.Generated by Claude Code