Repository navigation
Support expiring oauth tokens for better security - #5688
Closed
stephanmiehe wants to merge 1 commit into
Closed
stephanmiehe wants to merge 1 commit into
stephanmiehe wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
An in-flight request can fail after token rotation and incorrectly disable HACS and trigger reauthentication, because authentication failures are not retried with the newly valid credential.
1 open issue
What changed in this PR
Adds expiring GitHub OAuth credentials to HACS, with automatic refresh while preserving existing non-expiring logins.
Changes:
- Stores token lifetimes and coordinates refresh, rotation, unload, and shutdown.
- Updates both GitHub clients without reloading HACS and redacts refresh tokens from diagnostics.
- Adds regression tests and API-usage snapshots for refresh and reauthentication.
| File | Description |
|---|---|
tests/test_config_flow.py |
Tests expiring-token login, reauthentication, and token-only updates. |
tests/test_auth.py |
Tests rotation, failures, concurrency, shutdown, and client updates. |
tests/snapshots/api-usage/tests/test_config_flowtest-refreshable-device-flow-true.json |
Records reauthentication API usage. |
tests/snapshots/api-usage/tests/test_config_flowtest-refreshable-device-flow-false.json |
Records initial authorization API usage. |
tests/snapshots/api-usage/tests/test_authtest-terminal-failure-starts-existing-reauth-flow.json |
Records terminal refresh-failure API usage. |
tests/snapshots/api-usage/tests/test_authtest-refreshed-credentials-reach-both-clients-without-reload.json |
Records API usage after client credential updates. |
custom_components/hacs/system_health.py |
Routes health requests through refresh-aware handling. |
custom_components/hacs/repositories/base.py |
Resolves current credentials before legacy repository requests. |
custom_components/hacs/diagnostics.py |
Uses refresh-aware requests and redacts refresh tokens. |
custom_components/hacs/config_flow.py |
Requests offline access and stores complete token metadata. |
custom_components/hacs/base.py |
Synchronizes client credentials before API calls. |
custom_components/hacs/auth.py |
Adds token validation and coordinated refresh management. |
custom_components/hacs/__init__.py |
Integrates token-manager lifecycle and avoids token-only reloads. |
Review effort: Balanced
Comment on lines
+514
to
516
| if self.auth is not None: | ||
| await self.async_get_github_token() | ||
| return await method(*args, **kwargs) |
Member
|
Hi there 👋 HACS is moving to Home Assistant as the Marketplace, so no changes will be made to this integration. If your PR is still needed in the Marketplace integration, check out the Home Assistant contributor documentation for how to contribute there. Closing this one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Add expiring GitHub OAuth tokens with automatic refresh, safe rotation and shutdown handling, and reauthentication when needed. Preserve existing non-expiring logins and redact refresh tokens from diagnostics.
Using expiring tokens ensures that should a token ever leak, the exposure is limited by the lifetime of the oauth token. There is an influx in security incidents going on around the world because threat actors are finding oauth tokens and weaponizing them.
Validation
Regression tests and lint pass. Full suite: 579 passed, followed by a Python shutdown crash also reproduced on the unchanged baseline.
Rollout
Eventually, you'll want to set the recently introduced config flag in your GitHub Oauth app that forces all tokens to be expiring. However, you want to give people some time to upgrade before you do that since once you flip that switch, users will need to re-auth using a version of HACS that has the token renewal logic being added in this PR