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
@OllieinCanada

Copy link
Copy Markdown
Author

Native Windows validation on exact head cece0266498e3e1cb0104e0f9e30aebaee5dbe11 is green:

  • Python 3.10: tests/lib/test_credentials.py — 219 passed, 4 skipped
  • Ruff lint and format checks passed for both touched files
  • a direct production-path smoke test confirmed os.fchmod is absent, _atomic_write_credentials() still atomically wrote and re-read dummy rotated credentials, and no temporary file remained
  • git diff --check passed and the worktree is clean

The smoke test used an isolated temporary directory and no real credentials, API calls, or external services.


# -- "type": "authorized_user" ----------------------------------------

def test_atomic_write_credentials_without_fchmod(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you move these tests under the security: credentials file permissions section? Right now they're under the "type": "authorized_user" section

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

2 participants