1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Strip header whitespace. Fix #1890. Code by @matthewd (#2010)

* Strip header whitespace in C

Fix #1890

Co-authored-by: Matthew Draper <matthew@trebex.net>

* Add Java extension to do the same

Co-authored-by: Charles Nutter <headius@headius.com>

* Changelog
This commit is contained in:
Nate Berkopec 2019-10-07 15:23:18 +02:00 committed by GitHub
parent 2d46f0b63a
commit 22b135a636
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 5 deletions

View file

@ -1,5 +1,5 @@
* Features
* Your feature goes here (#Github Number)
* Strip whitespace at end of HTTP headers (#2010)
* Bugfixes
* Your bugfix goes here (#Github Number)

View file

@ -87,7 +87,9 @@ public class Http11 extends RubyObject {
validateMaxLength(flen, MAX_FIELD_NAME_LENGTH, MAX_FIELD_NAME_LENGTH_ERR);
validateMaxLength(vlen, MAX_FIELD_VALUE_LENGTH, MAX_FIELD_VALUE_LENGTH_ERR);
ByteList b = new ByteList(Http11.this.hp.parser.buffer,field,flen);
ByteList buffer = Http11.this.hp.parser.buffer;
ByteList b = new ByteList(buffer,field,flen);
for(int i = 0,j = b.length();i<j;i++) {
if((b.get(i) & 0xFF) == '-') {
b.set(i, (byte)'_');
@ -105,7 +107,9 @@ public class Http11 extends RubyObject {
f.cat(b);
}
b = new ByteList(Http11.this.hp.parser.buffer, value, vlen);
while (vlen > 0 && Character.isWhitespace(buffer.get(value + vlen - 1))) vlen--;
b = new ByteList(buffer, value, vlen);
v = req.op_aref(req.getRuntime().getCurrentContext(), f);
if (v.isNil()) {
req.op_aset(req.getRuntime().getCurrentContext(), f, RubyString.newString(runtime, b));

View file

@ -200,6 +200,8 @@ void http_field(puma_parser* hp, const char *field, size_t flen,
f = rb_str_new(hp->buf, new_size);
}
while (vlen > 0 && isspace(value[vlen - 1])) vlen--;
/* check for duplicate header */
v = rb_hash_aref(hp->request, f);

View file

@ -199,9 +199,7 @@ class Http11ParserTest < Minitest::Test
end
end
# https://github.com/puma/puma/issues/1890
def test_trims_whitespace_from_headers
skip("Known failure, see issue 1890 on GitHub")
parser = Puma::HttpParser.new
req = {}
http = "GET / HTTP/1.1\r\nX-Strip-Me: Strip This \r\n\r\n"