What are allowed characters in cookies?

前端 未结 13 1060
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 03:36

What are the allowed characters in both cookie name and value? Are they same as URL or some common subset?

Reason I\'m asking is that I\'ve recently hit some strange

13条回答
  •  北海茫月
    2020-11-22 04:34

    Newer rfc6265 published in April 2011:

    cookie-header = "Cookie:" OWS cookie-string OWS
    cookie-string = cookie-pair *( ";" SP cookie-pair )
    cookie-pair  = cookie-name "=" cookie-value
    cookie-value = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
    
    cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
                       ; US-ASCII characters excluding CTLs,
                       ; whitespace DQUOTE, comma, semicolon,
                       ; and backslash
    

    If you look to @bobince answer you see that newer restrictions are more strict.

提交回复
热议问题