Cookie-based routing should be case-sensitive.

This commit is contained in:
Igor Sysoev
2019-06-10 18:47:35 +03:00
parent b2a0620483
commit 1f8c395fc0
2 changed files with 25 additions and 16 deletions

View File

@@ -475,7 +475,7 @@ nxt_http_route_match_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
if (mtcf.cookies != NULL) {
table = nxt_http_route_table_create(task, mp, mtcf.cookies,
NXT_HTTP_ROUTE_COOKIE, 0);
NXT_HTTP_ROUTE_COOKIE, 1);
if (table == NULL) {
return NULL;
}
@@ -613,7 +613,7 @@ nxt_http_route_rule_name_create(nxt_task_t *task, nxt_mp_t *mp,
c = name->start[i];
*p++ = c;
c = nxt_lowcase(c);
c = case_sensitive ? c : nxt_lowcase(c);
hash = nxt_http_field_hash_char(hash, c);
}
@@ -1452,7 +1452,6 @@ nxt_http_route_cookie(nxt_array_t *array, u_char *name, size_t name_length,
for (p = name; p < name + name_length; p++) {
c = *p;
c = nxt_lowcase(c);
hash = nxt_http_field_hash_char(hash, c);
}
@@ -1483,8 +1482,7 @@ nxt_http_route_test_cookie(nxt_http_request_t *r,
if (rule->u.name.hash == nv->hash
&& rule->u.name.length == nv->name_length
&& nxt_strncasecmp(rule->u.name.start, nv->name, nv->name_length)
== 0)
&& nxt_memcmp(rule->u.name.start, nv->name, nv->name_length) == 0)
{
ret = nxt_http_route_test_rule(r, rule, nv->value,
nv->value_length);

View File

@@ -2423,7 +2423,7 @@ class TestRouting(TestApplicationProto):
self.get(
headers={
'Host': 'localhost',
'Cookie': 'foo=bar',
'Cookie': 'foO=bar',
'Connection': 'close',
},
)['status'],
@@ -2434,7 +2434,7 @@ class TestRouting(TestApplicationProto):
self.get(
headers={
'Host': 'localhost',
'Cookie': ['foo=bar', 'blah=blah'],
'Cookie': ['foO=bar', 'blah=blah'],
'Connection': 'close',
},
)['status'],
@@ -2445,7 +2445,7 @@ class TestRouting(TestApplicationProto):
self.get(
headers={
'Host': 'localhost',
'Cookie': 'foo=bar; blah=blah',
'Cookie': 'foO=bar; blah=blah',
'Connection': 'close',
},
)['status'],
@@ -2461,25 +2461,25 @@ class TestRouting(TestApplicationProto):
'Connection': 'close',
},
)['status'],
200,
'match cookies case insensitive',
404,
'match cookies case sensitive',
)
self.assertEqual(
self.get(
headers={
'Host': 'localhost',
'Cookie': 'foo=Bar',
'Cookie': 'foO=Bar',
'Connection': 'close',
},
)['status'],
200,
'match cookies case insensitive 2',
404,
'match cookies case sensitive 2',
)
self.assertEqual(
self.get(
headers={
'Host': 'localhost',
'Cookie': 'foo=bar1',
'Cookie': 'foO=bar1',
'Connection': 'close',
},
)['status'],
@@ -2490,12 +2490,23 @@ class TestRouting(TestApplicationProto):
self.get(
headers={
'Host': 'localhost',
'Cookie': 'foo=bar;',
'Cookie': '1foO=bar;',
'Connection': 'close',
},
)['status'],
404,
'match cookies exact 2',
)
self.assertEqual(
self.get(
headers={
'Host': 'localhost',
'Cookie': 'foO=bar;1',
'Connection': 'close',
},
)['status'],
200,
'match cookies exact 2',
'match cookies exact 3',
)
def test_routes_match_cookies_empty(self):