Repository navigation
feat(auth): end the sign-in at the server on logout - #45
vigubikReply wants to merge 1 commit into
Conversation
`reply auth logout` now revokes the stored refresh token at the sign-in server's revocation endpoint (RFC 7009) before it removes the stored record, so a logged-out sign-in can't be refreshed again. Until now it only removed the local record. The read, the revocation and the removal share one hold of the credentials lock. When the server doesn't confirm (a refusal, a redirect, a timeout, an unreachable server, or a record that changed during the revocation), the record is still removed and one warning says the sign-in may still be valid. `--json` gains `revoked`.
| }); | ||
| // The answer's body says nothing more (RFC 7009 §2.2); dropping it frees the connection. | ||
| await res.body?.cancel().catch(()=>undefined); | ||
| return res.ok ? {revoked: true} : {revoked: false, status: res.status}; |
There was a problem hiding this comment.
Non-blocking, the fix belongs in Identity: a 2xx here means the server deleted the token we sent, not that the sign-in ended. If someone with a copy of the credentials file refreshed first (T1 → T2), the file still holds the spent T1. Logout sends T1, Identity deletes only T1's row (IdentityServer4 revokes just the handle it's given) and answers 200, so we print revoked: true while the copy's T2 keeps refreshing, indefinitely under Sliding with no cap. Reuse detection from reply-team/Reply.Identity#840 doesn't catch it, since a logout never goes through a refresh.
Suggest a follow-up in Identity: revoking a refresh token also deletes its sign-in's live token (RefreshTokenRevoker.RevokeSignInAsync), so revoked: true holds whichever token of the sign-in the file has.
There was a problem hiding this comment.
Agreed. The server will end the whole sign-in when any of its refresh tokens is revoked, for clients with reuse detection on. That is a server change and comes as a follow-up there; nothing changes in this PR.
There was a problem hiding this comment.
One limit to add: the server knows a used refresh token only until that token expires (30 days after it was issued) and is cleaned up. Past that, revoking it ends nothing, and a password change is what ends the sign-in.
What changed
reply auth logoutnow ends the sign-in at the sign-in server as well as on this computer. Until now it onlyremoved the stored record, and the refresh token stayed valid at the server until its lifetime ran out.
The request: for a stored OAuth sign-in, the CLI posts the record's refresh token to the server's
revocation endpoint (RFC 7009),
${authority}/connect/revocation, withtoken_type_hint=refresh_tokenandthe CLI's
client_id, under the same User-Agent as the token requests and with the same 20 s timeout. Then itremoves the record.
One hold of the credentials lock covers the record's read, the revocation and the removal, so a refresh by
another process can't store a newer token in between. A logout holds the lock no longer than a refresh does;
CONTRIBUTING.mdwrites the sum out.When the server doesn't confirm, the logout still happens here. The record is removed, the exit code stays
0, and one line on stderr says the sign-in may still be valid at Reply, with the cause:
revokedtruefalsefalsefalsefalseA redirect isn't followed. Following one would post the refresh token wherever it points, and a page
answering there would read as confirmed.
--jsongainsrevokedbesidelogged_out. It is left out when nothing was sent: an API-key record, anOAuth record with no refresh token, or no record.
A logout acts on the stored record, whatever
--api-keyorREPLY_API_KEYsupplies. An API key is neversent to the revocation endpoint. No token is ever printed.
Docs: the README's "Authentication" and
CONTRIBUTING.md("Credentials on disk", "Tests") describe the newbehaviour. The help text of
auth logoutnow reads "End the stored sign-in at Reply and remove the storedcredential".
Why
A logout that only deletes a file doesn't sign anyone out at the server. A copy of the credentials file taken
before the logout could go on refreshing the sign-in afterwards, and the person who logged out had no way to
end it.
How it was verified
Tests first. Every new or changed test was run against the code before the change and failed.
src/__tests__/auth/refresh-processes.test.ts): built CLI processes run against a fakesign-in server on
127.0.0.1. The fake now applies a refresh when it arrives and holds only the answer, as areal server does, and has a strict revocation endpoint.
the fake ends with no live refresh token and the record is gone.
revoked: false, onewarning line, and no token in stdout or stderr. The redirect's target never receives the token.
revoked: false.REPLY_API_KEYset and--api-keypassed, a stored OAuth record is still revoked, the server sees onerequest, and its body holds none of the keys. With an API-key record or no record, nothing is sent.
src/__tests__/auth/oauth-flow.test.ts) against a server that acceptsand never answers.
the
token_type_hintdropped, the User-Agent dropped, the timeout misclassified.npm run build, thennpm test: 67 files, 1113 tests passed, 2 skipped (the existingcase-insensitive-filesystem tests).
Not yet run against a live sign-in server. That run comes before the merge.
Compatibility
Additive:
logged_outkeeps its meaning and the exit codes are unchanged. A new field in--jsonoutput is aminor change under "What counts as breaking", so this is a
feat.