Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 511021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:10:25+00:00 2026-05-13T07:10:25+00:00

What are the allowed characters in both cookie name and value? Are they same

  • 0

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 behavior with cookies that have - in their name and I’m just wondering if it’s something browser specific or if my code is faulty.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:10:26+00:00Added an answer on May 13, 2026 at 7:10 am

    According to the ancient Netscape cookie_spec the entire NAME=VALUE string is:

    a sequence of characters excluding semi-colon, comma and white space.

    So - should work, and it does seem to be OK in browsers I’ve got here; where are you having trouble with it?

    By implication of the above:

    • = is legal to include, but potentially ambiguous. Browsers always split the name and value on the first = symbol in the string, so in practice you can put an = symbol in the VALUE but not the NAME.

    What isn’t mentioned, because Netscape were terrible at writing specs, but seems to be consistently supported by browsers:

    • either the NAME or the VALUE may be empty strings

    • if there is no = symbol in the string at all, browsers treat it as the cookie with the empty-string name, ie Set-Cookie: foo is the same as Set-Cookie: =foo.

    • when browsers output a cookie with an empty name, they omit the equals sign. So Set-Cookie: =bar begets Cookie: bar.

    • commas and spaces in names and values do actually seem to work, though spaces around the equals sign are trimmed

    • control characters (\x00 to \x1F plus \x7F) aren’t allowed

    What isn’t mentioned and browsers are totally inconsistent about, is non-ASCII (Unicode) characters:

    • in Opera and Google Chrome, they are encoded to Cookie headers with UTF-8;
    • in IE, the machine’s default code page is used (locale-specific and never UTF-8);
    • Firefox (and other Mozilla-based browsers) use the low byte of each UTF-16 code point on its own (so ISO-8859-1 is OK but anything else is mangled);
    • Safari simply refuses to send any cookie containing non-ASCII characters.

    so in practice you cannot use non-ASCII characters in cookies at all. If you want to use Unicode, control codes or other arbitrary byte sequences, the cookie_spec demands you use an ad-hoc encoding scheme of your own choosing and suggest URL-encoding (as produced by JavaScript’s encodeURIComponent) as a reasonable choice.

    In terms of actual standards, there have been a few attempts to codify cookie behaviour but none thus far actually reflect the real world.

    • RFC 2109 was an attempt to codify and fix the original Netscape cookie_spec. In this standard many more special characters are disallowed, as it uses RFC 2616 tokens (a - is still allowed there), and only the value may be specified in a quoted-string with other characters. No browser ever implemented the limitations, the special handling of quoted strings and escaping, or the new features in this spec.

    • RFC 2965 was another go at it, tidying up 2109 and adding more features under a ‘version 2 cookies’ scheme. Nobody ever implemented any of that either. This spec has the same token-and-quoted-string limitations as the earlier version and it’s just as much a load of nonsense.

    • RFC 6265 is an HTML5-era attempt to clear up the historical mess. It still doesn’t match reality exactly but it’s much better then the earlier attempts—it is at least a proper subset of what browsers support, not introducing any syntax that is supposed to work but doesn’t (like the previous quoted-string).

    In 6265 the cookie name is still specified as an RFC 2616 token, which means you can pick from the alphanums plus:

    !#$%&'*+-.^_`|~
    

    In the cookie value it formally bans the (filtered by browsers) control characters and (inconsistently-implemented) non-ASCII characters. It retains cookie_spec’s prohibition on space, comma and semicolon, plus for compatibility with any poor idiots who actually implemented the earlier RFCs it also banned backslash and quotes, other than quotes wrapping the whole value (but in that case the quotes are still considered part of the value, not an encoding scheme). So that leaves you with the alphanums plus:

    !#$%&'()*+-./:<=>?@[]^_`{|}~
    

    In the real world we are still using the original-and-worst Netscape cookie_spec, so code that consumes cookies should be prepared to encounter pretty much anything, but for code that produces cookies it is advisable to stick with the subset in RFC 6265.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 301k
  • Answers 301k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The technique you are referring to is very closely related… May 13, 2026 at 8:15 pm
  • Editorial Team
    Editorial Team added an answer The answer is that not to rely on the "_id"… May 13, 2026 at 8:15 pm
  • Editorial Team
    Editorial Team added an answer Ok serves me right for not googling enough. To answer… May 13, 2026 at 8:14 pm

Related Questions

Since this question is rather popular, I thought it useful to give it an
I rewrite URLs to include the title of user generated travelblogs. I do this
I'm trying to get a site to validate as HTML5 on the W3C Markup
How many characters long can an oauth access token and oauth access secret be
What are the typical characters allowed in text fields in a new user sign-up?

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.