| @@ -204,9 +204,9 @@ | ||
| 204 | 204 | * |
| 205 | 205 | * @return void |
| 206 | 206 | */ |
| 207 | 207 | function wplng_clear_translations_cache() { |
| 208 | - delete_transient( 'wplng_cached_translations' ); | |
| 208 | + delete_option( 'wplng_cached_translations' ); | |
| 209 | 209 | wplng_clear_website_cache(); |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | |
| @@ -232,14 +232,14 @@ | ||
| 232 | 232 | |
| 233 | 233 | /** |
| 234 | 234 | * Clear cached slugs |
| 235 | 235 | * |
| 236 | - * Deletes the slugs transient and clears the website cache. | |
| 236 | + * Deletes the slugs option and clears the website cache. | |
| 237 | 237 | * |
| 238 | 238 | * @return void |
| 239 | 239 | */ |
| 240 | 240 | function wplng_clear_slugs_cache() { |
| 241 | - delete_transient( 'wplng_cached_slugs' ); | |
| 241 | + delete_option( 'wplng_cached_slugs' ); | |
| 242 | 242 | wplng_clear_website_cache(); |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | |
| @@ -273,8 +273,13 @@ | ||
| 273 | 273 | * @return int|false Number of bytes written, or false on failure. |
| 274 | 274 | */ |
| 275 | 275 | function wplng_put_cache_file( $file_name, $data ) { |
| 276 | 276 | |
| 277 | + // Security: prevent path traversal | |
| 278 | + if ( wplng_str_contains( $file_name, '..' ) ) { | |
| 279 | + return false; | |
| 280 | + } | |
| 281 | + | |
| 277 | 282 | // Create main wpLingua cache folder if not exist |
| 278 | 283 | if ( ! is_dir( WPLNG_CACHE_DIR ) ) { |
| 279 | 284 | if ( ! wp_mkdir_p( WPLNG_CACHE_DIR ) ) { |
| 280 | 285 | return false; |
| @@ -392,8 +397,13 @@ | ||
| 392 | 397 | * @return string|false File contents, or false if file doesn't exist or isn't readable. |
| 393 | 398 | */ |
| 394 | 399 | function wplng_get_cache_file( $file_name ) { |
| 395 | 400 | |
| 401 | + // Security: prevent path traversal | |
| 402 | + if ( wplng_str_contains( $file_name, '..' ) ) { | |
| 403 | + return false; | |
| 404 | + } | |
| 405 | + | |
| 396 | 406 | $file_path = WPLNG_CACHE_DIR . $file_name; |
| 397 | 407 | |
| 398 | 408 | if ( ! is_readable( $file_path ) ) { |
| 399 | 409 | return false; |
| @@ -416,9 +426,11 @@ | ||
| 416 | 426 | } else { |
| 417 | 427 | $path = wp_normalize_path( WPLNG_CACHE_DIR . $file ); |
| 418 | 428 | |
| 419 | 429 | // Security: ensure path is within cache directory |
| 420 | - if ( strpos( $path, wp_normalize_path( WPLNG_CACHE_DIR ) ) !== 0 ) { | |
| 430 | + if ( wplng_str_contains( $file, '..' ) | |
| 431 | + || ! wplng_str_starts_with( $path, wp_normalize_path( WPLNG_CACHE_DIR ) ) | |
| 432 | + ) { | |
| 421 | 433 | return false; |
| 422 | 434 | } |
| 423 | 435 | } |
| 424 | 436 | |