standard_id 0.36.0 → 0.36.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7dd8850abb672f638f6db5cf4d60ae8ec64b26bdb8d5835405c72e7bebc4d800
4
- data.tar.gz: 69575f6669362c905ed16059f35f15044f1ee2bbade449b6dc5c62bfd93caeb5
3
+ metadata.gz: 5519e19cd0f121d012683a24a10d0052ce4bf33e508ede831712db3851abace9
4
+ data.tar.gz: 9786b159f6ad07238cb7e636f3cfd5e028ec31cb6014f38e0349de3760f0deaf
5
5
  SHA512:
6
- metadata.gz: 87ed7e67e16666c2c576a2e7bb55e43ff2a861ecf93c824d5995da4d8f383d09f4bb60e8b389e9821e2d85acfb849690548cc0e6fbfabaa3e73d0f02dd44015c
7
- data.tar.gz: 9036f22d16ee08ac97a4e5d6ae46d8c6fc7c63130da4ed66a815dfef2b21ecce787f576cc2127dbd6040405e6a6dbd2f4f71c5303d1c6e803770347af6d85b9f
6
+ metadata.gz: b18d51d0fc882c6aaf4c9a6482e58600bf82594860715c1b6f5850dd0175834f72dc5735dbb23b2e1f45fbc4ceb8f975dffdc2484a3ee1871b882e89d76c4df6
7
+ data.tar.gz: 7039cfdf1894c351a3802b893e31a2ff23754acd0a861116b190ca5875540a7ba45d35589cefef79ad1a65444feca3eb999740285bc5af0bd073139d41fdedbc
data/CHANGELOG.md CHANGED
@@ -7,6 +7,36 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.36.1] - 2026-08-04
11
+
12
+ **A follow-up to 0.36.0's own regression, released the same day.** 0.36.0 is correct and stays — read its entry first for why `SESSION_VALIDATING` had to start carrying `account:`. This release repairs the fallout of that fix on the gem's own API routes. Two releases land together because the second is only reachable *because* of the first.
13
+
14
+ ### Fixed
15
+
16
+ - **`StandardId::Api::BaseController` now answers `401` — not `500` — when the authenticated account is deactivated or locked.** 0.36.0 made `AccountStatus` / `AccountLocking` fire on a live authenticated request for the first time, which is the intended behaviour. But `AccountDeactivatedError` and `AccountLockedError` are bare `StandardError` subclasses, under neither `InvalidSessionError` nor `OAuthError`, and the API base controller rescued only those three families. So the very change that started refusing a disabled account's bearer token turned every route under `ApiEngine` — `/api/v1/sessions`, `/api/v1/userinfo`, all of it — into an unhandled exception for that account. Every consumer mounting `ApiEngine` inherited it. Before 0.36.0 the guard was inert on that path, so the hole existed but was unreachable; the release is what exposed it.
17
+
18
+ Observed independently in two consumers during the 0.36.0 rollout: `luminality-web`, which has an app-side handler on `Api::ErrorHandling` and so saw only the *gem-owned* routes fail, and `sidekick-web`, which has none and saw its whole API tree fail.
19
+
20
+ A 500 is not a refusal. It carries no `WWW-Authenticate`, tells the client nothing about discarding a token that will never work again, and pages the on-call for a routine account state. Both errors now render the established bearer shape — `401`, `{ "error": "invalid_token", "error_description": … }`, plus the matching `WWW-Authenticate` challenge — via the same `render_bearer_unauthorized!` the other credential failures use. No new response shape was invented.
21
+
22
+ **Why `invalid_token`.** RFC 6750 §3.1 defines exactly three codes. `invalid_token` covers a token "expired, revoked, malformed, or **invalid for other reasons**", and a token whose subject account has been disabled is invalid for one of those other reasons; it also carries the right client instruction — discard the token and re-authenticate — which is precisely correct here, since no retry with this token can ever succeed. `insufficient_scope` (403) would be wrong twice over: nothing about this is a scope failure, and 403 invites a client to keep the token and retry. `invalid_request` (400) would be wrong because the request is perfectly well-formed.
23
+
24
+ `AccountLockedError#lock_reason` is **not** surfaced. It is operator-authored text meant for logs and admin screens, and `WWW-Authenticate` is a quoted string that arbitrary text would break as well as leak. A spec pins that the reason appears in neither the body nor the header.
25
+
26
+ ### Unchanged, deliberately — two decisions worth knowing about
27
+
28
+ - **The `WebEngine`'s own routes (`/sessions`, `/account`, `/logout`) get no gem-side handler, and this is not an oversight.** `StandardId::Web::BaseController` descends from the **host's** `ApplicationController`, so the `rescue_from StandardId::AccountDeactivatedError` the README has always told hosts to write already covers those routes. A gem handler there would not add safety, it would remove it: Rails scans `rescue_handlers` most-recently-registered-first, and a subclass registers after its parent, so anything the gem registered on `Web::BaseController` would outrank and silently override the host's — replacing a host's "your account has been deactivated" page with whatever the gem chose. `Api::BaseController` has no such escape hatch; descending from `ActionController::API`, there is nowhere in its ancestry for a host to put a handler, which is exactly why only that side is rescued in the gem.
29
+
30
+ **Hosts must therefore still carry their own `ApplicationController` handler for these two errors.** If you do not have one, a deactivated or locked account hitting a web route — yours or the engine's — is an unhandled exception. That was true before 0.36.0 for the sign-in path and remains true; 0.36.0 simply widened the set of requests that can reach it from "sign-in and token mint" to "any authenticated request". The README's account sections now spell out which routes the engine answers for and which it does not.
31
+
32
+ - **`AccountDeactivatedError` / `AccountLockedError` still descend from `StandardError`, not from `InvalidSessionError`.** Reparenting them was considered as the broader fix — it would make every consumer's existing `rescue_from StandardId::InvalidSessionError` catch them automatically, with no consumer change at all — and rejected on two grounds. First, they mean something genuinely different: an `InvalidSessionError` says the credential is no good and the remedy is to sign in again, while these say the credential is fine and the account is disabled, where signing in again will not help and the user needs to be told so. Consumers who deliberately distinguish the two would lose that distinction silently. Second, and decisively, it would hijack handlers hosts have already written: `Web::BaseController` registers `rescue_from NotAuthenticatedError, InvalidSessionError, with: :redirect_unauthenticated_to_login`, so under the reparented hierarchy a host's `rescue_from AccountDeactivatedError` — registered *earlier*, on the parent — would lose to the gem's subclass registration, and every consumer following the README would start bouncing disabled users to `/login` instead of to their account-disabled page. A patch release that quietly re-routes a documented UX is not a patch. The narrow fix leaves both hierarchies and both sets of host handlers exactly as they were.
33
+
34
+ ### Testing
35
+
36
+ `spec/requests/standard_id/live_session_account_guard_spec.rb` gains three API examples (401 shape for deactivated, 401 shape for locked, and `lock_reason` non-disclosure) and two web examples pinning the delegate-to-host design above. Proven by negative control: with the two `rescue_from` lines deleted from `Api::BaseController`, the three API examples fail with the raw error escaping the request; restored, the file is 14/14 and the suite 2097/2097.
37
+
38
+ Relates to rarebit-one/rarebit-ops#306.
39
+
10
40
  ## [0.36.0] - 2026-08-04
