Skip to content

Commit f001c63

Browse files
committed
Update header handling to RFC 7230
1 parent 7efbd70 commit f001c63

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ PHP NEWS
33
?? ??? 20?? PHP 5.4.38
44

55
- Core:
6+
. Removed support for multi-line headers, as the are deprecated by RFC 7230.
7+
(Stas)
68
. Fixed bug #68925 (Mitigation for CVE-2015-0235 – GHOST: glibc gethostbyname
79
buffer overflow). (Stas)
810

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
--TEST--
22
Bug #60227 (header() cannot detect the multi-line header with CR), \r before \n
3+
--INI--
4+
expose_php=0
35
--FILE--
46
<?php
57
header("X-foo: e\n foo");
6-
header("X-Foo6: e\rSet-Cookie: ID=123\n d");
78
echo 'foo';
89
?>
910
--EXPECTF--
11+
1012
Warning: Header may not contain more than a single header, new line detected in %s on line %d
1113
foo
1214
--EXPECTHEADERS--
13-
X-foo: e
14-
foo
15+
Content-type: text/html; charset=UTF-8
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
--TEST--
22
Bug #60227 (header() cannot detect the multi-line header with CR), \0 before \n
3+
--INI--
4+
expose_php=0
35
--FILE--
46
<?php
5-
header("X-foo: e\n foo");
67
header("X-Foo6: e\0Set-Cookie: ID=\n123\n d");
78
echo 'foo';
89
?>
910
--EXPECTF--
1011
Warning: Header may not contain NUL bytes in %s on line %d
1112
foo
1213
--EXPECTHEADERS--
13-
X-foo: e
14-
foo
14+
Content-type: text/html; charset=UTF-8
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
--TEST--
22
Bug #60227 (header() cannot detect the multi-line header with CR), CRLF
3+
--INI--
4+
expose_php=0
35
--FILE--
46
<?php
5-
header("X-foo: e\r\n foo");
67
header("X-foo: e\r\nfoo");
78
echo 'foo';
89
?>
910
--EXPECTF--
1011
Warning: Header may not contain more than a single header, new line detected in %s on line %d
1112
foo
1213
--EXPECTHEADERS--
13-
X-foo: e
14-
foo
14+
Content-type: text/html; charset=UTF-8

main/SAPI.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -743,13 +743,8 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
743743
/* new line/NUL character safety check */
744744
int i;
745745
for (i = 0; i < header_line_len; i++) {
746-
/* RFC 2616 allows new lines if followed by SP or HT */
747-
int illegal_break =
748-
(header_line[i+1] != ' ' && header_line[i+1] != '\t')
749-
&& (
750-
header_line[i] == '\n'
751-
|| (header_line[i] == '\r' && header_line[i+1] != '\n'));
752-
if (illegal_break) {
746+
/* RFC 7230 ch. 3.2.4 deprecates folding support */
747+
if (header_line[i] == '\n' || header_line[i] == '\r') {
753748
efree(header_line);
754749
sapi_module.sapi_error(E_WARNING, "Header may not contain "
755750
"more than a single header, new line detected");

0 commit comments

Comments
 (0)