Plugin Directory


Ignore:
Timestamp:
10/15/2026 11:24:25 AM (11 days ago)
Author:
shiponkarmakar
Message:

Release v1.1.1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • optimazz/trunk/includes/Modules/Cache/engine.php

    r3743505 r3748279  
    616616                $query = isset( $parts[1] ) ? $parts[1] : '';
    617617
    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 );
    621619                $dir  = self::cache_root() . self::sanitize_segment( $host ) . rtrim( $path, '/' ) . '/';
    622620
    … …  
    708706                $host     = self::url_host( $parts );
    709707                $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 );
    712709                $host_dir = self::cache_root() . self::sanitize_segment( $host ) . '/';
    713710                $dir      = self::cache_root() . self::sanitize_segment( $host ) . rtrim( $path, '/' ) . '/';
    … …  
    803800         */
    804801        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 ), '/' );
    807803                return self::cache_root() . self::sanitize_segment( strtolower( (string) $host ) ) . ( '' !== $path ? '/' . $path : '' ) . '/';
    808804        }
    … …  
    874870         */
    875871        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, '/' );
    877886        }
    878887
Note: See TracChangeset for help on using the changeset viewer.