$filepath = MINIFY_BASE_DIR . '/' . $file; } // Ensure that the file exists, that the path is under the base directory, // that the file's extension is either '.css' or '.js', and that the file is // actually readable. if (!$filepath || !is_file($filepath) || !is_readable($filepath) || !preg_match('/^' . preg_quote(MINIFY_BASE_DIR, '/') . '/', $filepath) || !preg_match('/\\.(?:css|js)$/iD', $filepath)) { // Even when the file exists, we still throw a // MinifyFileNotFoundException in order to try to prevent an information // disclosure vulnerability. throw new MinifyFileNotFoundException("File not found: {$filepath} " . $file); } return $filepath; } } // -- Exception Classes -------------------------------------------------------- class MinifyException extends Exception { } class MinifyFileNotFoundException extends MinifyException { } class MinifyInvalidArgumentException extends MinifyException { } class MinifyInvalidUrlException extends MinifyException { } // -- Global Scope ------------------------------------------------------------- if (realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME'])) { Minify::handleRequest(); }