11
41
 
12
42
  ### Security
data/README.md CHANGED
@@ -784,7 +784,14 @@ User.inactive # => Users with status 'inactive'
784
784
 
785
785
  ### Handling AccountDeactivatedError
786
786
 
787
- When an inactive account attempts to authenticate, `StandardId::AccountDeactivatedError` is raised. You need to handle this error in your application controller:
787
+ When an inactive account attempts to authenticate — at sign-in, at token mint, and (since 0.36.0) on every request made with an already-issued credential — `StandardId::AccountDeactivatedError` is raised. You need to handle this error in your application controller:
788
+
789
+ > **What the engine's own routes do.** You are responsible for **your** controllers only. The engine handles its own:
790
+ >
791
+ > - **`ApiEngine` routes** (`/api/v1/sessions`, `/api/v1/userinfo`, …) answer **`401` with `error: "invalid_token"`** per RFC 6750 — `StandardId::Api::BaseController` descends from `ActionController::API`, so your `rescue_from` is not in its ancestry and could never have covered it.
792
+ > - **`WebEngine` routes** (`/sessions`, `/account`, `/logout`) are covered by the `rescue_from` you write on `ApplicationController` below, because `StandardId::Web::BaseController` descends from it. The engine deliberately registers no handler of its own there — one would take precedence over yours and override your UX.
793
+ >
794
+ > So: write the `ApplicationController` handler (it covers your pages *and* the web engine's), and write the `Api::BaseController` handler only for **your own** API controllers.
788
795
 
789
796
  ```ruby
790
797
  # app/controllers/application_controller.rb
@@ -900,7 +907,7 @@ User.unlocked.active # => Users who can log in
900
907
 
901
908
  ### Handling AccountLockedError
902
909
 
903
- When a locked account attempts to authenticate, `StandardId::AccountLockedError` is raised. The error includes metadata about the lock:
910
+ When a locked account attempts to authenticate, `StandardId::AccountLockedError` is raised. The error includes metadata about the lock. The same engine-owned-route rules described under [Handling AccountDeactivatedError](#handling-accountdeactivatederror) apply: `ApiEngine` routes answer `401 invalid_token` themselves (never echoing `lock_reason`), `WebEngine` routes defer to your `ApplicationController` handler.
904
911
 
905
912
  ```ruby
906
913
  # app/controllers/application_controller.rb
@@ -16,6 +16,16 @@ module StandardId
16
16
  rescue_from StandardId::InvalidSessionError, with: :handle_invalid_session
17
17
  rescue_from StandardId::OAuthError, with: :handle_oauth_error
18
18
 
19
+ # AccountStatus / AccountLocking raise these from the SESSION_VALIDATING
20
+ # subscriber, i.e. mid-request on an ALREADY authenticated call, not just
21
+ # at sign-in or token mint. Unrescued they are a 500 on every gem-owned
22
+ # API route. Unlike Web::BaseController — which descends from the host's
23
+ # ApplicationController, so a host `rescue_from` covers it — this class
24
+ # descends from ActionController::API, so the host has nowhere to put a
25
+ # handler in the ancestry and the gem must answer for itself.
26
+ rescue_from StandardId::AccountDeactivatedError, with: :handle_account_deactivated
27
+ rescue_from StandardId::AccountLockedError, with: :handle_account_locked
28
+
19
29
  protected
20
30
 
21
31
  def validate_content_type!
@@ -43,6 +53,27 @@ module StandardId
43
53
  render_bearer_unauthorized!(error_description: default_invalid_token_message)
44
54
  end
45
55
 
56
+ # RFC 6750 §3.1 offers exactly three error codes, and `invalid_token` is
57
+ # the right one: it covers a token "expired, revoked, malformed, or
58
+ # invalid for other reasons", and a bearer token whose subject account has
59
+ # been disabled is invalid for one of those other reasons. It also carries
60
+ # the correct client instruction — discard the token and re-authenticate —
61
+ # which is what we want, since no retry with this token will ever succeed.
62
+ # `insufficient_scope` (403) would be wrong: nothing here is about scope,
63
+ # and a 403 invites the client to keep the token and retry. `invalid_request`
64
+ # (400) would be wrong: the request is well-formed.
65
+ def handle_account_deactivated(_error)
66
+ render_bearer_unauthorized!(error_description: "The account is deactivated")
67
+ end
68
+
69
+ # Deliberately does NOT surface `error.lock_reason`. It is operator-authored
70
+ # text intended for logs and admin screens (see StandardId::AccountLockedError),
71
+ # and the WWW-Authenticate header this renders into is a quoted string that
72
+ # arbitrary text would break as well as leak.
73
+ def handle_account_locked(_error)
74
+ render_bearer_unauthorized!(error_description: "The account is locked")
75
+ end
76
+
46
77
  def handle_oauth_error(error)
47
78
  render json: {
48
79
  error: error.oauth_error_code,
@@ -7,6 +7,31 @@ module StandardId
7
7
  class RevokedSessionError < InvalidSessionError; end
8
8
 
9
9
  # Account errors
10
+ #
11
+ # These deliberately do NOT descend from InvalidSessionError, even though
12
+ # doing so would make every host's existing `rescue_from InvalidSessionError`
13
+ # catch them for free. Two reasons:
14
+ #
15
+ # 1. They mean something different. An InvalidSessionError says the
16
+ # credential is no good — expired, revoked — and the remedy is to sign in
17
+ # again. These say the credential is fine and the ACCOUNT is disabled;
18
+ # signing in again will not help, and the user needs to be told so.
19
+ # Hosts document that distinction in their UX (see the README's
20
+ # "Handling AccountDeactivatedError" / "Handling AccountLockedError").
21
+ # 2. Reparenting them would silently HIJACK the handlers hosts already
22
+ # wrote. Web::BaseController registers
23
+ # `rescue_from NotAuthenticatedError, InvalidSessionError, with:
24
+ # :redirect_unauthenticated_to_login`, and Rails resolves rescue_from
25
+ # handlers most-recently-registered-first — a subclass's registration
26
+ # wins over its parent's. A host's `rescue_from AccountDeactivatedError`
27
+ # on ApplicationController is registered EARLIER than the gem's
28
+ # subclass registration, so as a subclass of InvalidSessionError these
29
+ # would start bouncing to /login instead of reaching the host's
30
+ # account-deactivated page. That is a behaviour regression for every
31
+ # consumer who followed the README.
32
+ #
33
+ # Consequently every entry point that must not raise has to rescue these
34
+ # explicitly; StandardId::Api::BaseController does.
10
35
  class AccountDeactivatedError < StandardError; end
11
36
 
12
37
  class AccountLockedError < StandardError
@@ -1,3 +1,3 @@
1
1
  module StandardId
2
- VERSION = "0.36.0"
2
+ VERSION = "0.36.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.36.0
4
+ version: 0.36.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaryl Sim