Add input validation for recent_qsos limit parameter

The recent_qsos API endpoint now validates and sanitizes the $limit parameter, enforcing a default of 10, a minimum of 1, and a maximum of 50. Additionally, get_last_qsos in Logbook_model ensures $num is always an integer to prevent SQL injection.
pull/3339/head
Peter Goodhall 2025-09-09 14:25:40 +01:00
rodzic 11c83f5908
commit b7c065dbdd
2 zmienionych plików z 16 dodań i 1 usunięć

Wyświetl plik

@ -848,9 +848,21 @@ class API extends CI_Controller {
* "logbook_slug": "my-public-logbook"
* }
*/
function recent_qsos($public_slug = null, $limit) {
function recent_qsos($public_slug = null, $limit = 10) {
header('Content-type: application/json');
// Validate and sanitize $limit
if (!is_numeric($limit)) {
$limit = 10; // Default to 10 if not numeric
} else {
$limit = intval($limit);
if ($limit < 1) {
$limit = 1; // Minimum limit of 1
} elseif ($limit > 50) {
$limit = 50; // Maximum limit of 50
}
}
if($public_slug == null) {
http_response_code(400);
echo json_encode(['status' => 'failed', 'reason' => 'missing public_slug parameter']);

Wyświetl plik

@ -1932,6 +1932,9 @@ class Logbook_model extends CI_Model
function get_last_qsos($num, $StationLocationsArray = null)
{
// Ensure $num is always an integer to prevent SQL injection
$num = intval($num);
if ($StationLocationsArray == null) {
$CI = &get_instance();
$CI->load->model('logbooks_model');