Revocation rejects confidential clients that have no saved consumer secret

Open Beginner friendly
#63 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
62/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php

Research direction

The check to remove is in ClientAuthenticationService::validateClientCredentials(), where the secret_field isEmpty() early return sits before the call to ClientRepository::validateClient(). Read that method first, then delete the isEmpty() check and the $secret_field variable so the client repository decides. Done when a confidential consumer-plugin client with the right secret authenticates while a wrong secret is still rejected, and the existing tests for saved consumers still pass.

Written by the indexing model from the issue text.

Description

Problem

ClientAuthenticationService::validateClientCredentials() returns FALSE when the consumer's secret field is empty, before it calls ClientRepository::validateClient():

if (!empty($provided_secret)) {
  // Get the stored secret hash.
  if ($secret_field->isEmpty()) {
    return FALSE;
  }

  return $this->clientRepository->validateClient(
    $consumer->getClientId(),
    $provided_secret,
    NULL
  );
}

That rejects confidential clients that a decorator of simple_oauth.repositories.client serves without a saved consumer. Simple OAuth Consumer Plugin defines consumers in code: its repository decorator returns an unsaved Consumer, and its validateClient() checks the secret from an environment variable, a setting, or a Key entity. The unsaved consumer's secret field is always empty, so the token revocation endpoint rejects those clients even with the right secret.

The check isn't needed. Simple OAuth's ClientRepository::validateClient() already returns FALSE for a consumer without a stored secret.

Proposed resolution

Remove the isEmpty() check and the $secret_field variable, and let the client repository decide:

     $is_confidential = $client_entity->isConfidential();
-    $secret_field = $consumer->get('secret');
 
     // Public clients (not confidential) can authenticate with just client_id.
     if (!$is_confidential && empty($provided_secret)) {
       return TRUE;
     }
 
     // If a secret is provided, it must be validated regardless of client type.
     if (!empty($provided_secret)) {
-      // Get the stored secret hash.
-      if ($secret_field->isEmpty()) {
-        return FALSE;
-      }
-
       // Use the client repository's validateClient method which properly

I ran authenticateClient() with this change on 1.13.11, with Simple OAuth 6.1.5:

Client Secret Result
Consumer plugin, confidential Right Authenticated
Consumer plugin, confidential Wrong Rejected
Saved confidential consumer with no stored secret Any Rejected
Saved confidential consumer Right Authenticated
Saved confidential consumer Wrong Rejected

Without the change, the first row is rejected.

Dominant language
JavaScript
Stars
6
Forks
9
Avg merge
9h 41m
Merged PRs (30d)
15

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from e0ipso/simple_oauth_21

All issues in e0ipso/simple_oauth_21

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.