Skip to content

Commit d9a24ba

Browse files
authored
net: fix cookie parsing when ; is used (fix #25544) (#25561)
1 parent be8023b commit d9a24ba

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

vlib/net/http/cookie.v

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ pub fn sanitize_cookie_value(v string) string {
192192
if v.len == 0 {
193193
return v
194194
}
195-
// Check for the existence of a space or comma
196-
if val.starts_with(' ') || val.ends_with(' ') || val.starts_with(',') || val.ends_with(',') {
195+
// Check for the existence of a space, comma or semicolon
196+
if val.starts_with(' ') || v.contains(';') || val.ends_with(' ') || val.starts_with(',')
197+
|| val.ends_with(',') {
197198
return '"${v}"'
198199
}
199200
return v

vlib/net/http/cookie_test.v

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,13 @@ const write_set_cookie_tests = [
224224
}
225225
raw: ''
226226
},
227+
SetCookieTestCase{
228+
cookie: &http.Cookie{
229+
name: 'complex-value'
230+
value: 'a b,c;d'
231+
}
232+
raw: 'complex-value="a b,c;d"'
233+
},
227234
]
228235
const add_cookies_tests = [
229236
AddCookieTestCase{

0 commit comments

Comments
 (0)