mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 02:14:13 +00:00
Adding support for optional cat_url argument in api/radio endpoint
This commit is contained in:
@@ -653,6 +653,13 @@ class API extends CI_Controller {
|
||||
break;
|
||||
}
|
||||
|
||||
// Handle optional cat_url
|
||||
if (isset($obj['cat_url']) && !empty($obj['cat_url'])) {
|
||||
$cat_url = $this->sanitize_callback_url($obj['cat_url']);
|
||||
if ($cat_url !== false) {
|
||||
$obj['cat_url'] = $cat_url;
|
||||
}
|
||||
}
|
||||
|
||||
// Store Result to Database
|
||||
$this->cat->update($obj, $user_id, $operator);
|
||||
@@ -1126,4 +1133,28 @@ class API extends CI_Controller {
|
||||
echo json_encode(['status' => 'successful', 'message' => 'Export successful', 'statistics' => $data]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize and validate callback URL
|
||||
* @param string $url The URL to sanitize
|
||||
* @return string|false Returns sanitized URL or false if invalid
|
||||
*/
|
||||
private function sanitize_callback_url($url) {
|
||||
// Basic sanitization
|
||||
$url = trim($url);
|
||||
|
||||
// Check if URL is valid and uses http or https
|
||||
if (!filter_var($url, FILTER_VALIDATE_URL) ||
|
||||
(!preg_match('/^https?:\/\//', $url))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove trailing slashes
|
||||
$url = rtrim($url, '/');
|
||||
|
||||
// Additional XSS cleaning
|
||||
$url = $this->security->xss_clean($url);
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,11 @@
|
||||
'timestamp' => $timestamp,
|
||||
);
|
||||
|
||||
// Handle callback URL if provided
|
||||
if (isset($result['cat_url']) && !empty($result['cat_url'])) {
|
||||
$data['cat_url'] = $result['cat_url'];
|
||||
}
|
||||
|
||||
if ( (isset($result['power'])) && ($result['power'] != "NULL") && ($result['power'] != '') && (is_numeric($result['power']))) {
|
||||
$data['power'] = $result['power'];
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user