Skip to content

Commit ce95ed5

Browse files
authored
Merge pull request from GHSA-w6jr-wj64-mc9x
fix: Deserialization of Untrusted Data in old()
2 parents bfa2262 + 025a63b commit ce95ed5

File tree

5 files changed

+48
-12
lines changed

5 files changed

+48
-12
lines changed

SECURITY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This person will coordinate the fix and release process, involving the following
2020
- Confirm the problem and determine the affected versions.
2121
- Audit code to find any potential similar problems.
2222
- Prepare fixes for all releases still under maintenance. These fixes will be released as fast as possible.
23+
- Publish security advisories at https://github.com/codeigniter4/CodeIgniter4/security/advisories
2324

2425
## Comments on this Policy
2526

system/Common.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -810,11 +810,6 @@ function old(string $key, $default = null, $escape = 'html')
810810
return $default;
811811
}
812812

813-
// If the result was serialized array or string, then unserialize it for use...
814-
if (is_string($value) && (strpos($value, 'a:') === 0 || strpos($value, 's:') === 0)) {
815-
$value = unserialize($value);
816-
}
817-
818813
return $escape === false ? $value : esc($value, $escape);
819814
}
820815
}

tests/system/CommonFunctionsTest.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,48 @@ public function testOldInput()
301301
$_GET = ['foo' => 'bar'];
302302
$_POST = [
303303
'bar' => 'baz',
304-
'zibble' => serialize('fritz'),
304+
'zibble' => 'fritz',
305305
];
306306

307307
$response = new RedirectResponse(new App());
308308
$response->withInput();
309309

310310
$this->assertSame('bar', old('foo')); // regular parameter
311311
$this->assertSame('doo', old('yabba dabba', 'doo')); // non-existing parameter
312-
$this->assertSame('fritz', old('zibble')); // serialized parameter
312+
$this->assertSame('fritz', old('zibble'));
313+
}
314+
315+
/**
316+
* @runInSeparateProcess
317+
* @preserveGlobalState disabled
318+
*/
319+
public function testOldInputSerializeData()
320+
{
321+
$this->injectSessionMock();
322+
// setup from RedirectResponseTest...
323+
$_SERVER['REQUEST_METHOD'] = 'GET';
324+
325+
$this->config = new App();
326+
$this->config->baseURL = 'http://example.com/';
327+
328+
$this->routes = new RouteCollection(Services::locator(), new Modules());
329+
Services::injectMock('routes', $this->routes);
330+
331+
$this->request = new MockIncomingRequest($this->config, new URI('http://example.com'), null, new UserAgent());
332+
Services::injectMock('request', $this->request);
333+
334+
// setup & ask for a redirect...
335+
$_SESSION = [];
336+
$_GET = [];
337+
$_POST = [
338+
'zibble' => serialize('fritz'),
339+
];
340+
341+
$response = new RedirectResponse(new App());
342+
$response->withInput();
343+
344+
// serialized parameters are only HTML-escaped.
345+
$this->assertSame('s:5:"fritz";', old('zibble'));
313346
}
314347

315348
/**

tests/system/HTTP/IncomingRequestTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ public function testMissingOldInput()
107107
$this->assertNull($this->request->getOldInput('pineapple.name'));
108108
}
109109

110-
// Reference: https://github.com/codeigniter4/CodeIgniter4/issues/1492
111-
public function testCanGetOldInputArray()
110+
/**
111+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/1492
112+
*/
113+
public function testCanGetOldInputArrayWithSESSION()
112114
{
113115
$_SESSION['_ci_old_input'] = [
114116
'get' => ['apple' => ['name' => 'two']],
@@ -119,13 +121,13 @@ public function testCanGetOldInputArray()
119121
$this->assertSame(['name' => 'foo'], $this->request->getOldInput('banana'));
120122
}
121123

122-
// Reference: https://github.com/codeigniter4/CodeIgniter4/issues/1492
123-
124124
/**
125+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/1492
126+
*
125127
* @runInSeparateProcess
126128
* @preserveGlobalState disabled
127129
*/
128-
public function testCanSerializeOldArray()
130+
public function testCanGetOldInputArrayWithSessionService()
129131
{
130132
$locations = [
131133
'AB' => 'Alberta',

user_guide_src/source/changelogs/v4.1.6.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Release Date: Not released
99
:local:
1010
:depth: 2
1111

12+
SECURITY
13+
********
14+
15+
- *Deserialization of Untrusted Data* found in the ``old()`` function was fixed. See the `Security advisory <https://github.com/codeigniter4/CodeIgniter4/security/advisories/GHSA-w6jr-wj64-mc9x>`_ for more information.
16+
1217
BREAKING
1318
********
1419

0 commit comments

Comments
 (0)