diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2007-09-21 15:00:40 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2007-09-21 15:00:40 +0000 |
commit | 69d29e9282e0fcdbcac0017acea8aaa942ee2623 (patch) | |
tree | 0e1df725fcc84bdae0e76fb20ed99aa86be91d7a | |
parent | 529980ab79094234eda8e6d796a3e0736c1c00cc (diff) | |
download | forums-69d29e9282e0fcdbcac0017acea8aaa942ee2623.tar forums-69d29e9282e0fcdbcac0017acea8aaa942ee2623.tar.gz forums-69d29e9282e0fcdbcac0017acea8aaa942ee2623.tar.bz2 forums-69d29e9282e0fcdbcac0017acea8aaa942ee2623.tar.xz forums-69d29e9282e0fcdbcac0017acea8aaa942ee2623.zip |
put expressions for ip validation into our get_preg_ function.
git-svn-id: file:///svn/phpbb/trunk@8094 89ea8834-ac86-4346-8a33-228a782c2dd0
-rw-r--r-- | phpBB/includes/functions.php | 13 | ||||
-rw-r--r-- | phpBB/includes/session.php | 8 |
2 files changed, 13 insertions, 8 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 3742d89475..cb2631d7b5 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3414,7 +3414,7 @@ function get_backtrace() /** * This function returns a regular expression pattern for commonly used expressions * Use with / as delimiter for email mode and # for url modes -* mode can be: email|bbcode_htm|url|url_inline|www_url|www_url_inline|relative_url|relative_url_inline +* mode can be: email|bbcode_htm|url|url_inline|www_url|www_url_inline|relative_url|relative_url_inline|ipv4|ipv6 */ function get_preg_expression($mode) { @@ -3435,6 +3435,17 @@ function get_preg_expression($mode) ); break; + // Whoa these look impressive! + // The code to generate the following two regular expressions which match valid IPv4/IPv6 addresses + // can be found in the develop directory + case 'ipv4': + return '#^(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$#'; + break; + + case 'ipv6': + return '#^(?:(?:(?:[\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+ case 'url': case 'url_inline': $inline = ($mode == 'url') ? ')' : ''; diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index de60f7f2bf..9def5f1edf 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -148,18 +148,12 @@ class session { $this->forwarded_for = preg_replace('#, +#', ', ', $this->forwarded_for); - // Whoa these look impressive! - // The code to generate the following two regular expressions which match valid IPv4/IPv6 addresses - // can be found in the develop directory - $ipv4 = '#^(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$#'; - $ipv6 = '#^(?:(?:(?:[\dA-F]{1,4}:){6}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:::(?:[\dA-F]{1,4}:){5}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:):(?:[\dA-F]{1,4}:){4}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,2}:(?:[\dA-F]{1,4}:){3}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,3}:(?:[\dA-F]{1,4}:){2}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,4}:(?:[\dA-F]{1,4}:)(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,5}:(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,6}:[\dA-F]{1,4})|(?:(?:[\dA-F]{1,4}:){1,7}:))$#i'; - // split the list of IPs $ips = explode(', ', $this->forwarded_for); foreach ($ips as $ip) { // check IPv4 first, the IPv6 is hopefully only going to be used very seldomly - if (!empty($ip) && !preg_match($ipv4, $ip) && !preg_match($ipv6, $ip)) + if (!empty($ip) && !preg_match(get_preg_expression('ipv4'), $ip) && !preg_match(get_preg_expression('ipv6'), $ip)) { // contains invalid data, don't use the forwarded for header $this->forwarded_for = ''; |