Skip to content

fix(web): write dashboard Anthropic OAuth creds atomically with 0600 perms#11004

Closed
shaun0927 wants to merge 1 commit into
NousResearch:mainfrom
shaun0927:verify/dashboard-oauth-file-perms
Closed

fix(web): write dashboard Anthropic OAuth creds atomically with 0600 perms#11004
shaun0927 wants to merge 1 commit into
NousResearch:mainfrom
shaun0927:verify/dashboard-oauth-file-perms

Conversation

@shaun0927

Copy link
Copy Markdown
Contributor

Summary

Fixes #11003.

The dashboard's Anthropic OAuth helper wrote the credential file directly to its final path and relied on the process umask for permissions. That made this one write path weaker than Hermes's adjacent auth writers, which already use owner-only permissions and safer write semantics.

This PR keeps the scope intentionally narrow:

  • write the dashboard OAuth payload to a temp file
  • flush() + fsync() before replace
  • os.replace() into the final path
  • chmod(0600) on the final file
  • clean up temp files in a finally block

Why this shape

Recent merged Hermes fixes that land quickly tend to have three traits:

  1. narrow scope
  2. explicit root cause
  3. focused regression coverage

This follows that pattern. It does not refactor the broader auth stack or change the dashboard flow beyond making its credential write behavior match the repo's existing conventions.

What changed

  • hermes_cli/web_server.py
    • replaced direct write_text(...) with temp-file write + os.replace()
    • added owner-only permission tightening on the final credential file
    • cleans temp files if the write path fails
  • tests/hermes_cli/test_web_server_oauth_write.py
    • verifies 0600 under umask 022
    • verifies the helper uses atomic replace semantics and cleans temp files on failure

Test plan

pytest -o addopts='' tests/hermes_cli/test_web_server_oauth_write.py tests/hermes_cli/test_web_server.py -q
# 78 passed

…ees as other auth paths

The web dashboard's Anthropic OAuth helper wrote the credential file
straight to its final destination and relied on the process umask for
permissions. That left the dashboard-specific path weaker than the
existing auth writers, which already use owner-only permissions and
safer write semantics.

This change keeps the scope narrow: make the dashboard helper write via
a temp file + replace, chmod the final file to owner-only, and add a
focused regression test for both permission handling and atomic-write
behavior.

Constraint: Must preserve the existing dashboard OAuth flow and credential-pool side effects
Rejected: Broader auth-storage refactor | unnecessary scope for a single verified inconsistency
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Keep dashboard credential writes aligned with existing auth storage semantics; do not reintroduce direct write_text() here without matching chmod/atomic behavior
Tested: pytest -o addopts='' tests/hermes_cli/test_web_server_oauth_write.py tests/hermes_cli/test_web_server.py -q (78 passed)
Not-tested: Cross-platform permission semantics on Windows-managed filesystems
@shaun0927

Copy link
Copy Markdown
Contributor Author

This is ready for review on my side. If GitHub Actions are waiting on maintainer approval because this is a fork PR from a first-time external contributor, please approve the workflow run so the normal checks can start.

@shaun0927

Copy link
Copy Markdown
Contributor Author

Re-validated this in an isolated worktree against current origin/main (24fa0557).

Current diff is still intentionally narrow:

  • hermes_cli/web_server.py
  • tests/hermes_cli/test_web_server_oauth_write.py

Targeted validation still passes locally:

  • source venv/bin/activate
  • pytest -o addopts='' tests/hermes_cli/test_web_server_oauth_write.py tests/hermes_cli/test_web_server.py -q
  • result: 78 passed

So the atomic write + 0600 permission fix still looks good from my side. If GitHub Actions are still waiting on maintainer approval because this is a fork PR, approving the workflow run should be enough to let the normal checks execute.

@alt-glitch alt-glitch added type/security Security vulnerability or hardening P2 Medium — degraded but workaround exists area/auth Authentication, OAuth, credential pools provider/anthropic Anthropic native Messages API comp/cli CLI entry point, hermes_cli/, setup wizard labels Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/auth Authentication, OAuth, credential pools comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists provider/anthropic Anthropic native Messages API type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: dashboard Anthropic OAuth helper writes credential file with default umask permissions

2 participants