mirror of
https://github.com/itflow-org/itflow
synced 2026-11-22 04:17:24 +00:00
API keys in the address: Admin API Keys flags each key sent in a call's address in the last 30 days with a note counting them, and Admin Settings Security gains Take API keys in the address - off, a key in the address is turned away with a 401 telling the caller to use the X-API-Key header and logged against the key; database 3.7.0 adds api_keys.api_key_address_at and settings.config_api_key_in_address, on where a key still in date was there at the update and off otherwise and on new installs; 26.11.9 changelog entries
This commit is contained in:
@@ -105,6 +105,26 @@ if (isset($api_key)) {
|
||||
$api_key_decrypt_hash = $row['api_key_decrypt_hash']; // No sanitization
|
||||
$api_key_user_id = intval($row['api_key_user_id']);
|
||||
|
||||
// A key in the address is in the web server's access log: Admin > API Keys flags it, and
|
||||
// once Admin > Settings > Security stops taking keys there, the call is turned away
|
||||
if (apiKeyInAddress()) {
|
||||
apiKeyNoteAddress($row['api_key_id']);
|
||||
if (!apiKeyInAddressAccepted()) {
|
||||
$url_path = escapeSql(parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH));
|
||||
$refused_description = escapeSql("API key " . $row['api_key_name'] . " sent in the address, which ITFlow doesn't take") . " (endpoint: $url_path)";
|
||||
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'API', log_action = 'Failed', log_description = '$refused_description', log_ip = '$ip', log_user_agent = '$user_agent',
|
||||
log_entity_id = " . intval($row['api_key_id']));
|
||||
logForwardQueue('audit', mysqli_insert_id($mysqli));
|
||||
|
||||
$return_arr['success'] = "False";
|
||||
$return_arr['message'] = "This ITFlow doesn't take API keys in the address, where web server logs keep them - send the key in the X-API-Key header.";
|
||||
|
||||
header(WORDING_UNAUTHORIZED);
|
||||
echo json_encode($return_arr);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// When it was last used, for Admin > API Keys - at most once a minute, not every call
|
||||
mysqli_query($mysqli, "UPDATE api_keys SET api_key_last_used_at = NOW() WHERE api_key_id = " . intval($row['api_key_id']) . "
|
||||
AND (api_key_last_used_at IS NULL OR api_key_last_used_at < NOW() - INTERVAL 1 MINUTE)");
|
||||
|
||||
Reference in New Issue
Block a user