Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c7ca33a

Browse filesBrowse files
committed
bug #54306 Throw TransformationFailedException when there is a null bytes injection (sormes)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- Throw TransformationFailedException when there is a null bytes injection | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | - <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT On one hand, in PHP 7, DateTime::createFromFormat allows null byte injection, and on the other hand, in PHP 8, it throws a ValueError that is not caught. This PR prevents injection when using version 5.4 under PHP 7 and onwards, throwing a TransformationFailedException. Commits ------- dd3c254 Throw TransformationFailedException when there is a null bytes injection
2 parents 8391d6d + dd3c254 commit c7ca33a
Copy full SHA for c7ca33a

File tree

2 files changed

+17
-0
lines changed
Filter options

2 files changed

+17
-0
lines changed

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ public function reverseTransform($value)
118118
throw new TransformationFailedException('Expected a string.');
119119
}
120120

121+
if (str_contains($value, "\0")) {
122+
throw new TransformationFailedException('Null bytes not allowed');
123+
}
124+
121125
$outputTz = new \DateTimeZone($this->outputTimezone);
122126
$dateTime = \DateTime::createFromFormat($this->parseFormat, $value, $outputTz);
123127

‎src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,19 @@ public function testReverseTransformEmpty()
133133
$this->assertNull($reverseTransformer->reverseTransform(''));
134134
}
135135

136+
public function testReverseTransformWithNullBytes()
137+
{
138+
$transformer = new DateTimeToStringTransformer();
139+
140+
$nullByte = \chr(0);
141+
$value = '2024-03-15 21:11:00'.$nullByte;
142+
143+
$this->expectException(TransformationFailedException::class);
144+
$this->expectExceptionMessage('Null bytes not allowed');
145+
146+
$transformer->reverseTransform($value);
147+
}
148+
136149
public function testReverseTransformWithDifferentTimezones()
137150
{
138151
$reverseTransformer = new DateTimeToStringTransformer('America/New_York', 'Asia/Hong_Kong', 'Y-m-d H:i:s');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.