Skip to content

Commit c08705d

Browse files
committed
Self service: fix timing attack
Compare icinga_host.api_key ("known_string") via hash_equals().
1 parent 9d2251f commit c08705d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

library/Director/Objects/IcingaHost.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,13 +585,15 @@ public static function loadWithApiKey($key, Db $db)
585585
$query = $db->getDbAdapter()
586586
->select()
587587
->from('icinga_host')
588-
->where('api_key = ?', $key);
588+
->where('api_key IS NOT NULL')
589+
->query();
589590

590-
$result = self::loadAll($db, $query);
591-
if (count($result) !== 1) {
592-
throw new NotFoundError('Got invalid API key "%s"', $key);
591+
foreach ($query as $row) {
592+
if (hash_equals($row->api_key, $key)) {
593+
return (new static())->setConnection($db)->setDbProperties($row);
594+
}
593595
}
594596

595-
return current($result);
597+
throw new NotFoundError('Got invalid API key "%s"', $key);
596598
}
597599
}

0 commit comments

Comments
 (0)