From 03b36d46c30d0382ebb876cf4ac132469ad3838c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 2 Dec 2021 20:59:06 +0100 Subject: [PATCH 1/2] [ticket/16924] Add test to cover potential escaping of json values PHPBB3-16924 --- tests/config/db_test.php | 11 +++++++++++ tests/config/db_text_test.php | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/tests/config/db_test.php b/tests/config/db_test.php index cf89341566..c77b3a3f66 100644 --- a/tests/config/db_test.php +++ b/tests/config/db_test.php @@ -86,6 +86,17 @@ class phpbb_config_db_test extends phpbb_database_test_case $this->cache->checkVar($this, 'config', array('foo' => '23', 'foobar' => '5')); } + public function test_set_new_json() + { + $json_value = '{"menu":{"id":"file","value":"File"}}'; + $this->config->set('foobar_json', $json_value); + $this->assertEquals($json_value, $this->config['foobar_json']); + + // re-read config and populate cache + $config2 = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config'); + $this->cache->checkVar($this, 'config', array('foo' => '23', 'foobar' => '5', 'foobar_json' => $json_value)); + } + public function test_set_new_uncached() { $this->config->set('foobar', '5', false); diff --git a/tests/config/db_text_test.php b/tests/config/db_text_test.php index 97d7daaf07..32cfcce15a 100644 --- a/tests/config/db_text_test.php +++ b/tests/config/db_text_test.php @@ -46,6 +46,13 @@ class phpbb_config_db_text_test extends phpbb_database_test_case $this->assertSame('phpbb', $this->config_text->get('barz')); } + public function test_set_new_get_json() + { + $json_value = '{"menu":{"id":"file","value":"File"}}'; + $this->config_text->set('foobar_json', $json_value); + $this->assertEquals($json_value, $this->config_text->get('foobar_json')); + } + public function test_set_replace_get() { $this->config_text->set('foo', '24'); From 8cc6075d920f1969cdcb17e75952ecb2df0b6ed7 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 2 Dec 2021 21:01:45 +0100 Subject: [PATCH 2/2] [ticket/16924] Do not double escape values inserted into config table PHPBB3-16924 --- phpBB/phpbb/config/db.php | 6 +++--- tests/config/db_test.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/phpbb/config/db.php b/phpBB/phpbb/config/db.php index 5c20bb5ec9..a346164db2 100644 --- a/phpBB/phpbb/config/db.php +++ b/phpBB/phpbb/config/db.php @@ -170,9 +170,9 @@ class db extends config if (!isset($this->config[$key])) { $sql = 'INSERT INTO ' . $this->table . ' ' . $this->db->sql_build_array('INSERT', array( - 'config_name' => $this->db->sql_escape($key), - 'config_value' => $this->db->sql_escape($new_value), - 'is_dynamic' => ($use_cache) ? 0 : 1)); + 'config_name' => $key, + 'config_value' => $new_value, + 'is_dynamic' => $use_cache ? 0 : 1)); $this->db->sql_query($sql); } diff --git a/tests/config/db_test.php b/tests/config/db_test.php index c77b3a3f66..11c99435f8 100644 --- a/tests/config/db_test.php +++ b/tests/config/db_test.php @@ -94,7 +94,7 @@ class phpbb_config_db_test extends phpbb_database_test_case // re-read config and populate cache $config2 = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config'); - $this->cache->checkVar($this, 'config', array('foo' => '23', 'foobar' => '5', 'foobar_json' => $json_value)); + $this->cache->checkVar($this, 'config', ['foo' => '23', 'foobar_json' => $json_value]); } public function test_set_new_uncached()