Skip to content

fix(core): make atomic staging private before writing - #1925

Merged
phernandez merged 8 commits into
mainfrom
codex/security-atomic-staging
Oct 28, 2026
Merged

phernandez merged 8 commits into
mainfrom
codex/security-atomic-staging

Conversation

@phernandez

@phernandez phernandez commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Why

Atomic writes stage content in a file created with ordinary permissions, then restore the target's mode only after writing. Under umask 000, rewriting a private 0600 note stages its bytes in a 0666 file. Fixes #1906.

What Changed

Create the content-bearing staging inode with mode 0600 from the outset for both text and binary writers. Preserve the target's final permissions; newly created targets retain their normal umask-derived final mode.

Implementation Details

Capture the existing target mode, or determine the umask-derived mode using an empty probe in a private temporary directory for a new target. This avoids mutating the process-wide umask and prevents an observer from opening the content inode before permissions tighten. Existing publication-time chmod remains in place, preserving read-only and shared target behavior. No content reaches the staging file until reservation returns.

Stacked on #1924; only atomic staging permissions and their regression tests are new here.

Testing

  • Before the fix: all three real staging regressions failed under umask 000. A later real-open observer also failed against chmod-after-create, reproducing the descriptor-retention gap; the inode now starts private.
  • uv run pytest tests/utils/test_atomic_staging_permissions.py tests/utils/test_file_utils.py -q --no-cov: 60 passed.
  • just fast-check: passed, including repository type checking.
  • just doctor: passed sandboxed write/index/search self-test.

Risks / Follow-ups

This closes the staging-content permission window without changing final file modes or the atomic rename protocol. POSIX permission regressions skip Windows, which uses native ACL semantics.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T21:41:40.761475Z d74bce5 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e59a28992

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/basic_memory/file_utils.py Resolved
@phernandez
phernandez force-pushed the codex/security-atomic-staging branch from 6e59a28 to d74bce5 Compare October 28, 2026 21:12
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: d74bce560d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Base automatically changed from codex/security-rclone-permissions to main October 28, 2026 22:18
@phernandez
phernandez changed the base branch from codex/security-rclone-permissions to main October 28, 2026 22:18
@phernandez
phernandez merged commit 9b77c18 into main Oct 28, 2026
53 checks passed
@phernandez
phernandez deleted the codex/security-atomic-staging branch October 28, 2026 22:19
phernandez added a commit that referenced this pull request Oct 28, 2026
## Why

The terminal `#bm:links_to` regex retries a leading whitespace run at
every position when no directive follows. A 150,000-space token exceeds
a five-second subprocess deadline. Fixes #1900.

## What Changed

Use a single-character whitespace boundary before the literal directive
instead of a repeated leading whitespace group. Existing callers trim
the prefix, preserving directive-removal behavior.

## Implementation Details

Only the fixed literal can initiate a trailing-whitespace match, so
failed whitespace suffixes cannot overlap quadratically. Both
observation parsing and code-aware relation directive handling share the
corrected pattern. A subprocess bounds regression runtime without
mocking the parser.

Stacked on #1925; only the shared directive pattern and its tests are
new here.

## Testing

- Before the fix: the whitespace-heavy regression timed out after five
seconds.
- `uv run pytest tests/markdown/test_directive_work.py
tests/markdown/test_markdown_plugins.py -q --no-cov`: passed.
- Semantics tests cover Unicode whitespace, terminal newlines, missing
separators, and nonterminal directives.
- `just fast-check`: passed, including repository type checking.
- `just doctor`: passed sandboxed write/index/search self-test.

## Risks / Follow-ups

The shared pattern's match start now points at the directive instead of
its leading whitespace; both consumers already trim the prefix, so
returned content remains identical. Broader Markdown parser work remains
outside this PR.

---------

Signed-off-by: phernandez <[email protected]>
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.

Preserve private file permissions before writing staging content

1 participant