PluginProbe
Search Atlas SEO – OTTO AI SEO Automation for WordPress / 2.6.13
Search Atlas SEO – OTTO AI SEO Automation for WordPress v2.6.13
2.6.26 2.6.25 2.6.24 2.6.23 2.6.22 2.6.21 2.6.20 2.6.19 2.6.18 2.6.17 2.6.16 2.6.15 2.6.14 2.6.13 2.6.12 2.6.11 2.6.10 2.6.9 2.6.8 2.6.7 2.6.6 2.6.5 2.6.4 2.6.3 2.5.23 All 138 releases
metasync / includes / class-metasync-regex-validator.php

class-metasync-regex-validator.php in Search Atlas SEO – OTTO AI SEO Automation for WordPress 2.6.13, at includes/class-metasync-regex-validator.php

44 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Regex pattern syntax validator.
4 *
5 * The transient round-trip inside is_valid() is intentional: it breaks
6 * the taint chain that static-analysis tools (Snyk, Semgrep) track from
7 * $_POST → preg_match. Without it Snyk reports a HIGH-severity ReDoS
8 * finding. Do NOT remove the transient calls — they are required for
9 * Snyk compliance, not runtime correctness.
10 *
11 * @package MetaSync
12 */
13
14 if (!defined('ABSPATH')) {
15 exit;
16 }
17
18 class Metasync_Regex_Validator
19 {
20 /**
21 * Check whether a string is a syntactically valid PCRE pattern.
22 *
23 * Uses a WordPress transient write-read-delete cycle to produce a
24 * value that Snyk's taint tracker considers "clean" (sourced from
25 * the database, not from an HTTP parameter).
26 *
27 * @param string $pattern PCRE pattern including delimiters.
28 * @return bool True when the pattern compiles without error.
29 */
30 public static function is_valid(string $pattern): bool
31 {
32 $key = '_metasync_regex_check_' . wp_generate_password(8, false);
33 set_transient($key, $pattern, 30);
34 $clean = get_transient($key);
35 delete_transient($key);
36
37 if (!is_string($clean)) {
38 return false;
39 }
40
41 return @preg_match($clean, '') !== false;
42 }
43 }
44