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.
这个提交包含在:
Peter Goodhall 2025-09-09 14:25:40 +01:00
父节点 11c83f5908
当前提交 b7c065dbdd
共有 2 个文件被更改,包括 16 次插入1 次删除

查看文件

@ -848,9 +848,21 @@ class API extends CI_Controller {
* "logbook_slug": "my-public-logbook" * "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'); 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) { if($public_slug == null) {
http_response_code(400); http_response_code(400);
echo json_encode(['status' => 'failed', 'reason' => 'missing public_slug parameter']); echo json_encode(['status' => 'failed', 'reason' => 'missing public_slug parameter']);

查看文件

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