Skip to content

fix(authserver): a suspended, revoked or locked client gets no token, authorization or active introspection (#345) - #350

Merged
dfcoffin merged 8 commits into
mainfrom
fix/345-enforce-client-suspension
Nov 30, 2026
Merged

dfcoffin merged 8 commits into
mainfrom
fix/345-enforce-client-suspension

Conversation

@dfcoffin

@dfcoffin dfcoffin commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #345. Part 2 of #344 (plan); part 1 was #346.

Suspending, revoking or locking a client through PUT /api/v1/oauth2/clients/{clientId}/status now takes effect. Before, the status was stored and nothing read it, and on PostgreSQL it was not even stored.

Changes

  1. ClientStatusService decides whether a client may use the AS now:

    • its client_status is active (a NULL means the column default, active) and its locked_until, if set, has passed;
    • a stored suspended or revoked lasts until the client is set active. A lock only ever restricts (round 3): it suspends an active client while it runs and never ends a stored status. So a suspension with lock_duration_minutes is stored as active with locked_until, and ends on its own when the lock does. Whatever writes locked_until (the database, or a future lockout, fix(authserver): max-failures-before-lock and default-lock-duration-minutes are documented but never applied #353), it can't let a client in;
    • any other stored value counts as revoked; a client with no row is not active.

    It reads the database on every call, so a suspension, a reactivation or the end of a lock applies to the next request. A database error is not caught: the request fails rather than letting the client in.

  2. ClientStatusEnforcement applies it through Spring Authorization Server's own hooks:

    Where A client that is not active
    Client authentication: /oauth2/token, /oauth2/introspect, /oauth2/revoke 401 invalid_client, as for a wrong secret, with no description, so nothing says the secret was right. No new token, refresh or client_credentials token.
    /oauth2/introspect Its existing tokens are reported active: false, so the DC releases no data. The tokens are kept: on reactivation they work again until they expire.
    /oauth2/authorize 400, the same error Spring gives an unknown client_id, with no redirect to the client (RFC 6749 4.1.2.1). It runs before the redirect URI and scope checks (Spring checks the grant type first), and again on the replay that would mint the code.
  3. /authorize/delegate can be reached without going through /oauth2/authorize. It now refuses an unknown or inactive client with 400 before the customer is sent to the DC. /oauth2/authorize/continue does the same when the customer comes back: a client suspended while the customer was at the DC gets neither a code nor an access_denied redirect.

  4. The AS's own bearer-token check (AuthorizationServiceOpaqueTokenIntrospector, used by the admin API, actuator and /oauth2/register) refuses a token of an inactive client, as /oauth2/introspect does.

  5. Pre-existing: on PostgreSQL the status update always answered 500. client_status is the enum type client_status_type, which refuses a text parameter. The update now casts to it there (CAST(? AS client_status_type)), with the database read once at startup, as for the audit JSON (fix(authserver): client management API: list always 500, status without reason 500s after applying, bulk logs raw ids, null scope saved; fix or retire the controller #344 review).

  6. H2: the new migration V12__client_status_columns adds client_status (with the same three values), locked_until and updated_by. H2 skipped V2 (Complete #123 schema-repair sync: align AS V1 schema with application code column names #145), so the status update failed there, and so would the new check.

revoked and suspended act the same. Ending a client's tokens for good is a client delete (#346), or #349 once fixed.

Docs: OAUTH2_CLIENT_MANAGEMENT_API.md says what each status does.

Not covered

Tests

  • ClientSuspensionScenarios, run on MySQL (ClientSuspensionMySqlIntegrationTest) and PostgreSQL (ClientSuspensionPostgreSqlIntegrationTest), 8 each. The status is changed through the real status endpoint as an administrator:
    • suspended: no token, invalid_client with no description; reactivated: a token again;
    • revoked: no token;
    • locked: no token until the lock ends, then a token;
    • suspended with lock_duration_minutes through the endpoint: stored as active with a lock in whole seconds; no token until the lock ends, then a token; client details and the list's status filter report suspended, then active;
    • suspended without a lock, then a lock written that has already passed: still no token, still reported suspended, with no locked_until;
    • a suspended client's existing token introspects active: false without its claims, and active again after reactivation;
    • a suspended client cannot introspect, even its own token;
    • a suspended client's /oauth2/authorize and /authorize/delegate are 400 with no redirect; when active the same request is delegated to the DC.
  • ClientStatusServiceTest (28, against the real H2 migrations, including V12): each status and lock combination by id, by client_id, and as the status in force in Java and in the list's SQL; a lock written onto a stored suspension doesn't end it; any other stored value is revoked in Java and SQL; now() is the service's clock; lockInForce reports a lock only while it decides the status; an unknown or null client, H2 refusing an unknown status, and the PostgreSQL cast.
  • AuthorizationServiceOpaqueTokenIntrospectorTest (2): the AS's own bearer-token check accepts an active client's token and refuses an inactive one's.
  • AuthorizeDelegateControllerTest: an inactive client is refused and no handoff is built.
  • ClientCertificateServiceStatusTest: certificate validation follows ClientStatusService, and a database error refuses the client and is logged as a warning with its exception.
  • OAuth2ClientManagementControllerTest (with a fixed ClientStatusService clock): the list filters by the status in force at the clock's time for the page and the count; a timed suspension is written as active with the lock in whole seconds, and its audit holds the status asked for, its length and that end; lock_duration_minutes with active or revoked is 400; the list's status filter refuses paused, Suspended and a blank value with 400 before any query (the blank cases fail with the old check), and its statuses must equal the status update's @Pattern exactly, whose message must name each of them.
  • AuthorizeContinueControllerTest: a client that became inactive during the delegation gets 400 on allow (no grant context kept) and on deny (no access_denied redirect).
  • The PostgreSQL scenarios answered 500 on the status change before change 5. The enforcement tests were written with the fix, so their failing on the old code was not shown.
  • Full AS suite (WSL, Docker): 644 tests, 0 failures.

Code review

Security-sensitive (it decides whether a client gets tokens and whether customer data is released).

Round 1, /code-review high (whole PR):

# Finding Where it went
1 Important: lock_duration_minutes did nothing: the endpoint writes a lock only with suspended, and any status other than active was refused, so a timed suspension never ended (and the doc said it did) Fixed: a suspension whose lock has passed counts as active; ClientStatusServiceTest rows, a scenario through the endpoint on MySQL and PostgreSQL, doc corrected
2 A client suspended while the customer is at the DC still got an access_denied redirect on deny; the review also suspected Spring's consent POST could mint a code Deny path fixed (/oauth2/authorize/continue checks the status, 400); consent POST answered on the PR: unreachable since #305
3 Pre-existing: other PostgreSQL enum binds, and H2's create writing missing columns Filed #351, on #255
4 The config comment said a non-active client "learns nothing else", but Spring's grant-type check runs first Comment corrected

Fixes in 91a65c9. Round 1 found a real bug in this PR's own changes, so round 2 is a scoped /code-review xhigh of that commit.

Round 2, /code-review xhigh (scoped to 91a65c9):

# Finding Where it went
1 Important: after a timed suspension ends, client details, the list and its status filter still reported suspended, and locked_until was shown nowhere Fixed: ClientStatusService.statusInForce (and the same rule as SQL for the filter) is what client details and the list report, with locked_until; tested on MySQL and PostgreSQL
2 Important: the audit record of a status change left out the lock that now ends a suspension Fixed: lock_duration_minutes and locked_until are in the audit data
3 Pre-existing, made worse: certificate validation accepted only active and ignored the lock Fixed: ClientCertificateService asks ClientStatusService
4 Pre-existing: lock_duration_minutes with active or revoked was answered 200 and dropped Fixed: 400, as for other fields not applied (#332)
5 Pre-existing: max-failures-before-lock / default-lock-duration-minutes documented, read nowhere Filed #353, on #255
6 The class Javadoc's first paragraph still said only active lets a client in Fixed
7 The doc no longer said an active client with a running lock is refused Fixed
8 PostgreSQL/H2 timestamps without time zone are stored in the JVM's zone Filed #354, on #255

Round 2 found real problems in this PR's own changes (1, 2); fixes in 1933d8b; the owner chose a scoped xhigh (not ultra) for round 3. Under the review rules, if round 3 still finds a real bug, the automated reviews stop and the owner reviews the design.

Round 3, /code-review xhigh (scoped to 1933d8b):

# Finding Where it went
1 Design: a lock written onto an open-ended suspension ended it once the lock passed (only a direct write or a future #353 lockout could do it) Owner design review: a lock only ever restricts. A timed suspension is stored as active with locked_until; a stored suspended or revoked never ends on its own. Regression tests in ClientStatusServiceTest and on MySQL and PostgreSQL; doc updated; the constraint for a lockout (extend only, never shorten) is noted on #353
2 Client details answered 500 on a locked_until type its switch didn't list Fixed: read with getTimestamp, as the list does
3 For a stored value other than active/suspended, the SQL said revoked but Java returned the value Fixed: Java returns revoked; tested against the SQL
4 Client management used the system clock, enforcement ClientStatusService's Fixed: both use ClientStatusService.now()
5 The doc said locked_until is null when there is none; it's left out Doc fixed
6 The audit's locked_until kept fractions of a second that MySQL doesn't store Fixed: the lock is set in whole seconds
7 A database error during certificate validation was logged at debug as "not found" Fixed: a warning with the exception

Fixes in 45f1972. Fixing #1 treats it as a real bug in this PR's own changes, so round 4 goes up, not down; the owner chose a scoped xhigh (not ultra).

Round 4, /code-review xhigh (scoped to 45f1972):

# Finding Where it went
1 Important: rows stored as suspended with a lock before this change would stay suspended for good Answered on the PR: no deployed data has that shape (local test databases only, disposable; main never enforced the status); it fails closed
2 Pre-existing: the list's status filter wasn't validated: paused gave an empty page, and Suspended matched on MySQL only Fixed: 400 for anything but active, suspended, revoked
3 PostgreSQL's reporting views filter on the stored status only, so a timed suspension counts as active (no Java reads them) Filed #355, on #255
4 A timed suspension of a revoked client ends when its lock does, which contradicted the Javadoc's "nothing that writes locked_until can let a client in" Wording fixed: an administrator's status change replaces the earlier state, as setting active does; only other writers are limited to extending a lock
5 locked_until was reported even when it didn't decide the status, so an open-ended suspension looked as if it would end Fixed: reported only while it runs on a client stored active (ClientStatusService.lockInForce)
6 The doc and the scenario Javadoc still said an active client with a lock could only come from a direct write Fixed
7 The new stored-row check passed when the row was missing Fixed: queryForObject, which fails then

Fixes in 8d2ca29. Round 4 found no real bug in this PR's own changes once #1 is answered (#2 is pre-existing, the rest are nits), so round 5 steps down to a scoped high, the floor for security-sensitive code.

Round 5, /code-review high (scoped to 8d2ca29):

# Finding Where it went
1 The stored-row check would fail with an NPE, not an assertion, if the lock were missing Fixed: asserts the lock is present first
2 A blank status filter was ignored while other unknown values got 400 Fixed: blank is 400; empty still means no filter
3 The filter's statuses and the status update's @Pattern could drift apart Fixed: a test checks they accept the same values
4 The Javadoc and doc said a lock is reported for a client stored active, but NULL counts too Fixed
5 The doc still said a stored suspended ends with its lock Fixed

Fixes in fc8c290: nits only, touching no enforcement code, so round 6 is a scoped medium.

Round 6, /code-review medium (scoped to fc8c290):

# Finding Where it went
1 Test: the status=%20 case sent the literal text %20 (MockMvc re-encodes %), so the new blank-status check was untested Fixed: sent with param(); confirmed the cases fail with the old check
2 The statuses-vs-@Pattern test checked a fixed list, so a status added only to the pattern passed Fixed: the pattern must equal ^( + the joined STATUSES + )$
3 Two lines were wrapped far wider than the rest Rewrapped

Fixes in 0901cc5 (tests and wording only), so round 7 is a scoped medium, the floor for a test change.

Round 7, /code-review medium (scoped to 0901cc5):

# Finding Where it went
1 The tab case was a raw tab character in the string, which a formatter could turn into spaces Fixed: written as "\t"
2 The @Pattern message lists the statuses by hand and wasn't checked Fixed: the test checks it names every status in STATUSES

Fixes in 80f6217 (tests only), so round 8 is a scoped medium.

Round 8, /code-review medium (scoped to 80f6217):

# Finding Where it went
1 The message check would pass with a stale message naming a removed status Answered on the PR: the check guards against a status being added; removing one is a deliberate API change that the docs and scenarios also reflect
2 contains matches substrings, so a new status that is a prefix of an existing one would pass Answered on the PR: unlikely in a three-value set; an exact string would just copy the annotation
3 The tab case's test name shows a real tab in reports Answered on the PR: cosmetic; the source writes "\t"

No src/ change followed round 8, so the review cycle is complete.

🤖 Generated with Claude Code

… authorization or active introspection; the status update works on PostgreSQL (#345)

- ClientStatusService: active = client_status active (NULL is the default)
  and no running lock; read on every request.
- ClientStatusEnforcement: client authentication fails with invalid_client
  (token, introspection, revocation); introspection reports the client's
  tokens inactive; /oauth2/authorize answers as for an unknown client_id,
  with no redirect. /authorize/delegate and the AS's own bearer-token check
  refuse an inactive client too.
- PostgreSQL: the status update casts to client_status_type (it was 500).
- H2 V12 adds client_status, locked_until and updated_by.
- Tests on MySQL and PostgreSQL through the real status endpoint; docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ended during delegation gets no access_denied redirect (#345 review)

- ClientStatusService: a suspended client whose locked_until has passed counts as
  active, so lock_duration_minutes ends the suspension; without a lock it lasts
  until reactivation; revoked never ends on its own.
- AuthorizeContinueController: a client no longer active when the customer comes
  back from the DC gets 400 on allow and deny (no code, no access_denied redirect).
- AuthorizationServerConfig: the validator comment says Spring checks the grant
  type before the client's status.
- Docs: what lock_duration_minutes does.
- Tests: ClientStatusServiceTest rows for timed suspensions and revocations; a
  timed suspension through the status endpoint on MySQL and PostgreSQL; the
  continue controller's inactive-client paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dfcoffin

Copy link
Copy Markdown
Contributor Author

Round 1, finding 2, the consent part (Spring's consent POST could mint a code for a client suspended mid-flow): this can't happen, so no change.

Since #305, the AS keeps no customer sign-in and no stored consent. DelegatedCustomerAuthenticationFilter.shouldNotFilter skips every request that is not a GET carrying DELEGATION_PARAMETER, so the customer is signed in only on the replayed GET /oauth2/authorize. A POST to the consent endpoint therefore has no authenticated customer and never mints a code. The replayed GET that does mint one runs ClientStatusEnforcement.authorizationCodeRequest(), and since 91a65c9 /oauth2/authorize/continue checks the client's status before building the replay.

The deny part of the finding (an access_denied redirect to a client suspended mid-flow) is fixed in 91a65c9.

dfcoffin and others added 3 commits November 29, 2026 01:25
…cked_until; a timed suspension is audited; certificate validation uses the same status rule (#345 review)

- ClientStatusService.statusInForce, and the same rule as SQL (STATUS_IN_FORCE_SQL):
  a timed suspension whose lock has passed is active, an active client with a
  running lock is suspended, revoked stays revoked.
- Client details and the list report the status in force and locked_until; the
  list's status filter uses the same rule (and so works on PostgreSQL).
- The status change audit holds lock_duration_minutes and locked_until.
- lock_duration_minutes with active or revoked is 400, not dropped.
- ClientCertificateService asks ClientStatusService whether a client is active.
- ClientStatusService Javadoc and the API doc match the rule.
- Tests: the status in force in Java and SQL on H2; client details and the list
  through a timed suspension on MySQL and PostgreSQL; the audit and the 400;
  certificate validation follows ClientStatusService.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d suspension; client management uses enforcement's clock (#345 review)

- A timed suspension is stored as active with locked_until; a stored suspended
  or revoked never ends on its own, whatever writes locked_until.
- Any other stored status is revoked in Java as in the list's SQL.
- Client details read locked_until with getTimestamp, as the list does.
- The list, details and status update use ClientStatusService's clock; a lock
  is set in whole seconds, so the audit records the time stored.
- A status read failure during certificate validation is logged as a warning
  with its exception.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…til is reported only while it decides the status (#345 review)

- The list's status filter takes only active, suspended or revoked (400
  otherwise), so the result no longer depends on the database's collation.
- Client details and the list report locked_until only while it runs on a
  client stored active (ClientStatusService.lockInForce), so a suspended
  client without it is open-ended.
- The Javadoc and doc say a status change replaces the earlier state; only
  other writers of locked_until are limited to extending a lock.
- Stale descriptions of an active client with a lock corrected; the stored-row
  check fails when the row is missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dfcoffin

Copy link
Copy Markdown
Contributor Author

Round 4, finding 1 (rows stored as suspended with a lock before this change would now stay suspended for good): answered, no migration.

dfcoffin and others added 3 commits November 29, 2026 13:49
… statuses are tested against the status update's (#345 review)

- A blank status filter is 400; an empty one still means no filter.
- A test checks STATUSES accepts exactly what the status update's @pattern does.
- The timed-suspension stored-row check asserts the lock is present before
  reading it.
- The Javadoc and doc say a lock is reported on a client stored active or
  NULL, and a stored suspended lasts until the client is set active.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… filter's statuses must equal the status update's pattern (#345 review)

- The blank-status cases send " ", a tab and two spaces with param(), since
  MockMvc re-encodes a '%' in the URI; they fail with the old hasText guard.
- The test compares the @pattern with STATUSES exactly, so a status added to
  only one of them fails.
- Rewrapped the lockedUntil Javadoc and the API doc paragraph.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…age must name every status (#345 review)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dfcoffin

Copy link
Copy Markdown
Contributor Author

Round 8 (/code-review medium, scoped to 80f6217): answers to the three nits. All three are in OAuth2ClientManagementControllerTest, and the owner ruled that each one stands as written. No src/ change follows, so this round ends the review cycle.

  1. The message check passes with a stale message (a status removed from STATUSES and the regex could still be named in the message). The check exists to catch the drift round 7 raised: a status added without updating the message. Removing a status is a deliberate API change. It would also mean changing docs/OAUTH2_CLIENT_MANAGEMENT_API.md and the suspension scenarios, so review would catch it there.
  2. contains matches substrings, so a new status that is a prefix of an existing one (e.g. suspend) would pass. That needs a new status that is a prefix of an existing one in a three-value set, which is unlikely. The full fix, an exact message string, would just repeat the annotation word for word in the test.
  3. The tab case's test name shows a real tab between quotes in reports. This is cosmetic. The source now writes it as "\t", and the test sends a real tab, which is what it is meant to test.

🤖 Generated with Claude Code

@dfcoffin
dfcoffin merged commit 897e13f into main Nov 30, 2026
12 of 13 checks passed
@dfcoffin
dfcoffin deleted the fix/345-enforce-client-suspension branch November 30, 2026 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AS: suspending or revoking a client has no effect: client_status is never checked at the token, authorization or introspection endpoints

1 participant