Changeset 3412265
- Timestamp:
- 12/05/2025 02:23:08 PM (4 months ago)
- Location:
- anac-xml-viewer
- Files:
-
- 4 edited
- 1 copied
-
tags/1.8.2 (copied) (copied from anac-xml-viewer/trunk)
-
tags/1.8.2/anac-xml-viewer.php (modified) (3 diffs)
-
tags/1.8.2/readme.txt (modified) (2 diffs)
-
trunk/anac-xml-viewer.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
anac-xml-viewer/tags/1.8.2/anac-xml-viewer.php
r3301629 r3412265 5 5 Description: Visualizzatore XML per file generati da applicativi esterni 6 6 Author: Marco Milesi 7 Version: 1.8. 17 Version: 1.8.2 8 8 Author URI: https://marcomilesi.com 9 9 */ … … 140 140 141 141 if ( substr( $content, 0, 4 ) === "http" ) { 142 $gare_xml = new SimpleXMLElement( $content, LIBXML_NOCDATA, true ); 142 $gare_xml = $this->fetch_and_load_xml( $content ); 143 if ( $gare_xml === null ) { 144 echo '<div class="notice notice-error"><p>Impossibile caricare XML. Assicurarsi che l\'URL esista e che il contenuto sia XML valido.</p></div>'; 145 return; 146 } 143 147 } else { 144 $gare_xml = new SimpleXMLElement( stripslashes($content) ); 148 try { 149 $gare_xml = new SimpleXMLElement( stripslashes($content) ); 150 } catch ( Exception $e ) { 151 echo '<div class="notice notice-error"><p>Il contenuto inserito non è XML valido.</p></div>'; 152 return; 153 } 145 154 } 146 155 … … 262 271 } 263 272 273 private function is_private_ip( $ip ) { 274 if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) ) { 275 $long = ip2long($ip); 276 $ranges = [ 277 ['0.0.0.0', '0.255.255.255'], 278 ['10.0.0.0', '10.255.255.255'], 279 ['127.0.0.0', '127.255.255.255'], 280 ['169.254.0.0', '169.254.255.255'], 281 ['172.16.0.0', '172.31.255.255'], 282 ['192.168.0.0', '192.168.255.255'] 283 ]; 284 foreach ( $ranges as $r ) { 285 if ( $long >= ip2long($r[0]) && $long <= ip2long($r[1]) ) return true; 286 } 287 return false; 288 } 289 if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 ) ) { 290 if ( strpos($ip, '::1') === 0 ) return true; // localhost 291 // fc00::/7 unique local, fe80::/10 link-local 292 if ( strpos($ip, 'fc') === 0 || strpos($ip, 'fd') === 0 ) return true; 293 if ( strpos($ip, 'fe80') === 0 ) return true; 294 return false; 295 } 296 return true; 297 } 298 299 private function fetch_and_load_xml( $url ) { 300 if ( ! function_exists('wp_http_validate_url') || ! wp_http_validate_url( $url ) ) return null; 301 $parts = wp_parse_url( $url ); 302 if ( ! $parts || ! isset($parts['scheme']) || ! in_array( strtolower($parts['scheme']), ['http','https'], true ) ) return null; 303 if ( empty($parts['host']) ) return null; 304 305 $host = $parts['host']; 306 $blocked_hosts = [ 307 '169.254.169.254', 308 'metadata.google.internal' 309 ]; 310 if ( in_array( strtolower($host), $blocked_hosts, true ) ) return null; 311 312 $resolved = gethostbynamel( $host ); 313 if ( $resolved ) { 314 foreach ( $resolved as $ip ) { 315 if ( $this->is_private_ip( $ip ) ) return null; 316 } 317 } 318 319 $args = [ 320 'timeout' => 5, 321 'redirection' => 2, 322 'headers' => [ 'Accept' => 'application/xml, text/xml; q=0.9, */*; q=0.1' ], 323 ]; 324 $response = wp_remote_get( $url, $args ); 325 if ( is_wp_error( $response ) ) return null; 326 327 $code = wp_remote_retrieve_response_code( $response ); 328 if ( $code < 200 || $code >= 300 ) return null; 329 330 $body = wp_remote_retrieve_body( $response ); 331 if ( ! $body ) return null; 332 333 $ctype = wp_remote_retrieve_header( $response, 'content-type' ); 334 if ( $ctype && strpos( strtolower($ctype), 'xml' ) === false ) { 335 // Allow if body looks like XML even when header is wrong 336 if ( strpos( ltrim($body), '<') !== 0 ) return null; 337 } 338 339 libxml_use_internal_errors(true); 340 try { 341 $xml = new SimpleXMLElement( $body ); 342 return $xml; 343 } catch ( Exception $e ) { 344 return null; 345 } 346 } 347 264 348 public function template_redirect() { 265 349 global $wp, $wp_query; -
anac-xml-viewer/tags/1.8.2/readme.txt
r3301629 r3412265 5 5 Requires at least: 4.3 6 6 Tested up to: 6.9 7 Version: 1.8. 18 Stable tag: 1.8. 17 Version: 1.8.2 8 Stable tag: 1.8.2 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 40 40 41 41 > Questa è la lista completa di tutti gli aggiornamenti, test e correzioni. Ogni volta che una nuova versione viene rilasciata assicuratevi di aggiornare il prima possibile per usufruire delle ultime migliorie! 42 43 = 1.8.2 2025-12-05 = 44 * Bugfix minori e sicurezza 42 45 43 46 = 1.8.1 2025-05-27 = -
anac-xml-viewer/trunk/anac-xml-viewer.php
r3301629 r3412265 5 5 Description: Visualizzatore XML per file generati da applicativi esterni 6 6 Author: Marco Milesi 7 Version: 1.8. 17 Version: 1.8.2 8 8 Author URI: https://marcomilesi.com 9 9 */ … … 140 140 141 141 if ( substr( $content, 0, 4 ) === "http" ) { 142 $gare_xml = new SimpleXMLElement( $content, LIBXML_NOCDATA, true ); 142 $gare_xml = $this->fetch_and_load_xml( $content ); 143 if ( $gare_xml === null ) { 144 echo '<div class="notice notice-error"><p>Impossibile caricare XML. Assicurarsi che l\'URL esista e che il contenuto sia XML valido.</p></div>'; 145 return; 146 } 143 147 } else { 144 $gare_xml = new SimpleXMLElement( stripslashes($content) ); 148 try { 149 $gare_xml = new SimpleXMLElement( stripslashes($content) ); 150 } catch ( Exception $e ) { 151 echo '<div class="notice notice-error"><p>Il contenuto inserito non è XML valido.</p></div>'; 152 return; 153 } 145 154 } 146 155 … … 262 271 } 263 272 273 private function is_private_ip( $ip ) { 274 if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) ) { 275 $long = ip2long($ip); 276 $ranges = [ 277 ['0.0.0.0', '0.255.255.255'], 278 ['10.0.0.0', '10.255.255.255'], 279 ['127.0.0.0', '127.255.255.255'], 280 ['169.254.0.0', '169.254.255.255'], 281 ['172.16.0.0', '172.31.255.255'], 282 ['192.168.0.0', '192.168.255.255'] 283 ]; 284 foreach ( $ranges as $r ) { 285 if ( $long >= ip2long($r[0]) && $long <= ip2long($r[1]) ) return true; 286 } 287 return false; 288 } 289 if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 ) ) { 290 if ( strpos($ip, '::1') === 0 ) return true; // localhost 291 // fc00::/7 unique local, fe80::/10 link-local 292 if ( strpos($ip, 'fc') === 0 || strpos($ip, 'fd') === 0 ) return true; 293 if ( strpos($ip, 'fe80') === 0 ) return true; 294 return false; 295 } 296 return true; 297 } 298 299 private function fetch_and_load_xml( $url ) { 300 if ( ! function_exists('wp_http_validate_url') || ! wp_http_validate_url( $url ) ) return null; 301 $parts = wp_parse_url( $url ); 302 if ( ! $parts || ! isset($parts['scheme']) || ! in_array( strtolower($parts['scheme']), ['http','https'], true ) ) return null; 303 if ( empty($parts['host']) ) return null; 304 305 $host = $parts['host']; 306 $blocked_hosts = [ 307 '169.254.169.254', 308 'metadata.google.internal' 309 ]; 310 if ( in_array( strtolower($host), $blocked_hosts, true ) ) return null; 311 312 $resolved = gethostbynamel( $host ); 313 if ( $resolved ) { 314 foreach ( $resolved as $ip ) { 315 if ( $this->is_private_ip( $ip ) ) return null; 316 } 317 } 318 319 $args = [ 320 'timeout' => 5, 321 'redirection' => 2, 322 'headers' => [ 'Accept' => 'application/xml, text/xml; q=0.9, */*; q=0.1' ], 323 ]; 324 $response = wp_remote_get( $url, $args ); 325 if ( is_wp_error( $response ) ) return null; 326 327 $code = wp_remote_retrieve_response_code( $response ); 328 if ( $code < 200 || $code >= 300 ) return null; 329 330 $body = wp_remote_retrieve_body( $response ); 331 if ( ! $body ) return null; 332 333 $ctype = wp_remote_retrieve_header( $response, 'content-type' ); 334 if ( $ctype && strpos( strtolower($ctype), 'xml' ) === false ) { 335 // Allow if body looks like XML even when header is wrong 336 if ( strpos( ltrim($body), '<') !== 0 ) return null; 337 } 338 339 libxml_use_internal_errors(true); 340 try { 341 $xml = new SimpleXMLElement( $body ); 342 return $xml; 343 } catch ( Exception $e ) { 344 return null; 345 } 346 } 347 264 348 public function template_redirect() { 265 349 global $wp, $wp_query; -
anac-xml-viewer/trunk/readme.txt
r3301629 r3412265 5 5 Requires at least: 4.3 6 6 Tested up to: 6.9 7 Version: 1.8. 18 Stable tag: 1.8. 17 Version: 1.8.2 8 Stable tag: 1.8.2 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 40 40 41 41 > Questa è la lista completa di tutti gli aggiornamenti, test e correzioni. Ogni volta che una nuova versione viene rilasciata assicuratevi di aggiornare il prima possibile per usufruire delle ultime migliorie! 42 43 = 1.8.2 2025-12-05 = 44 * Bugfix minori e sicurezza 42 45 43 46 = 1.8.1 2025-05-27 =
Note: See TracChangeset
for help on using the changeset viewer.