You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
auth: add versioned secure-storage format for credentials [3/10] - #22938
Adds the secure-storage format for rotating credentials on its own, before anything writes them.
A credential with no refresh token is stored as the bare access token, the format every install already uses. No migration is needed, and older Desktop versions can still read it.
A rotating pair is stored as github-desktop-oauth:{"version":1,"credential":{...}}: access token, refresh token and both expiry times in one secure-store item.
A malformed record throws a fixed error that never includes the stored contents.
On load, AccountsStore deletes records that hold no usable credential and drops those accounts. Records it can't parse are handled like any other secure-storage read error: logged, reported, and the account is skipped.
addAccount writes through the serializer, which gives the same value as today for plain tokens.
No behavior change for existing accounts.
Stack
Merge in order, starting with 1. Each PR builds, passes tests, and keeps production behavior on its own.
The sentinel is itself a valid token according to isToken (it is non-empty and contains no whitespace). As a result, a plain opaque token beginning with github-desktop-oauth: is serialized verbatim but then parsed as a versioned record, so it cannot round-trip and an existing account using such a token will be skipped at startup. Use a sentinel outside the accepted token grammar (for example, one containing whitespace) and update the format tests accordingly.
According to Copilot (which seems correct AFAICT):
Re the sentinel collision note on account-credential.ts: leaving it as is on purpose. GitHub and GHES tokens only use [A-Za-z0-9_] (classic 40-hex, gho_/ghu_/ghp_/ghs_/ghr_, github_pat_), so no real token can contain :, let alone start with github-desktop-oauth:. Only a forged OAuth response could produce one, and at that point the server has far worse options. A whitespace sentinel would make every stored value odd with no practical gain.
The reason will be displayed to describe this comment to others. Learn more.
The versioned credential format is well scoped: rotating token pairs are stored atomically, legacy bare-token compatibility is preserved, malformed records fail with secret-safe errors, and token/expiry validation is appropriately strict.
We reviewed the startup case where cleaning up one unusable credential can persist an account list that excludes another account whose keychain read failed. The consequence is reauthentication rather than repository or server-side data loss, and we consider that an acceptable recovery tradeoff for this layer. The remaining observations around repeated corrupted-record errors, explicit undefined expiry properties, and expiry-only non-refreshable tokens are non-blocking.
Short-lived OAuth tokens come with a refresh token and expiry times,
and all of it has to live in the OS secure store: the refresh token is
a secret, and splitting the pair across items could leave a new access
token next to an old refresh token. Introduce the storage format on its
own, before anything writes rotating credentials, so it can be
reviewed in isolation.
`account-credential.ts` serializes a credential as:
- the bare access token when there is no refresh token. This is the
format every existing install already uses, so plain tokens keep
working, need no migration, and stay readable by older Desktop
versions;
- `github-desktop-oauth:` followed by
`{"version":1,"credential":{...}}` for a rotating pair, holding the
access token, refresh token and both expiry times in one item.
Reading accepts both formats. A versioned record whose credential is
`null` means "no usable credential". A malformed or unsupported record
throws a fixed error that never includes the stored contents, so
secrets can't leak into logs or error dialogs.
AccountsStore reads secure storage through this parser:
- plain tokens load exactly as before;
- a record with no usable credential (including an empty value) is
deleted, and the account is dropped from the saved account list;
- a record that can't be parsed is treated like any other secure
storage read error: logged, reported, and the account is skipped.
`addAccount` writes through `serializeAccountCredential`, which for
today's plain tokens produces the same value as before. Nothing writes
rotating pairs yet, so this change has no behavior change for existing
accounts.
Tests cover reading plain tokens, round-tripping a rotating pair and
the `null` marker, rejecting corrupted records without exposing
secrets, and removing accounts whose stored credential is the `null`
marker.
Co-authored-by: Copilot <[email protected]>
Versioned secure-store records (`github-desktop-oauth:` + JSON) were
validated more loosely than the OAuth responses they come from.
`deserializeAccountCredential` only required `accessToken` and
`refreshToken` to be non-empty strings, while `parseOAuthToken` also
rejects any value containing whitespace. A record such as
`{"accessToken":" ","refreshToken":"secret"}` was therefore loaded as
a usable credential instead of producing the fixed "Unable to read
stored OAuth credentials. Please sign in again." error.
Desktop only ever writes versioned records with tokens that already
passed `parseOAuthToken`, so this can only happen through external
tampering or corruption of the secure store. The practical impact was
small: the malformed token would be sent, rejected with a 401 and the
account signed out. With this change the record is instead reported
as unreadable at load time and the account is skipped, which is the
behavior the storage layer already promises for every other malformed
record.
Changes:
- `oauth-token.ts`: export the existing `isToken` guard (non-empty
string without whitespace) with a JSDoc comment so both parsers
share one definition of a valid token value.
- `account-credential.ts`: use `isToken` for both `accessToken` and
`refreshToken` in versioned records instead of the ad-hoc
`typeof === 'string' && length > 0` checks.
- `account-token-lifecycle-test.ts`: add a whitespace-only access
token and an embedded-whitespace refresh token to the "rejects
corrupted or unsupported records without exposing secrets" cases.
The test fails without the source change and passes with it.
Legacy bare-token records are intentionally left unvalidated. That is
the format every existing install uses and matches the `development`
behavior this stack preserves.
Addresses review feedback on #22938.
Co-authored-by: Copilot <[email protected]>
sergiou87
changed the title
auth: add versioned secure-storage format for credentials [3/9]
auth: add versioned secure-storage format for credentials [3/10]
Oct 2, 2026
Brings in short-lived token support (#22917, #22937, #22938, #22939) and
adapts it to multiple accounts per endpoint:
- Credential sessions are keyed per account (endpoint + login) instead of
per endpoint, so renewal, invalidation and storage writes are isolated.
- AccountsStore lookups, retirement and refresh match the exact account.
- The invalidated token dialog names the signed-out login and offers a
targeted sign-in for that account.
Co-authored-by: Copilot App <[email protected]>
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
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.
Description
Adds the secure-storage format for rotating credentials on its own, before anything writes them.
github-desktop-oauth:{"version":1,"credential":{...}}: access token, refresh token and both expiry times in one secure-store item.addAccountwrites through the serializer, which gives the same value as today for plain tokens.No behavior change for existing accounts.
Stack
Merge in order, starting with 1. Each PR builds, passes tests, and keeps production behavior on its own.
Validation
Release notes
Notes: no-notes