fix(backend): report a rejected token as Unauthenticated, not as a crash - #299
Merged
Conversation
Two jwt versions were installed: `auth.go` reads tokens with v5, while `errors.go` matched v4's `*jwt.ValidationError` — a type v5 deleted. The match never fired, so every expired, malformed, badly signed or wrongly issued token fell past the Unauthenticated list to `codes.Internal`, and a routine expired session was reported and logged as a server fault. Matches v5's sentinels with `errors.Is`, adds the issuer case v5 raises that nothing was mapping, and drops the now-unused jwt/v4 dependency — `errors.go` was its only importer. The invitation page no longer has to read INTERNAL as an expired session, so a real fault can say so. The auth tests asserted error messages, which come from the library and matched either way. They now assert the gRPC code, and did fail before this change.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Expired logins stop looking like server crashes
Before: your login token expires — completely routine — and the backend reported it as an internal server error. Two consequences. Users got misleading messages: the invitation page had to treat "server error" as "your sign-in expired", because that's what actually arrived, so a genuine server problem told people to sign in again over an invitation that was working fine. And in the logs, every ordinary expired session showed up as a server fault, so anything watching error rates was counting normal behaviour as breakage.
The cause: two versions of the same JWT library were installed. The code that reads tokens used the new one; the code that translated the errors checked for a type the new version had deleted. So the translation never matched, and every rejected token fell through to the catch-all: "internal error".
Now: a rejected token is reported as a rejected token. A real server fault is reported as a real server fault, and the invitation page says so instead of blaming your sign-in.
Details