Keeping Deleted Notes Outside a Search Result
🔄 Topic
I worked on a local bridge that lets a controlled helper search and read Apple Notes. The first version treated every result returned by Notes as usable. That created two security and integrity problems: a note in the Recently Deleted folder could be selected, and an exact title could fail simply because an older valid note was beyond an arbitrary result limit.
The bridge also became slow during broad searches. A search for a common one-letter term caused a separate Apple Event for the title and identifier of almost every matching note. The operation could time out before the caller received a complete result.
🎯 Goal
Make note retrieval respect the state of the record and keep the search bounded and predictable:
- exclude notes in the trash before any body is read;
- require an exact title for the read operation;
- keep older valid notes eligible instead of hiding them behind a limit;
- make broad searches efficient enough to finish within the wrapper timeout.
🛠 What I Did
I changed the search path to collect the identifiers of notes in the trash first. The bridge now removes those identifiers from title and body results before returning them. A note with the same title in the live Notes folder remains a valid result; a title that exists only in the trash is treated as absent.
The read path uses an exact title match before reading note content. It does not silently choose a body-search result that merely happens to contain the requested words. If more than one live note has the exact title, the bridge reports an ambiguous result and requires the caller to choose by identifier.
I also moved the expensive title work into a bulk read. Instead of asking Apple Events for the title and identifier of each match one by one, the script reads the lists in bulk and performs the case-insensitive title comparison in Python. Body matching remains a Notes query. This keeps the result semantics while reducing the number of cross-process calls.
The tests cover a live note beside a trashed note with the same title, a title found only in the trash, the title-only flag, and the bulk-search structure. The source commits were ec504ce, e8f7495, 4453218, and 95b3fe8 in the Hermes Apple bridge repository.
🔗 Key Cybersecurity Connections
🔍 Investigation Questions
When a security-sensitive helper reads personal data, I should ask:
- Does the result represent a live record or a deleted one?
- Does the operation select by an exact identity, or by an accidental text match?
- Can a result limit hide the real record that the caller needs?
- Can a slow integration time out and return an incomplete picture?
- Are body reads performed only after the record has passed the state and identity checks?
🚨 Detection Opportunities
Useful diagnostics include the number of trashed records excluded, ambiguous exact-title matches, timeouts, and truncated result sets. A caller should be able to distinguish “no live note matched” from “the search was incomplete” and from “several live records matched.”
🧭 MITRE ATT&CK Techniques
No direct ATT&CK technique mapping is claimed. This is a local privacy, record-integrity, and access-boundary lesson. A deleted record being returned is a control failure; it is not evidence of attacker behaviour by itself.
⚠️ Challenges and Boundaries
The bridge is still a local owner-controlled integration. I did not treat Apple Notes as an enterprise records-management system, and I did not publish note contents. The changes prove narrower properties: trashed identifiers are filtered, exact reads do not silently select body matches, and the bulk-search design avoids the previous per-result request pattern.
There is also a useful distinction between speed and completeness. A faster query is not automatically safer if it changes which records are eligible. The implementation kept the title and body match semantics while moving only the repeated title comparison into the local process.
📚 What I Learned
Deletion state is part of a record’s security meaning. A note that still exists in a data store is not necessarily a valid answer to a user’s request. The bridge has to understand the difference between live and trashed records before it reads or exposes their contents.
I also learned that an integration timeout can become a data-integrity problem. If a caller cannot tell whether a result set is complete, it may make a decision from a partial search while believing the search succeeded.
🧩 Lessons Learned
- Filter deleted or trashed records before reading their bodies.
- Use exact identity checks for read operations that can expose private content.
- Treat ambiguity as a result that needs resolution, not as permission to guess.
- Keep old valid records reachable; arbitrary limits can hide the evidence needed for a decision.
- Optimize repeated integration calls without changing the security meaning of the query.
- Make incomplete searches visible instead of returning a convincing partial answer.
😄 TL;DR
I made a local Notes bridge more honest about what it returns. Trashed notes stay out of live results, exact reads do not guess between records, older notes remain reachable, and broad searches avoid an avoidable one-request-per-note timeout.