Change API keys from string to hashed password

Created on 25 September 2023, 9 months ago
Updated 12 December 2023, 7 months ago

Problem/Motivation

This is a public follow up on a previous security report (179490).

The API key in a password in this context and therefore it must not be stored in plain text rather encrypted or hashed and only displayed once to a user.

https://owasp.org/www-community/vulnerabilities/Password_Plaintext_Storage
https://blog.mergify.com/api-keys-best-practice#encryption-vs-hashing

Steps to reproduce

Create a key auth as user 1 or any other user and check the content of users_field_data.api_key in the database for the given user.

Proposed resolution

Suggested fix for fixing this with hashing is changing the type of the api_key field on user from string to password. Basically this is how Simple OAuth stores consumer secrets as well, see simple_oauth_entity_base_field_info(). After that, when authentication happens the incoming value has to be compared with the saved value using the password checker service. See: \Drupal\simple_oauth\Repositories\ClientRepository::validateClient()

  1. Change the field to password and use $this->passwordChecker->check() to validate
  2. Create an update hook to update the field for existing sites
  3. Create an update hook to hash/update existing API keys

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.1

Component

Code

Created by

🇭🇺Hungary mxr576 Hungary

Live updates comments and jobs are added and updated live.
  • Security

    It is used for security vulnerabilities which do not need a security advisory. For example, security issues in projects which do not have security advisory coverage, or forward-porting a change already disclosed in a security advisory. See Drupal’s security advisory policy for details. Be careful publicly disclosing security vulnerabilities! Use the “Report a security vulnerability” link in the project page’s sidebar. See how to report a security issue for details.

Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024