Skip to content

fix(acquire): profile follow-ups from the #33 review - #55

Merged
bojieli merged 8 commits into
mainfrom
fix/issue-50-profile-followups
Nov 24, 2026
Merged

bojieli merged 8 commits into
mainfrom
fix/issue-50-profile-followups

Conversation

@bojieli

@bojieli bojieli commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Closes #50

Follow-ups from the #33 review of profile-aware capture.

Changes

Check the key destination before the logout/login step (SecretOutputWriter.checkDestinationAccess, main.swift)

  • New check runs inside invokingUser.perform and changes nothing. It mirrors the final write's rules:
    • An existing output fails without --overwrite (outputExists).
    • With --overwrite, the output must be a single-link regular file the user owns and can write. Its folder must not be a symbolic link and must be readable and searchable, because the writer opens it O_RDONLY.
    • A missing output needs the nearest existing folder to be writable and searchable, and readable when it is the immediate parent.
  • Access uses faccessat(..., AT_EACCESS), because under sudo the real uid is root and plain access(2) would approve everything.
  • preflight and capture both run it. It shows up as its own failed preflight check, so it doesn't hide the database or process diagnostics. capture --json reports it in blockers and exits 1 before any logout prompt.
  • New errors: destinationNotWritable for a folder on the path and outputNotWritable for an existing read-only key.

Mirror Rust discovery when only source.passphrase_file is configured (QueryProfileTarget.discoverDefaultLiveSourceRoot)

  • Ports discover_default_live_source_root():
    • Candidates are the com.tencent.xinWeChat container's xwechat_files plus Group Containers entries whose ASCII-lowercased name contains wechat or xinwechat.
    • A root qualifies only if it is a real directory owned by the user and has contact, session and message directories.
    • Recency is the newest mtime of a regular file directly inside those three folders.
    • If another account is less than 14 days older than the newest, the result is ambiguous.
  • Directory entries are kept as raw bytes and read in place from readdir records.
  • Runs as the invoking user, inside the existing resolve perform block.
  • Fails closed in three cases:
    • Discovery fails: capture or verify without --db-root reports Rust's reason.
    • --db-root is given alongside a discovered root: it still needs --output, because a query discovers under its own $HOME.
    • GREENBUBBLES_CONFIG_FILE is set: the query's home can't be known, so no account is guessed.

Compare database directories by identity (AcquireTarget.originConflicting)

  • Compares st_dev/st_ino from stat (run as the invoking user) instead of realpath strings. A failed lookup on either side counts as a conflict.

Keep --overwrite in the suggested Next: command (captureCommand).

Smoke test (scripts/sudo-smoke-test-acquire.sh), new checks:

  • user: preflight reports an existing key file without --overwrite and accepts it with --overwrite.
  • sudo (e): a root-owned 0700 key folder blocks preflight as you; capture --json reports it and never prints the logout step; nothing gets created. A key folder inside root's home is also refused.
  • sudo (f): preflight with --overwrite refuses a root-owned key file and leaves it unchanged.

Testing

  • swift test, run on a copy without the HistoryApp target: all suites pass. Acquire has 137 tests, with new ones for discovery (14-day window, group containers, skipped roots, other owner), identity comparison (NFC/NFD, failed lookup), and destination access (0500/0300/0000 folders, read-only file, hard/symbolic links, file in place of a folder, symlinked parent, other owner).
  • swift format lint --strict: clean.
  • scripts/sudo-smoke-test-acquire.sh --no-sudo: 4/4 pass.

Needs manual check

  • Owner: please rerun scripts/sudo-smoke-test-acquire.sh under real sudo. The new (e) and (f) checks have not been run as root.
  • Discovery against a real WeChat install with two accounts. Unit tests cover the rules on synthetic trees; the smoke test does not touch the real home.

Known limitations (Codex P2s not fixed)

  • macOS directory ACLs can grant add_file and add_subdirectory separately. The preflight probes generic W_OK, so a split ACL can make preflight disagree with the writer. In that case capture fails at the final write, which is how it behaved before this PR.
  • If a query runs with a custom $HOME that differs from the login home, it can still discover a different account than capture does when the default config.toml is used. The same was true before this PR, and it also affects the profile file location. The GREENBUBBLES_CONFIG_FILE case now fails closed.

🤖 Generated with Claude Code

bojieli and others added 6 commits November 24, 2026 09:47
- Check the key destination as the invoking user, without modifying it,
  in both preflight and capture (existing file, ownership, links, and the
  nearest existing folder's write access via faccessat(AT_EACCESS)).
- Mirror Rust's discover_default_live_source_root candidate and 14-day
  recency rules when only source.passphrase_file is configured.
- Compare --db-root against the configured root by st_dev/st_ino; a failed
  lookup is a conflict.
- Keep --overwrite in preflight's Next: command.
- Extend scripts/sudo-smoke-test-acquire.sh with destination checks.

Closes #50

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…check

Also require read access on the existing containing folder (the writer
opens it O_RDONLY), suggest --db-root with --output for ambiguous accounts,
and make the smoke test's absence check require a valid report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
capture --json now reports a key destination problem in its readiness
report (exit 1) instead of exiting 2 with no output. A discovered root
keeps requiring --output with --db-root, since a query may discover under
a different $HOME. A read-only existing key file gets its own message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dden

Rust discovers under the query's $HOME; with GREENBUBBLES_CONFIG_FILE set
that home can't be established, so require --db-root and --output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
readdir returns variable-length records; copying the whole d_name tuple
could read past the buffer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bojieli
bojieli force-pushed the fix/issue-50-profile-followups branch from f6c5d1b to ad13a75 Compare November 24, 2026 01:48
bojieli and others added 2 commits November 24, 2026 09:55
Unlink the two key fixtures and rmdir the expected-empty folder without sudo,
instead of a recursive delete as root; a non-empty folder is left and reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bojieli

bojieli commented Nov 24, 2026

Copy link
Copy Markdown
Owner Author

Sudo smoke test at cb135e1 on the owner's Mac: passed: 15 failed: 0 skipped: 0, including the new (e) and (f) checks. A final Codex round found no P0/P1. Its two P2s: the recursive sudo cleanup in the smoke test is fixed in 322bacc; the macOS ACL file-vs-subfolder distinction is left as a known limitation, as it was before this PR.

🤖 Generated with Claude Code

@bojieli
bojieli merged commit 2dc2859 into main Nov 24, 2026
4 checks passed
@bojieli bojieli mentioned this pull request Nov 24, 2026
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.

acquire profiles: follow-ups from the #33 review

1 participant