Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 7a000c0

Browse files
committed
Merge branch 'hotfix/47'
Close #47
2 parents 79e07df + 7fe05d7 commit 7a000c0

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

src/HeaderSecurity.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,15 @@ public static function isValid($value)
106106
return false;
107107
}
108108

109-
$length = strlen($value);
110-
for ($i = 0; $i < $length; $i += 1) {
111-
$ascii = ord($value[$i]);
112-
113-
// Non-visible, non-whitespace characters
114-
// 9 === horizontal tab
115-
// 10 === line feed
116-
// 13 === carriage return
117-
// 32-126, 128-254 === visible
118-
// 127 === DEL
119-
// 255 === null byte
120-
if (($ascii < 32 && ! in_array($ascii, [9, 10, 13], true))
121-
|| $ascii === 127
122-
|| $ascii > 254
123-
) {
124-
return false;
125-
}
109+
// Non-visible, non-whitespace characters
110+
// 9 === horizontal tab
111+
// 10 === line feed
112+
// 13 === carriage return
113+
// 32-126, 128-254 === visible
114+
// 127 === DEL (disallowed)
115+
// 255 === null byte (disallowed)
116+
if (preg_match('/[^\x09\x0a\x0d\x20-\x7E\x80-\xFE]/', $value)) {
117+
return false;
126118
}
127119

128120
return true;

test/HeaderSecurityTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ public function validateValues()
6565
["This is a\r\r test", 'assertFalse'],
6666
["This is a \r\r\n test", 'assertFalse'],
6767
["This is a \r\n\r\ntest", 'assertFalse'],
68-
["This is a \r\n\n\r\n test", 'assertFalse']
68+
["This is a \r\n\n\r\n test", 'assertFalse'],
69+
["This is a \xFF test", 'assertFalse'],
70+
["This is a \x7F test", 'assertFalse'],
71+
["This is a \x7E test", 'assertTrue'],
6972
];
7073
}
7174

0 commit comments

Comments
 (0)