Skip to content

fix(credentials): guard fchmod on Windows - #1869

Open
OllieinCanada wants to merge 1 commit into
anthropics:mainfrom
OllieinCanada:fix/1868-windows-credential-writeback
Open

fix(credentials): guard fchmod on Windows#1869
OllieinCanada wants to merge 1 commit into
anthropics:mainfrom
OllieinCanada:fix/1868-windows-credential-writeback

Conversation

@OllieinCanada

Copy link
Copy Markdown

Fixes #1868

Summary

Guard the POSIX-only os.fchmod call when atomically writing credentials so
OAuth token refreshes can persist rotated credentials on Windows.

The write path still applies mode 0600 whenever fchmod is available. On
platforms without it, the existing atomic write, file fsync, and replacement
continue normally.

Impact

Previously, the refresh request could succeed and rotate the server-side
refresh token, then Windows would raise AttributeError before writing the new
token. The credentials file retained the now-invalid old token and subsequent
refreshes failed with invalid_grant.

Tests

  • deterministic regression with os.fchmod removed
  • security regression proving available fchmod is called with 0600
  • existing end-to-end mocked refresh/write-back test
  • tests/lib/test_credentials.py: 219 passed, 4 skipped
  • ruff check .
  • targeted Ruff format, Pyright, and Mypy checks
  • dependency-cap validation and import smoke test
  • git diff --check

No real credentials, API calls, or external services are used by the
regression tests.

Signed-off-by: Oliver Slapinski <olliefromcanada@gmail.com>
@OllieinCanada
OllieinCanada marked this pull request as ready for review August 21, 2026 19:14
@OllieinCanada
OllieinCanada requested a review from a team as a code owner August 21, 2026 19:14
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.

Windows: os.fchmod in credential write-back bricks the OAuth refresh token

1 participant