How to Prevent Web Sessions from Using Unknown Client-Supplied IDs
An application may create an anonymous session on the first request. The question is who chooses its identifier: the server or the client. If the server receives an unknown ID and creates a session under that exact value, it uses a permissive mechanism. Preventing this requires a strict mechanism: the application accepts only identifiers it previously issued and replaces unknown values with new IDs of its own. Here is how to test that boundary and confirm the result using the server response and storage state.
The trust boundary: the client returns the ID, the server creates it
A session identifier cannot be considered application-issued simply because it arrives in a cookie and looks valid. Its format and its origin are separate concerns. A strict mechanism accepts identifiers previously created by the application itself. A permissive mechanism allows a different behavior: it accepts a client-chosen value and creates a new session for it.
The test has a narrow purpose: to verify that an unknown value does not become the identifier of a new session. It does not establish the security of the entire session management system and, on its own, says nothing about access to user data.
A fictional test environment and observable results
Consider a wholly fictional web product called “Mockup,” owned by the developer’s team. In its test environment, the /demo-session route normally creates an anonymous session. All records are synthetic; the team adds demo-marker-17 to the session data as an observation marker. The route, cookie, and marker names used here are illustrative.
The data associated with the ID and the application’s session logic must reside on the server, in the session object or storage. The test therefore requires two observations: which identifier the server sent to the client, and which identifier the resulting record uses. The following are acceptance tests devised for this owned test environment, rather than an official testing procedure.
First control: normal session creation
Request /demo-session without a cookie. Record the identifier the server issues through Set-Cookie and find the corresponding record in server-side storage. Then associate the synthetic marker with that record. This step confirms that the selected route actually creates an anonymous session and that the team can match the response to the server state.
Set-Cookie sends a cookie from the server to the client for subsequent requests back to the server. Browsers prevent client-side JavaScript from accessing this header, so inspect the HTTP response using a method available outside the page’s code. A successful HTTP response without a matching record does not yet confirm that the expected session was created.
Second control: repeat the request with the issued ID
Repeat the request with a cookie containing the identifier from the first step. Check server-side storage to confirm that the request continued the original anonymous session, using the same synthetic marker as your reference. This verifies the positive case against which you will compare the handling of an unknown value.
If the response includes Set-Cookie, retain it for comparison. The absence of this header does not, by itself, indicate a problem with the repeat request. The criterion for this control is observable continuation of the original session; issuing the cookie again is not required.
The main test: a preselected unknown ID
In the same owned test environment, choose a syntactically valid identifier value and confirm in advance that it is absent from storage. Send it in a cookie from a separate test client. This matters: the unknown value must be tested separately from the ID already issued by the server.
Compare the response, including Set-Cookie, with the storage state after the request. The submitted value must not become the identifier of the newly created session. Since the selected route normally creates a session, the expected result is a new server-generated ID that differs from the submitted value, with a record associated specifically with the new ID. Also verify that no record was created under the client-chosen value.
A different ID in Set-Cookie alone is insufficient: without checking storage, you cannot know what state the server actually created. Likewise, a successful HTTP status code does not show whether the server accepted the client-proposed identifier.
What to fix, and in what order
The first priority is to stop creating sessions under unknown incoming IDs. Enable or implement a strict mechanism in session handling: a value previously issued by the application may be accepted, while an unknown value must trigger the generation and issuance of a new valid identifier. Do not use the submitted unknown value as the key for a new record.
Next, check that the result is consistent: the new ID in the response must correspond to the server-side record containing the session data. After the change, repeat all three acceptance tests described here. The fix is accepted when normal creation works, the issued ID continues the original session, and the preselected unknown ID does not become the key for a new record.
Limits of the findings and the next step
The result applies to the route and configuration tested. These tests do not cover ID renewal at login, shopping cart transfer, validation of an existing session’s secret, transmission of the secret through URLs, cookie scope, session termination and revocation, session lifetimes, CSRF, JWT, or object access. These are separate requirements; passing the three scenarios does not replace testing them.
For a product owner, the practical outcome is reproducible evidence of one boundary: the server chooses the identifier for a new session. If you need help assessing a web product, CheckMyApp offers a free audit of your website or the web portion of your application.