v1.2.1 - Handle NDKs pings of kind 99999

This commit is contained in:
Your Name
2026-02-03 13:19:33 -04:00
parent 18a7deec54
commit 086d2af56c
3 changed files with 66 additions and 10 deletions

View File

@@ -1456,6 +1456,10 @@ int validate_search_term(const char* search_term, char* error_message, size_t er
/**
* Validate all filter values in a filter object
* Returns:
* 1 = valid
* 0 = invalid (malformed, should count toward rate limit)
* -1 = invalid but benign (e.g., kind 99999 from NDK ping, should not count toward rate limit)
*/
int validate_filter_values(cJSON* filter_json, char* error_message, size_t error_size) {
if (!filter_json || !cJSON_IsObject(filter_json)) {
@@ -1463,6 +1467,8 @@ int validate_filter_values(cJSON* filter_json, char* error_message, size_t error
return 0;
}
int has_kind_99999 = 0; // Track if we encounter kind 99999 (NDK ping)
// Validate kinds array
cJSON* kinds = cJSON_GetObjectItem(filter_json, "kinds");
if (kinds) {
@@ -1485,11 +1491,25 @@ int validate_filter_values(cJSON* filter_json, char* error_message, size_t error
}
int kind_val = (int)cJSON_GetNumberValue(kind_item);
// Special case: kind 99999 is used by NDK for ping/connectivity checks
// We reject it but don't count it as a malformed request
if (kind_val == 99999) {
has_kind_99999 = 1;
snprintf(error_message, error_size, "kinds[%d]: invalid event kind %d (used by NDK for ping)", i, kind_val);
continue; // Continue checking other kinds
}
if (kind_val < 0 || kind_val > 65535) { // Reasonable range for event kinds
snprintf(error_message, error_size, "kinds[%d]: invalid event kind %d", i, kind_val);
return 0;
}
}
// If we only found kind 99999 and no other validation errors, return -1 (benign error)
if (has_kind_99999) {
return -1;
}
}
// Validate authors array