From 6cc7da0c9c0fc8515aad780fba5de5b3860e5d56 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 3 Nov 2014 16:07:32 +0100 Subject: [ticket/13280] Properly format the current page and add sanitizer to tests PHPBB3-13280 --- tests/security/extract_current_page_test.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/security/extract_current_page_test.php b/tests/security/extract_current_page_test.php index 58dea68dc8..8e536ee461 100644 --- a/tests/security/extract_current_page_test.php +++ b/tests/security/extract_current_page_test.php @@ -37,16 +37,16 @@ class phpbb_security_extract_current_page_test extends phpbb_security_test_base )); $symfony_request->expects($this->any()) ->method('getScriptName') - ->will($this->returnValue($url)); + ->will($this->returnValue($this->sanitizer($url))); $symfony_request->expects($this->any()) ->method('getQueryString') - ->will($this->returnValue($query_string)); + ->will($this->returnValue($this->sanitizer($query_string))); $symfony_request->expects($this->any()) ->method('getBasePath') ->will($this->returnValue($server['REQUEST_URI'])); - $symfony_request->expects($this->any()) + $symfony_request->expects($this->sanitizer($this->any())) ->method('getPathInfo') - ->will($this->returnValue('/')); + ->will($this->returnValue($this->sanitizer('/'))); $result = \phpbb\session::extract_current_page('./'); $label = 'Running extract_current_page on ' . $query_string . ' with PHP_SELF filled.'; @@ -65,20 +65,27 @@ class phpbb_security_extract_current_page_test extends phpbb_security_test_base )); $symfony_request->expects($this->any()) ->method('getScriptName') - ->will($this->returnValue($url)); + ->will($this->returnValue($this->sanitizer($url))); $symfony_request->expects($this->any()) ->method('getQueryString') - ->will($this->returnValue($query_string)); + ->will($this->returnValue($this->sanitizer($query_string))); $symfony_request->expects($this->any()) ->method('getBasePath') - ->will($this->returnValue($server['REQUEST_URI'])); + ->will($this->returnValue($this->sanitizer($server['REQUEST_URI']))); $symfony_request->expects($this->any()) ->method('getPathInfo') - ->will($this->returnValue('/')); + ->will($this->returnValue($this->sanitizer('/'))); $result = \phpbb\session::extract_current_page('./'); $label = 'Running extract_current_page on ' . $query_string . ' with REQUEST_URI filled.'; $this->assertEquals($expected, $result['query_string'], $label); } + + protected function sanitizer($value) + { + $type_cast_helper = new \phpbb\request\type_cast_helper(); + $type_cast_helper->set_var($value, $value, gettype($value), true); + return $value; + } } -- cgit v1.2.1 From 6fd092b5df6f96530fec8ba1aec426b6d59b822b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 3 Nov 2014 16:24:09 +0100 Subject: [ticket/13280] Correctly format user page for build_url() PHPBB3-13280 --- tests/functions/build_url_test.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functions/build_url_test.php b/tests/functions/build_url_test.php index 06415a424e..df178f277e 100644 --- a/tests/functions/build_url_test.php +++ b/tests/functions/build_url_test.php @@ -79,9 +79,16 @@ class phpbb_build_url_test extends phpbb_test_case { global $user, $phpbb_root_path; - $user->page['page'] = $page; + $user->page['page'] = str_replace('%2F', '/', urlencode($this->sanitizer($page))); $output = build_url($strip_vars); $this->assertEquals($expected, $output); } + + protected function sanitizer($value) + { + $type_cast_helper = new \phpbb\request\type_cast_helper(); + $type_cast_helper->set_var($value, $value, gettype($value), true); + return $value; + } } -- cgit v1.2.1 From 13b59af1ffd0af652ba0ce3bc3f2594fc448fdb5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 3 Nov 2014 17:14:18 +0100 Subject: [ticket/13280] Add additional sanitizer for ampersands in server superglobal PHPBB3-13280 --- tests/functions/build_url_test.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/functions/build_url_test.php b/tests/functions/build_url_test.php index df178f277e..5cfd1300de 100644 --- a/tests/functions/build_url_test.php +++ b/tests/functions/build_url_test.php @@ -69,6 +69,11 @@ class phpbb_build_url_test extends phpbb_test_case array('f', 'style', 't'), 'http://test.phpbb.com/viewtopic.php?', ), + array( + 'posting.php?f=2&mode=delete&p=20%22%3Cscript%3Ealert%281%29%3B%3C%2Fscript%3E', + false, + 'phpBB/posting.php?f=2&mode=delete&p=20%22%3Cscript%3Ealert%281%29%3B%3C%2Fscript%3E', + ) ); } @@ -79,16 +84,10 @@ class phpbb_build_url_test extends phpbb_test_case { global $user, $phpbb_root_path; - $user->page['page'] = str_replace('%2F', '/', urlencode($this->sanitizer($page))); + $user->page['page'] = $page; + $output = build_url($strip_vars); $this->assertEquals($expected, $output); } - - protected function sanitizer($value) - { - $type_cast_helper = new \phpbb\request\type_cast_helper(); - $type_cast_helper->set_var($value, $value, gettype($value), true); - return $value; - } } -- cgit v1.2.1 From 32881dbe31a945b6d2449a3f7e1bf7c5e73cd0a6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 4 Nov 2014 16:54:45 +0100 Subject: [ticket/13280] Only run sanitizer for server superglobal and modify tests PHPBB3-13280 --- tests/security/extract_current_page_test.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/security/extract_current_page_test.php b/tests/security/extract_current_page_test.php index 8e536ee461..c127b69b2b 100644 --- a/tests/security/extract_current_page_test.php +++ b/tests/security/extract_current_page_test.php @@ -84,8 +84,13 @@ class phpbb_security_extract_current_page_test extends phpbb_security_test_base protected function sanitizer($value) { + // Fix for objects passed in phpunit + if (is_object($value)) + { + return $value; + } $type_cast_helper = new \phpbb\request\type_cast_helper(); $type_cast_helper->set_var($value, $value, gettype($value), true); - return $value; + return str_replace('&', '&', $value); } } -- cgit v1.2.1