diff --git a/ajax/ajax_asset_details.php b/ajax/ajax_asset_details.php index 3ffa50a2..ec378459 100644 --- a/ajax/ajax_asset_details.php +++ b/ajax/ajax_asset_details.php @@ -24,8 +24,8 @@ $asset_make = nullable_htmlentities($row['asset_make']); $asset_model = nullable_htmlentities($row['asset_model']); $asset_serial = nullable_htmlentities($row['asset_serial']); $asset_os = nullable_htmlentities($row['asset_os']); -$asset_uri = nullable_htmlentities($row['asset_uri']); -$asset_uri_2 = nullable_htmlentities($row['asset_uri_2']); +$asset_uri = sanitize_url($row['asset_uri']); +$asset_uri_2 = sanitize_url($row['asset_uri_2']); $asset_status = nullable_htmlentities($row['asset_status']); $asset_purchase_reference = nullable_htmlentities($row['asset_purchase_reference']); $asset_purchase_date = nullable_htmlentities($row['asset_purchase_date']); @@ -262,25 +262,25 @@ ob_start();
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -291,19 +291,19 @@ ob_start();
-
+
-
+
-
+
-
Link
+
-
Link 2
+
@@ -315,19 +315,19 @@ ob_start();
-
+
-
+
-
+
-
+
-
+
diff --git a/asset_details.php b/asset_details.php index ca4eaf2e..632c87b2 100644 --- a/asset_details.php +++ b/asset_details.php @@ -34,8 +34,8 @@ if (isset($_GET['asset_id'])) { $asset_model = nullable_htmlentities($row['asset_model']); $asset_serial = nullable_htmlentities($row['asset_serial']); $asset_os = nullable_htmlentities($row['asset_os']); - $asset_uri = nullable_htmlentities($row['asset_uri']); - $asset_uri_2 = nullable_htmlentities($row['asset_uri_2']); + $asset_uri = sanitize_url($row['asset_uri']); + $asset_uri_2 = sanitize_url($row['asset_uri_2']); $asset_status = nullable_htmlentities($row['asset_status']); $asset_purchase_reference = nullable_htmlentities($row['asset_purchase_reference']); $asset_purchase_date = nullable_htmlentities($row['asset_purchase_date']); @@ -283,19 +283,19 @@ if (isset($_GET['asset_id'])) {
-
+
-
+
-
+
-
Link
+
-
Link 2
+
@@ -307,19 +307,19 @@ if (isset($_GET['asset_id'])) {
-
+
-
+
-
+
-
+
-
+
diff --git a/assets.php b/assets.php index bdbb6112..a74df2b8 100644 --- a/assets.php +++ b/assets.php @@ -486,8 +486,8 @@ if (mysqli_num_rows($os_sql) > 0) { $asset_ipv6 = nullable_htmlentities($row['interface_ipv6']); $asset_nat_ip = nullable_htmlentities($row['interface_nat_ip']); $asset_mac = nullable_htmlentities($row['interface_mac']); - $asset_uri = nullable_htmlentities($row['asset_uri']); - $asset_uri_2 = nullable_htmlentities($row['asset_uri_2']); + $asset_uri = sanitize_url($row['asset_uri']); + $asset_uri_2 = sanitize_url($row['asset_uri_2']); $asset_status = nullable_htmlentities($row['asset_status']); $asset_purchase_reference = nullable_htmlentities($row['asset_purchase_reference']); $asset_purchase_date = nullable_htmlentities($row['asset_purchase_date']); diff --git a/functions.php b/functions.php index 1c1e9b6f..b440ef9e 100644 --- a/functions.php +++ b/functions.php @@ -1652,3 +1652,22 @@ function display_folder_options($parent_folder_id, $client_id, $folder_location display_folder_options($folder_id, $client_id, $folder_location, $indent + 1); } } + +function sanitize_url($url) { + $allowed = ['http', 'https', 'file', 'ftp', 'ftps', 'sftp', 'dav', 'webdav', 'caldav', 'carddav', 'ssh', 'telnet', 'smb', 'rdp', 'vnc', 'rustdesk', 'anydesk', 'connectwise', 'splashtop', 'sip', 'sips', 'ldap', 'ldaps']; + $parts = parse_url($url); + if (isset($parts['scheme']) && !in_array(strtolower($parts['scheme']), $allowed)) { + // Remove the scheme and colon + $pos = strpos($url, ':'); + $without_scheme = $url; + if ($pos !== false) { + $without_scheme = substr($url, $pos + 1); // This keeps slashes (e.g. //pizza.com) + } + // Prepend 'unsupported://' (strip any leading slashes from $without_scheme to avoid triple slashes) + $unsupported = 'unsupported://' . ltrim($without_scheme, '/'); + return htmlspecialchars($unsupported, ENT_QUOTES, 'UTF-8'); + } + + // Safe schemes: return escaped original URL + return htmlspecialchars($url, ENT_QUOTES, 'UTF-8'); +} \ No newline at end of file diff --git a/includes/side_nav.php b/includes/side_nav.php index 7d30cc8a..24c1f288 100644 --- a/includes/side_nav.php +++ b/includes/side_nav.php @@ -211,7 +211,7 @@ while ($row = mysqli_fetch_array($sql_custom_links)) { $custom_link_name = nullable_htmlentities($row['custom_link_name']); - $custom_link_uri = nullable_htmlentities($row['custom_link_uri']); + $custom_link_uri = sanitize_url($row['custom_link_uri']); $custom_link_icon = nullable_htmlentities($row['custom_link_icon']); $custom_link_new_tab = intval($row['custom_link_new_tab']); if ($custom_link_new_tab == 1) { diff --git a/includes/top_nav.php b/includes/top_nav.php index 45aeaa88..944cd3c2 100644 --- a/includes/top_nav.php +++ b/includes/top_nav.php @@ -36,7 +36,7 @@ while ($row = mysqli_fetch_array($sql_custom_links)) { $custom_link_name = nullable_htmlentities($row['custom_link_name']); - $custom_link_uri = nullable_htmlentities($row['custom_link_uri']); + $custom_link_uri = sanitize_url($row['custom_link_uri']); $custom_link_icon = nullable_htmlentities($row['custom_link_icon']); $custom_link_new_tab = intval($row['custom_link_new_tab']); if ($custom_link_new_tab == 1) {