Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
5500d544
Commit
5500d544
authored
Dec 08, 2017
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix header validation to match Fetch spec.
parent
7f513230
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
1 deletion
+28
-1
http-test.c++
c++/src/kj/compat/http-test.c++
+23
-0
http.c++
c++/src/kj/compat/http.c++
+5
-1
No files found.
c++/src/kj/compat/http-test.c++
View file @
5500d544
...
...
@@ -233,6 +233,29 @@ KJ_TEST("HttpHeaders parse invalid") {
"
\r\n
"
))
==
nullptr
);
}
KJ_TEST
(
"HttpHeaders validation"
)
{
auto
table
=
HttpHeaderTable
::
Builder
().
build
();
HttpHeaders
headers
(
*
table
);
headers
.
add
(
"Valid-Name"
,
"valid value"
);
// The HTTP RFC prohibits control characters, but browsers only prohibit \0, \r, and \n. KJ goes
// with the browsers for compatibility.
headers
.
add
(
"Valid-Name"
,
"valid
\x01
value"
);
// The HTTP RFC does not permit non-ASCII values.
// KJ chooses to interpret them as UTF-8, to avoid the need for any expensive conversion.
// Browsers apparently interpret them as LATIN-1. Applications can reinterpet these strings as
// LATIN-1 easily enough if they really need to.
headers
.
add
(
"Valid-Name"
,
u8"valid€value"
);
KJ_EXPECT_THROW_MESSAGE
(
"invalid header name"
,
headers
.
add
(
"Invalid Name"
,
"value"
));
KJ_EXPECT_THROW_MESSAGE
(
"invalid header name"
,
headers
.
add
(
"Invalid@Name"
,
"value"
));
KJ_EXPECT_THROW_MESSAGE
(
"invalid header value"
,
headers
.
set
(
HttpHeaderId
::
HOST
,
"in
\n
valid"
));
KJ_EXPECT_THROW_MESSAGE
(
"invalid header value"
,
headers
.
add
(
"Valid-Name"
,
"in
\n
valid"
));
}
// =======================================================================================
class
ReadFragmenter
final
:
public
kj
::
AsyncIoStream
{
...
...
c++/src/kj/compat/http.c++
View file @
5500d544
...
...
@@ -461,7 +461,11 @@ static void requireValidHeaderName(kj::StringPtr name) {
static
void
requireValidHeaderValue
(
kj
::
StringPtr
value
)
{
for
(
char
c
:
value
)
{
KJ_REQUIRE
(
c
>=
0x20
,
"invalid header value"
,
value
);
// While the HTTP spec suggests that only printable ASCII characters are allowed in header
// values, reality has a different opinion. See: https://github.com/httpwg/http11bis/issues/19
// We follow the browsers' lead.
KJ_REQUIRE
(
c
!=
'\0'
&&
c
!=
'\r'
&&
c
!=
'\n'
,
"invalid header value"
,
kj
::
encodeCEscape
(
value
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment