Pass the menu and read the page

SignupFolio

Session ID length rules: 4 publisher checks

OWASP says a hex-encoded session ID needs at least 16 characters to reach 64 bits of entropy. The session identifier is a value that maintains the active state. ASP.NET Core provides a cookie to the client containing this session ID, according to Microsoft.

Key takeaways for session identifier length rules

  • Use at least 16 hexadecimal characters for 64 bits of entropy when your session ID uses hex encoding (OWASP).
  • If you build your own session ID, use a CSPRNG with at least 128 bits and make each ID unique (OWASP).
  • Count only the random characters, because fixed characters add no randomness.
  • Store only an identifier in the cookie, and keep it within the 4096-byte browser limit (Microsoft).

The identifier that keeps a new account signed in has a minimum size

When a user completes the signup process, the system must retain a reference that proves the connection remains active on subsequent requests. This reference is the session identifier. It is not the password or the email address; it is a separate value. The login state persists across page loads through this identifier. Size matters separately for security: if the identifier is too short, the space of possible values shrinks, making the specific value easier to locate through random guessing. Therefore, the size of this identifier is a fundamental security parameter for any signup flow.

Microsoft describes the mechanism by which this state is maintained in web applications. In their documentation for ASP.NET Core, they explain that the framework handles session state by providing a cookie to the client. This cookie contains the session ID. The browser stores this cookie and can send it back to the server later. The server then looks up the session data associated with that ID. The identifier itself is the key to this lookup table.

The session identifier must meet specific size and security standards to keep the login state active. The 16-character minimum ensures the identifier carries sufficient random data to resist guessing attacks; length alone is not enough if the characters are fixed. Using a generator larger than the minimum entropy helps maintain uniqueness across many concurrent users without relying on sequential numbering.

The cookie should hold an identifier rather than the whole record, keeping the payload small enough to fit within standard browser constraints. NIST explains that cookies are not authenticators but are suitable as short-term secrets for the duration of a session (NIST). This distinction means the cookie tracks the session state but does not verify the user's identity by itself; it relies on other factors established during login.

Reference table of identifier rules by publisher

PublisherRule or DefinitionSource Document
OWASPWhen using hexadecimal encoding, a session ID must be at least 16 hexadecimal characters long to achieve the required 64 bits of entropy. If you need to create your own sessionID, use a cryptographically secure pseudorandom number generator (CSPRNG) with a size of at least 128 bits and ensure that each sessionID is unique.Session Management - OWASP Cheat Sheet Series
MicrosoftMost browsers restrict cookie size to 4096 bytes. Ideally, only an identifier should be stored in a cookie with the data stored by the app.Session in ASP.NET Core - Microsoft Learn
MDNThe HTTP Set-Cookie response header is used to send a cookie from the server to the user agent, so that the user agent can send it back to the server later.Set-Cookie header - HTTP - MDN
NISTCookies are not authenticators but are suitable as short-term secrets for the duration of a session.NIST Special Publication 800-63B

Review these rows against your current implementation. Verify that your session ID generation matches the OWASP requirements for both entropy and generator size. Confirm that your cookie storage strategy aligns with the Microsoft guidance on storing identifiers rather than full records. Ensure your server correctly uses the Set-Cookie header as described by MDN. Finally, distinguish between the cookie's role as a session tracker and its lack of authenticator status, as NIST describes. For a broader release check, see Test signup authentication with 5 steps before release.

How many bits and characters OWASP names

The Session Management Cheat Sheet Series from OWASP sets a specific floor for the random value in the identifier. It states that when using hexadecimal encoding, a session ID must be at least 16 hexadecimal characters long to achieve the required 64 bits of entropy according to OWASP. This connects two numbers: the bit count measures the randomness, while the character count defines the visible length in a hex string. The publisher ties these together directly; it does not list separate minimums for other encodings in this rule. If your identifier uses base-64 or another format, the 16-character hex figure does not apply as written. Stick to the hex context when quoting this limit.

OWASP also illustrates why the full length matters by describing what happens if part of the ID is fixed. For example, if half of a 16-character hexadecimal session ID is fixed, only the remaining 8 characters are random, providing just 32 bits of entropy — which is insufficient for strong security according to OWASP. This shows that the entropy comes from the random portion alone. A developer might prepend a constant prefix for routing or versioning; the prefix adds no randomness, but the random portion still counts. Check whether any part of your generated ID is static. If so, subtract those fixed characters from the total before comparing against the 64-bit requirement. The cheat sheet warns that 32 bits is not enough, so an ID whose random portion provides fewer than 64 bits does not meet the 64-bit standard.

To put the 64-bit threshold in perspective, OWASP provides a calculation based on guessing speed and available sessions. If a web application generates session IDs with 64 bits of entropy, an attacker can expect to spend approximately 585 years to successfully guess a valid session ID, assuming the attacker can try 10,000 guesses each second with 100,000 valid simultaneous sessions available in the application according to OWASP. This is a theoretical estimate, not a guarantee that no account will ever be guessed. The time depends on the specific assumptions about guessing rate and concurrent sessions. Do not use the 585-year figure as a promise of absolute safety. Instead, view it as evidence that 64 bits creates a large search space under those conditions. If your system has far fewer active sessions or slower attack vectors, the real-world risk may differ, but the entropy floor remains the same.

Illustrative example: counting random characters

Suppose an identifier is 16 hexadecimal characters long, and 8 of them are a fixed prefix. The 8 random characters provide 32 bits, half the 64-bit target. Reaching the target would take 16 random characters.

The browser limit for the storage container is a hard number you can check against your current setup. Most browsers restrict cookie size to 4096 bytes, according to Microsoft.

Beyond the raw byte count, the content of that cookie matters for security. Ideally, only an identifier should be stored in a cookie with the data stored by the app, according to Microsoft. Storing the full user record, preferences, or credential details directly in the cookie expands the attack surface. The identifier acts as a key that the server uses to look up the actual session state in its own memory or database. Keeping the cookie small and opaque reduces the risk of exposing sensitive data if the cookie is intercepted or logged.

Because cookies are subject to tampering, they must be validated by the app, according to Microsoft. Your backend logic cannot assume the cookie is unchanged since it was issued. Validation steps should verify the integrity of the identifier and ensure it maps to a valid, active session on the server side. Without this check, a modified cookie could grant access to another account or bypass permission checks.

The lifecycle of this specific type of cookie is tied to the browser session. Session cookies are deleted when the browser session ends, according to Microsoft. Check which kind of cookie your signup flow sets, because a session cookie and a persistent cookie follow different lifecycles.

When designing your signup flow, verify that the identifier generated fits comfortably within the 4096-byte limit. Check that your application validates the session identifier against the server-side session store rather than trusting the client-provided value. Confirm that your documentation clarifies whether the cookie is intended to be a session cookie that expires on close or a persistent cookie with an expiration date. These checks align with the guidance provided in the Session in ASP.NET Core documentation and help prevent common implementation errors related to size and trust boundaries.

The mechanism for returning the session identifier relies on a specific HTTP header. According to MDN, the HTTP Set-Cookie response header sends a cookie from the server to the user agent so that the user agent can send it back to the server later. This header acts as the initial instruction for the browser to store and subsequently transmit the data. If your signup flow sets the session cookie, that response carries this header.

A cookie definition starts with a name-value pair, according to MDN. The browser uses this name to identify which stored value to attach to future requests. If you are checking your implementation, verify that the name assigned to the session cookie matches what your backend expects when reading incoming headers. The value itself should be the opaque identifier discussed in other sections, not personal data or full account records.

Servers may need to set more than one cookie in a single interaction. To send multiple cookies, multiple Set-Cookie headers should be sent in the same response, according to MDN. This applies if your application sets a session identifier alongside other tracking or preference cookies. Each header operates independently, allowing the browser to store distinct values under different names. For example, one header might set the session ID, while another sets a theme preference. The browser processes each header separately but returns all applicable cookies in the next request. Ensure your code generates separate headers rather than attempting to combine multiple values into a single header line, as MDN describes.

The distinction between tracking a session and proving identity is critical for marketers checking their signup flows. NIST Special Publication 800-63B clarifies that browser cookies are the predominant mechanism by which a session is created and tracked when a subscriber accesses a service, according to NIST. This definition establishes the cookie's role as a tracker rather than a proof of who the user is.

However, the same publication draws a hard line on security status. Cookies are not authenticators but are suitable as short-term secrets for the duration of a session, according to NIST. This means the identifier stored in the cookie maintains the active state but does not serve as the primary credential verifying the account holder's identity. Marketers should understand that the cookie keeps the login alive; it does not replace the password or multi-factor authentication used at the start of the session.

To find the specific technical requirements, look to Section 5 of the document, which describes requirements for session management, according to NIST. Within that section, Section 5.1.1 adds requirements for browser cookies used for session maintenance, according to NIST. These subsections detail how the cookie must behave to remain a secure short-term secret without crossing into authenticator territory.

When reviewing your own implementation, verify that your system treats the cookie strictly as a session identifier. Do not rely on the cookie value alone to confirm user identity during sensitive actions. The NIST guidance supports using the cookie to track the session while keeping authenticator checks separate. If your current setup blurs this line, ask your developer to review the separation between session tracking and identity verification. Ensure the cookie remains a short-term secret as defined by the standard. Review your session and authentication handling to confirm this separation. For related authentication steps, see Passkey registration: 4 steps for a new account flow.

Next step: count the random characters in one session ID your signup flow creates, then compare that count with the 16-character hexadecimal minimum in the OWASP cheat sheet.

Session identifier length FAQ

How many hexadecimal characters does OWASP require for 64 bits?

According to OWASP, a session ID must be at least 16 hexadecimal characters long when using hexadecimal encoding. This length is required to achieve the necessary 64 bits of entropy.

What size of generator does OWASP name for a homemade session id?

If you need to create your own sessionID, OWASP specifies using a cryptographically secure pseudorandom number generator (CSPRNG). The generator must have a size of at least 128 bits, and each sessionID must remain unique.

Microsoft states that most browsers restrict cookie size to 4096 bytes.

No, NIST states that cookies are not authenticators. However, NIST notes they are suitable as short-term secrets for the duration of a session.

Sources and check date

Related posts

More posts