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) { if (mtcf.cookies != NULL) {
table = nxt_http_route_table_create(task, mp, mtcf.cookies, table = nxt_http_route_table_create(task, mp, mtcf.cookies,
NXT_HTTP_ROUTE_COOKIE, 0); NXT_HTTP_ROUTE_COOKIE, 1);
if (table == NULL) { if (table == NULL) {
return 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]; c = name->start[i];
*p++ = c; *p++ = c;
c = nxt_lowcase(c); c = case_sensitive ? c : nxt_lowcase(c);
hash = nxt_http_field_hash_char(hash, 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++) { for (p = name; p < name + name_length; p++) {
c = *p; c = *p;
c = nxt_lowcase(c);
hash = nxt_http_field_hash_char(hash, 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 if (rule->u.name.hash == nv->hash
&& rule->u.name.length == nv->name_length && rule->u.name.length == nv->name_length
&& nxt_strncasecmp(rule->u.name.start, nv->name, nv->name_length) && nxt_memcmp(rule->u.name.start, nv->name, nv->name_length) == 0)
== 0)
{ {
ret = nxt_http_route_test_rule(r, rule, nv->value, ret = nxt_http_route_test_rule(r, rule, nv->value,
nv->value_length); nv->value_length);

View File

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