Changeset 3748279 for optimazz/trunk/includes/Modules/Cache/engine.php
- Timestamp:
- 10/15/2026 11:24:25 AM (11 days ago)
- File:
-
- 1 edited
-
optimazz/trunk/includes/Modules/Cache/engine.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
optimazz/trunk/includes/Modules/Cache/engine.php
r3743505 r3748279 616 616 $query = isset( $parts[1] ) ? $parts[1] : ''; 617 617 618 // Sanitize path — never allow traversal. 619 $path = str_replace( array( '..', "\0" ), '', $path ); 620 $path = '/' . trim( preg_replace( '#[^a-zA-Z0-9/_\-.]#', '-', $path ), '/' ); 618 $path = self::sanitize_path( $path ); 621 619 $dir = self::cache_root() . self::sanitize_segment( $host ) . rtrim( $path, '/' ) . '/'; 622 620 … … 708 706 $host = self::url_host( $parts ); 709 707 $path = isset( $parts['path'] ) ? $parts['path'] : '/'; 710 $path = str_replace( array( '..', "\0" ), '', $path ); 711 $path = '/' . trim( preg_replace( '#[^a-zA-Z0-9/_\-.]#', '-', $path ), '/' ); 708 $path = self::sanitize_path( $path ); 712 709 $host_dir = self::cache_root() . self::sanitize_segment( $host ) . '/'; 713 710 $dir = self::cache_root() . self::sanitize_segment( $host ) . rtrim( $path, '/' ) . '/'; … … 803 800 */ 804 801 public static function site_dir( $host, $path ) { 805 $path = trim( str_replace( array( '..', "\0" ), '', (string) $path ), '/' ); 806 $path = preg_replace( '#[^a-zA-Z0-9/_\-.]#', '-', $path ); 802 $path = trim( self::sanitize_path( $path ), '/' ); 807 803 return self::cache_root() . self::sanitize_segment( strtolower( (string) $host ) ) . ( '' !== $path ? '/' . $path : '' ) . '/'; 808 804 } … … 874 870 */ 875 871 private static function sanitize_segment( $segment ) { 876 return preg_replace( '#[^a-zA-Z0-9_\-.]#', '-', (string) $segment ); 872 return preg_replace( '#\.{2,}#', '.', preg_replace( '#[^a-zA-Z0-9_\-.]#', '-', (string) $segment ) ); 873 } 874 875 /** 876 * Sanitize a URL path for use as cache folders: unsafe characters (NUL 877 * included) become "-", then any run of dots becomes one, so nothing can 878 * rebuild "..". 879 * 880 * @param string $path URL path. 881 * @return string Path with one leading slash and no trailing slash. 882 */ 883 private static function sanitize_path( $path ) { 884 $path = preg_replace( '#\.{2,}#', '.', preg_replace( '#[^a-zA-Z0-9/_\-.]#', '-', (string) $path ) ); 885 return '/' . trim( $path, '/' ); 877 886 } 878 887
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)