Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 5 min read

I built a local memory for my PC in Rust, then tried to steal my own secrets from it

What was that error I searched for an hour ago? Which terminal did I paste that command into? What was I even doing before lunch? I wanted to press one shortcut and just find it. Tools like that exist, but most of them

I built a local memory for my PC in Rust, then tried to steal my own secrets from it

What was that error I searched for an hour ago? Which terminal did I paste that command into? What was I even doing before lunch?

I wanted to press one shortcut and just find it. Tools like that exist, but most of them take periodic screenshots or send your activity to a server. I did not want either. So I built Synapse Mind: a local-first memory for Windows that never takes screenshots, never leaves the device, and masks secrets in memory before anything touches the disk.

This post is about the parts that turned out to be harder than expected, and about testing the privacy claims by actually dumping the app's memory and searching it for secrets.

Alt+Space search with causality links

What it does

  • Remembers: captures the focused window's text through UI Automation, clipboard events and window switches. No periodic screenshots.
  • Connects: links events by time and simple rules ("searched after an error", "pasted from clipboard", "switched app"), so a result shows the chain around a moment, not just the moment.
  • Finds: Alt+Space, type, done. Hybrid search: BM25 full text + vector similarity + recency.
  • Protects: password managers, private browser windows and .env / .pem / id_rsa windows are never processed. Everything else passes a masker: STRIPE_SECRET=[REDACTED_API_KEY].

Architecture

It is a Rust 2024 workspace plus a Tauri 2 app:

s-sensor  ──►  s-guard  ──►  s-core  ──►  Tauri UI
(Win32 hooks,   (blocklist,     (SQLCipher,     (Alt+Space overlay,
 UI Automation,  PII/secret      FTS5 + vectors,  Memory Panel, tray)
 clipboard)      masker,         causality)
                 zeroize)

The rule that shaped everything: raw data cannot reach the disk or the embedding model without passing the guard. The type system enforces part of it. The raw packet type has no Debug, Serialize or Clone, and that is checked with compile_fail doctests:

// This is a compile_fail doctest: it must NOT compile.
fn leak(p: &s_types::RawCapturePacket) {
    println!("{:?}", p); // error[E0277]: `RawCapturePacket` doesn't implement `Debug`
}

Raw fields are wiped with zeroize on drop. The database is SQLite encrypted with SQLCipher (AES-256), and its key is random and protected by Windows DPAPI, so the plain key is never written to disk.

Problem 1: Windows keeps copies you cannot wipe

UI Automation is the right way to read text from other apps (OCR is only a fallback). But UIAutomationCore.dll copies the text it reads into its own internal heap buffers and frees them without zeroing. Those buffers are not reachable from my code, so zeroize cannot help. In a long-running process, that text just sits in RAM, and in any memory dump.

The fix was to move the read out of the main process. A single-use, pre-warmed helper process waits with COM and UI Automation already initialized. For each read it receives only numbers (a window handle and limits) over stdin, reads one window, writes the result back and is killed. When the process dies, the kernel reclaims and zeroes its pages. All helpers are in a job object with kill-on-close, so they die if the main app dies. The main app never loads the UIA library at all.

Problem 2: proving it, with memory dumps

"We zeroize everything" is easy to write in a README. I wanted a test that could fail.

  • Gate 1 feeds synthetic PII and secrets (cards with valid Luhn digits, national IDs, API keys, JWTs, private keys, plus encoded and split variants) through the guard and checks that nothing leaks into what gets stored.
  • Gate 2 starts the real release binary with an isolated data folder, feeds synthetic secrets through the real sensor path (a fake window with secret text, clipboard contents), uses the search box, opens the Memory Panel, and takes full memory dumps of the app, the helper processes and every WebView2 process at several stages. Then it searches the dumps for the raw secrets, the database key in several encodings, and the SQLCipher-derived HMAC key. At the end it opens the encrypted database and confirms that the events were stored masked.

The harness has its own controls, so a blind detector cannot pass: it must find the secrets in its own memory, and it must find a marker typed into the search box inside the WebView.

For v0.1.1, the final run dumped 41 processes and found no raw secrets or keys.

Problem 3: a 3.6 GB surprise from attention padding

After switching from a test embedder to a real model (bge-small-en-v1.5 through fastembed / ONNX Runtime, running on the CPU), existing records have to be re-embedded once. On a fresh test database this path never ran. On my real database, the app climbed to 3.6 GB of memory.

The cause: the backfill sent 128 texts to ONNX Runtime in one call. Every text is padded to the longest one (up to 512 tokens), and attention memory grows with batch Γ— seq_lenΒ². I wrote a test that pushes 128 long texts through the app's exact configuration and measured peak working set by batch size:

Texts per call Peak working set Time
128 3,351 MB 20.3 s
8 417 MB 11.7 s
4 299 MB 9.9 s
2 238 MB 12.6 s
1 209 MB 13.4 s

One at a time keeps memory at the model-loaded footprint, and it is still faster than the original single call. The model is also unloaded after 10 idle minutes, which brings the app's private memory down to about 32 MB.

Problem 4: the spinning cursor

I noticed a busy (loading) cursor that kept spinning. The single-use UIA helper was the cause: it is the same GUI-subsystem executable as the app, and Windows shows "app starting" feedback for a new GUI process until it shows a window or calls GetMessage, or a timeout passes. The helper did neither, and a new one starts for every read.

The fix is one call at the top of the helper: post a message to its own thread and immediately read it with GetMessageW. Windows turns the feedback cursor off after the first GetMessage. In a 60-second check with 14 helper launches, the busy cursor never appeared.

Numbers (Ryzen 7 8845HS, release build)

  • Single-query embedding p95: ~18 ms on CPU
  • Long pasted queries (4 KB) are trimmed: embedding p95 went from 88 ms to 19 ms, keyword search p95 from 25 ms to 3 ms
  • Idle: about 32 MB private memory after the model is unloaded; about 200 MB with the model loaded

Honest limitations

  • Windows 11 only for now.
  • The semantic model is English-only. Turkish text still matches by keyword, but not by meaning.
  • The links between events are rule-based. Nothing here "understands" your content.
  • Accepted risks are documented in SECURITY.md, including what this cannot protect against (malware in the same user session, pagefile and hibernation).

Try it

The license is FSL-1.1-MIT: source-available now, and each version becomes MIT two years after release.

I would love feedback, especially on the threat model and on the memory-dump approach. If you can think of a way the guard could be bypassed, please open an issue.

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.