Skip to content

Agent Zero AI framework

Preserve private mode for OAuth fallback writes

Cooper Gamble1acf88e323f5
diff --git a/plugins/_oauth/helpers/codex.py b/plugins/_oauth/helpers/codex.py
index 4591f49cb..fe2447629 100644
--- a/plugins/_oauth/helpers/codex.py
+++ b/plugins/_oauth/helpers/codex.py
@@ -1085,6 +1085,10 @@ def _write_auth_file_in_place(path: Path, data: dict[str, Any]) -> None:
handle.write(json.dumps(data, indent=2) + "\n")
handle.flush()
os.fsync(handle.fileno())
+ try:
+ path.chmod(0o600)
+ except OSError:
+ pass
def _validate_private_auth_path(path: Path) -> Path:
diff --git a/tests/test_oauth_codex.py b/tests/test_oauth_codex.py
index 9c10e42f3..e8360e1b1 100644
--- a/tests/test_oauth_codex.py
+++ b/tests/test_oauth_codex.py
@@ -304,6 +304,7 @@ def test_write_auth_file_falls_back_for_file_bind_mount(tmp_path, monkeypatch):
assert json.loads(auth_path.read_text(encoding="utf-8")) == {
"tokens": {"refresh_token": "refresh-1"}
}
+ assert stat.S_IMODE(auth_path.stat().st_mode) == 0o600
assert list(tmp_path.glob(".auth.json.*.tmp")) == []
@@ -324,6 +325,7 @@ def test_write_auth_file_falls_back_when_parent_rejects_temporary_files(tmp_path
assert json.loads(auth_path.read_text(encoding="utf-8")) == {
"tokens": {"refresh_token": "refresh-1"}
}
+ assert stat.S_IMODE(auth_path.stat().st_mode) == 0o600
assert not auth_path.with_name(".auth.json.lock").exists()