Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion inc/class-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,21 @@ public function get_auth() {
*/
public function validate_credentials($api_key, $api_secret) {
$auth = $this->get_auth();
return $api_key === $auth['api_key'] && $api_secret === $auth['api_secret'] && 'prevent' !== $api_key && 'prevent' !== $api_secret;

/*
* 'prevent' is the sentinel stored when API credentials have not been
* generated yet. Reject it explicitly so a request that supplies
* 'prevent' (or empty/unset credentials) can never authenticate.
*/
if ('prevent' === $auth['api_key'] || 'prevent' === $auth['api_secret'] || '' === (string) $api_key || '' === (string) $api_secret) {
return false;
}

/*
* Compare with hash_equals() so the check runs in constant time and does
* not leak the stored key/secret through response-timing differences.
*/
return hash_equals((string) $auth['api_key'], (string) $api_key) && hash_equals((string) $auth['api_secret'], (string) $api_secret);
}

/**
Expand Down
Loading