← All articlesWeb security

Protecting web sessions: reject secrets supplied in URLs

Using a cookie to transmit a web session secret does not necessarily mean the server will refuse to accept it from a URL. The developer’s task is to verify a specific contract: one designated cookie authenticates the session, while the same valid secret in the URL does not grant access. We will look at where to enforce this rule and how to verify it using an entirely fictional account portal, your own test account and synthetic data.

Why session secrets do not belong in URLs

OWASP recommends using cookies to exchange web session identifiers and refusing to accept them through other mechanisms, such as URL parameters. Here, ‘secret’ means the identifier the application uses to authenticate the selected session. You need to check the source of that value, rather than merely confirm that a normal browser request contains a cookie.

Authentication secrets in URLs can end up in web server logs. However, a general rule against placing secrets in URLs and the contract for a particular cookie session are separate requirements. For this task, removing the parameter from visible links is insufficient: the server must stop using it to authenticate the session.

The trust boundary: where the server obtains the secret

Using cookies by default does not prove that other transmission methods are disabled. OWASP specifically highlights applications that also accepted URL parameters or automatically switched to them through URL rewriting. The check must therefore cover behavior when the cookie is absent.

Establish a clear rule for this session: the server reads the secret only from the designated cookie. A value from the URL must neither serve as a fallback source nor authenticate the user. The trust boundary lies where the source of the secret is selected: that is where reading a URL parameter to authenticate this session must be ruled out.

A fictional portal and a positive control

Imagine an entirely fictional account portal called ‘Mayak’ in your own test environment. Your own test account has a private page containing the synthetic record ‘Training order M-17’. The designated cookie is named cabinet_session, and session_id is a fictional URL parameter name that the application previously used for sessions. These names are examples only: use the names actually used by your product.

The following sequence consists of defensive checks proposed by the editorial team, not an official OWASP procedure. First, request the private page with a valid secret only in cabinet_session, with no secret in the URL. Success means receiving the expected record, ‘Training order M-17’. If the private test data does not appear, resolve the positive control first: a subsequent denial alone will not establish anything.

Testing the URL without an unnoticed cookie

Repeat the request to the same private resource, removing the Cookie header and supplying the same valid secret only in the session_id parameter. Use a parameter the application accepts or previously accepted; an arbitrary new name will not test the former mechanism. Inspect the request actually sent: the testing tool must not add a cookie automatically.

The expected result is that the private record is absent and access to the private resource is denied. The server must also avoid establishing an authenticated session based on the URL secret. If the response includes redirects or sets cookies, assess the final outcome: did the test client gain access to the portal because of the value in the URL? A successful HTTP response alone establishes neither acceptance of the secret nor compliance with the prohibition.

A control without a secret and acceptance criteria

Now request the same resource without a cookie or a secret in the URL. Private data must not be returned in either this request or the previous one. The responses do not have to match in status or text: compare access to private content and the outcome of redirects. After the negative checks, repeat the request with the original cookie to confirm that the secret is still valid.

For the tested scenario, the contract is satisfied if the cookie request displays the expected synthetic data, the request with only the URL secret neither opens the resource nor creates an authenticated session, and the request without a secret also reveals no data. The repeated positive control must display the private record again.

What to fix first

If the URL secret opens the portal, first fix how the server selects the source: read this session’s secret only from the designated cookie. Remove fallback reads from the URL parameter and disable automatic switching to URL-based session transmission when the cookie is absent. Changing links in the interface alone does not satisfy this contract.

The next priority is to repeat the entire sequence after the fix and retain it as a check of application behavior. During acceptance checks, examine private data and the actual authentication state, rather than the response code alone. Then separately check other routes you own that use the same mechanism before extending the conclusion to them.

Limits of the result and help with your web product

The result applies to the resource, parameter and transmission method tested. It does not prove that every route and URL variant rejects the secret, nor does it provide a general security guarantee. Separate API Bearer authentication falls outside this contract. Cookie settings, identifier renewal, secret storage, session termination and lifetimes, log cleanup, CSRF, CORS and access to other users’ objects are not tested here.

The practical outcome for the team is an observable contract: a valid cookie opens the private test resource, while the same secret in the URL without a cookie does not. If you need help assessing this behavior, CheckMyApp offers a free audit of your website or the web component of your product.

Sources and documentation

  1. Session Management Cheat Sheet
  2. REST Security Cheat Sheet
CheckMyApp

Check your application’s security.

Enter your web application address and email. Get a free preliminary report and choose the depth of analysis.

Check for free