Learning path · Level 11 · Tutorial 5

Compare Browser Session Storage and Transport

Compare browser session designs by separating credential format, storage, and transport, and explain which protections depend on cookie attributes and server-enforced session behavior.

  • Level: Advanced
  • Duration: 22 min
  • 8 steps
Start tutorial Back to the path
Compare Browser Session Storage and Transport

What you will go through

  1. Separate Credential Format, Storage, and Transport Separate what a credential is from where it is stored and how it travels with a request. 2 min
  2. Trace Cookie and Bearer-Header Requests Trace cookie-based and bearer-header authentication requests by identifying whether the browser or Page JavaScript attaches each credential. 3 min
  3. Identify What Secure and HttpOnly Protect Separate HTTPS cookie transport and blocked JavaScript cookie reads from the authenticated actions that injected page code can still perform. 3 min
  4. Compare Storage Against Application Requirements Compare localStorage, sessionStorage, an in-memory credential, and an HttpOnly cookie against Atlas Workspace’s reload, transport, and XSS-exposure requirements. 4 min
  5. Configure Browser-Managed Credentials in Fetch Choose fetch credentials modes for browser-managed cookies and distinguish them from explicit bearer-header transport. 3 min
  6. Check Credentialed Cross-Origin Response Access Diagnose the distinct browser and server checks that determine whether Atlas Workspace can read a credentialed cross-origin API response. 3 min
  7. Separate Local Sign-Out from Server Invalidation Distinguish local cleanup, browser credential removal, and server-enforced invalidation during logout and expiration. 3 min
  8. Recommend and Defend a Session Design Synthesize a documented session design for Atlas Workspace and defend its browser and server boundaries. 3 min

What you will learn

  • Trace how a cookie-based request and a bearer-header request carry authentication credentials.
  • Explain the protections and limitations of Secure and HttpOnly cookie attributes.
  • Compare persistent storage, in-memory storage, and HttpOnly cookies for a documented application scenario.
  • Identify the fetch and CORS requirements for reading a credentialed cross-origin response.
  • Explain why effective logout or expiration requires more than changing React state.

Before you start

  • Diagnose Request Failures and CORS Restrictions
  • Protect Sensitive Data at the Browser Boundary
  • Prevent XSS When Rendering External Content
  • Distinguish Authentication from Authorization

Step 1 of 8

Separate Credential Format, Storage, and Transport

Separate what a credential is from where it is stored and how it travels with a request.

Name the three dimensions

Three independent design dimensions

A credential is a value that connects a later request to an authenticated identity. Two common credential formats are an opaque session identifier, such as DEMO_SESSION_ID, and an access token, such as DEMO_ACCESS_TOKEN.

To describe a session design precisely, separate three independent dimensions:

  1. credential format — what the credential value represents;
  2. storage location — where it is held between uses;
  3. transport mechanism — how it is carried with a request.

Do not treat “cookies versus tokens” as a complete comparison. A cookie can carry either kind of credential.

Map each choice separately

A three-column diagram separates credential format, storage location, and transport mechanism, showing that each column has independent choices.

A session design is a combination of one choice from each column, not a single “cookie” or “token” choice.

Describe designs without shorthand

Architecture maps for Atlas Workspace

Read each row across. The same credential format can be paired with different storage locations and transport mechanisms. Likewise, a cookie is not proof that the credential format is an opaque identifier.

Three precise design descriptions

Illustrative architecture maps; later steps examine the protections and request behavior of these choices.
Credential formatStorage locationTransport mechanism
Opaque session identifier (`DEMO_SESSION_ID`)Browser cookie storeCookie
Access token (`DEMO_ACCESS_TOKEN`)In-memory credentialBearer header
Access token (`DEMO_ACCESS_TOKEN`)Browser cookie storeCookie

Example

A cookie does not define the format

These two values can use the same cookie name while representing different credential formats:

atlas_session=DEMO_SESSION_ID — the value is an opaque identifier.

atlas_session=DEMO_ACCESS_TOKEN — the value is an access token.

The server defines what a credential means. “Access token” does not imply a particular internal structure, and this tutorial does not assume one.

Practice: classify each statement

Classify the session-design statements

Match each design statement to the dimension it describes.

Tap an item and then its matching pair.

Step 2 of 8

Trace Cookie and Bearer-Header Requests

Trace cookie-based and bearer-header authentication requests by identifying whether the browser or Page JavaScript attaches each credential.

See the two request paths

Two actors can attach credentials

A credential can travel in two different ways even when it represents the same signed-in identity.

In the cookie path, the API server sends Set-Cookie; the browser accepts it into the Browser cookie store and later adds Cookie to an eligible request. In the bearer path, Page JavaScript has an accessToken value and explicitly builds an Authorization header.

The important question is: who attaches the later request header? The browser attaches Cookie; application code supplies Authorization.

Who handles each request header?

Parallel diagram showing the API server issuing a cookie that the browser later attaches, compared with Page JavaScript explicitly attaching a bearer header.

Browser-managed cookie arrows and application-supplied bearer-header arrows have different owners.

Follow a browser-managed cookie

Cookie issuance is not cookie attachment

A cookie exchange has two separate moments: issuance and later transport. The Set-Cookie response header asks the browser to store a cookie. On a later eligible request, the browser network layer adds the Cookie request header.

Page JavaScript can start a fetch, but it does not directly supply the Cookie header as an application header. The browser controls that header.

Illustrative exchange: cookie-based request

Illustrative exchange: API issues a session credential, then the browser sends it later.

http
POST /api/session HTTP/1.1
Host: api.example.test

HTTP/1.1 200 OK
Set-Cookie: atlas_session=DEMO_SESSION_ID

GET /api/me HTTP/1.1
Host: api.example.test
Cookie: atlas_session=DEMO_SESSION_ID

Tip

Trace the owner, not just the header

Treat the Cookie line as browser-managed transport. It is not evidence that Page JavaScript read the credential or manually copied it into the request.

Follow an application-supplied bearer header

Bearer headers are application-supplied

Bearer transport works differently. Before making the request, application code must have a credential value available as accessToken. It explicitly constructs the Authorization header.

Putting a value in localStorage or sessionStorage does not automatically add it to outgoing requests. Code must read a JavaScript-accessible value and supply the header. An in-memory credential also needs code to supply the header.

Bearer-header fetch

This fragment uses a dummy value so the application code can construct the request header.

javascript
const accessToken = 'DEMO_ACCESS_TOKEN';

const response = await fetch('/api/me', {
  headers: {
    Authorization: `Bearer ${accessToken}`
  }
});

Tip

Keep issuance separate from transport

This code does not demonstrate an authentication protocol. It only traces transport: Page JavaScript supplies Authorization, while the browser supplies a qualifying Cookie in the other design.

Trace both exchanges

Order the cookie exchange

Put the cookie-based events in their required order.

  1. Browser cookie store accepts the cookie.
  2. API server returns Set-Cookie for atlas_session.
  3. Browser attaches Cookie to a later eligible /api/me request.

Complete the bearer request

Complete the application-supplied request header.

javascript
const accessToken = 'DEMO_ACCESS_TOKEN';

await fetch('/api/me', {
  headers: {
    : `Bearer ${accessToken}`
  }
});

Step 3 of 8

Identify What Secure and HttpOnly Protect

Separate HTTPS cookie transport and blocked JavaScript cookie reads from the authenticated actions that injected page code can still perform.

Map the protection boundaries

Two attributes, different boundaries

Secure and HttpOnly are separate cookie attributes with separate enforcement points.

  • Secure restricts transmission of the cookie to HTTPS in these HTTPS deployment examples.
  • HttpOnly prevents Page JavaScript from reading the cookie through cookie APIs.

Neither attribute decides whether JavaScript is executing in the page. If injected JavaScript runs, it can still attempt actions as that page.

Where each protection applies

Diagram showing HttpOnly blocking JavaScript cookie reads, Secure limiting a browser-managed cookie route to HTTPS, and page JavaScript still sending a request to the API server.

HttpOnly blocks a cookie-reading route. Secure constrains the browser-managed cookie route. Neither stops code already running in the page from making requests.

Attribute comparison

The browser enforces both attributes; React state does not. They reduce particular exposure paths, but they do not make a session immune to XSS.

Cookie attributes address different boundaries.
AttributePrimary boundaryWhat it preventsWhat it does not prevent
SecureBrowser cookie transportTransmission of that cookie over non-HTTPSMalicious JavaScript running in the page
HttpOnlyPage JavaScript cookie APIsDirect reading of that cookie through cookie APIsAuthenticated requests made by injected JavaScript

Establishment and remaining XSS impact

The server establishes HttpOnly

An HttpOnly cookie is created by the API server through Set-Cookie. A React variable cannot add an equivalent protection, and document.cookie cannot create an HttpOnly cookie.

The browser processes the response header, but Set-Cookie is not a fetch response header that Page JavaScript can read. The application may receive a normal response body while the browser separately stores the cookie.

Server response

Illustrative exchange: the API server issues an HttpOnly cookie after sign-in.

http
HTTP/1.1 200 OK
Content-Type: application/json
Set-Cookie: atlas_session=DEMO_SESSION_ID; Secure; HttpOnly

{"signedIn":true}

An injected script can still act

Even though the cookie value is not readable through document.cookie or response.headers.get('Set-Cookie'), code executing in the affected page can request a protected same-origin resource. The browser can attach an eligible cookie; the code can then read data that the page is permitted to access.

javascript
const response = await fetch('/api/me', {
  credentials: 'same-origin'
});

const projectData = await response.json();

Warning

XSS remains a serious boundary failure

Treat Secure and HttpOnly as valuable, specific defenses—not as an XSS cure. Preventing injected code from running remains essential.

Check your distinction

Assess the remaining capabilities

Atlas Workspace uses an atlas_session cookie with Secure and HttpOnly. Injected JavaScript is running at https://app.example.test. Which statement is accurate?

Step 4 of 8

Compare Storage Against Application Requirements

Compare localStorage, sessionStorage, an in-memory credential, and an HttpOnly cookie against Atlas Workspace’s reload, transport, and XSS-exposure requirements.

Frame the comparison

Use storage as one comparison dimension

A session design is clearer when you separate three choices:

  • credential format: what proves the authenticated identity, such as an opaque sessionId or an accessToken.
  • storage location: where the browser or page keeps that credential.
  • transport mechanism: how it reaches the API on a protected request.

Storage does not determine format or transport. For example, an opaque sessionId can be stored in an HttpOnly cookie and sent by the browser, while an accessToken in localStorage must be read by Page JavaScript before application code supplies a bearer header.

Storage and transport are separate choices

Diagram separating Page JavaScript, Browser cookie store, and API server. JavaScript storage locations feed an application-supplied bearer header, while an HttpOnly cookie is sent through a browser-managed Cookie header.

The arrows show transport mechanism; the places holding the credential show storage location.

Compare lifetime, continuity, and transport

Storage comparison for Atlas Workspace

Compare candidates against the requirements rather than treating “cookies versus tokens” as a complete architecture decision.

Browser retention is not the same as server-enforced credential validity.
Storage locationScript readable?Browser retentionReload continuityTransport mechanism
localStorageYesUsually persists until cleared or browser policyYesApp reads it and supplies a bearer header
sessionStorageYesCurrent page sessionYes, while that page session remainsApp reads it and supplies a bearer header
in-memory credentialYesOnly while current page runsNormally noApp supplies a bearer header
HttpOnly cookieNo, through cookie APIsSession or persistent; depends on cookie lifetime attributes and browser behaviorYes, if retainedBrowser attaches Cookie when eligible

Read the distinctions precisely

localStorage and sessionStorage are Web Storage APIs, not server sessions. sessionStorage survives a reload during its page session, but it is normally removed when that page session ends.

An in-memory credential reduces how long a JavaScript-readable value remains stored, but a reload normally loses it. Restoring sign-in then needs an additional design decision.

An HttpOnly cookie is not automatically persistent. HttpOnly controls JavaScript cookie access; cookie lifetime attributes and browser behavior govern retention. In every row, the API separately decides whether it accepts the presented credential.

Make a conditional recommendation

Example

Apply the requirements, not a slogan

Atlas Workspace displays private project data and must preserve sign-in across reloads. Its cooperating API team makes a browser-managed session design a defensible candidate: store an opaque sessionId in an HttpOnly cookie and let the browser use the Cookie transport mechanism for eligible requests.

This can provide reload continuity when the cookie’s lifetime is configured to retain it. It also keeps the credential from direct reads through JavaScript cookie APIs. It is a trade-off, not a universal winner: it depends on API support and cookie rules, and it does not decide the credential’s format by itself.

Tip

Keep the XSS residual risk visible

Persistent JavaScript-readable credentials in localStorage or sessionStorage create more opportunity for direct credential theft if malicious code runs in the page. An in-memory credential reduces persistence, but active injected JavaScript can still use values available to it.

HttpOnly reduces direct cookie theft through cookie APIs. It does not make Atlas Workspace immune to injected JavaScript: compromised Page JavaScript can still attempt authenticated actions as the current page and may access data returned to that page.

Practice: justify the trade-off

Defend a storage choice

For Atlas Workspace, choose one storage candidate and write 3–5 sentences. State one benefit, one limitation, and the residual risk if active injected JavaScript runs in the page. Also explain why sessionStorage is not a server-session mechanism.

Write at least 220 characters (0/220).

Step 5 of 8

Configure Browser-Managed Credentials in Fetch

Choose fetch credentials modes for browser-managed cookies and distinguish them from explicit bearer-header transport.

Set the permission for browser-managed cookies

Credentials mode controls browser behavior

fetch has a credentials mode for browser-managed credentials such as cookies. It is a transport setting—not a credential format or storage location.

By default, fetch uses credentials: 'same-origin'. That allows the browser to attach eligible cookies to a same-origin request. For a cross-origin request, use credentials: 'include' when the request is intended to permit eligible browser-managed cookies.

The mode also affects whether the browser respects a Set-Cookie response. It never reads an access token from JavaScript storage or creates an Authorization header for you.

Who supplies a browser-managed credential?

Two request diagrams show the browser cookie store adding an eligible cookie, while a separate arrow represents an application-supplied bearer header.

A credentials mode permits browser-managed cookie behavior; it does not turn application data into a bearer header.

Tip

Keep these outcomes separate

credentials: 'include' is permission, not a guarantee. A cookie must exist and be eligible under the browser's cookie rules before it can be attached. Also, cookie attachment does not by itself prove that page JavaScript can read the response; cross-origin response access is a separate check covered next.

Compare the three modes

Same-origin request

For a same-origin protected read, the default mode is already suitable for browser-managed cookies. Writing it explicitly can make the request policy easier to review.

Same-origin cookie request

Illustrative same-origin fetch from https://app.example.test.

javascript
const response = await fetch('/api/me', {
  credentials: 'same-origin'
});

Cross-origin request

For the cross-origin API, select include when the design permits the browser to send eligible cookies. This still does not promise that a cookie exists, qualifies for the request, or that the response will be readable by page JavaScript.

Cross-origin cookie request

Illustrative cross-origin fetch from https://app.example.test.

javascript
const response = await fetch('https://api.example.test/api/me', {
  credentials: 'include'
});

Fetch credentials modes

The mode concerns browser-managed credentials and Set-Cookie handling. It is not a shortcut for supplying an access token.

Cookie eligibility remains a separate browser decision.
ModeCookie behaviorSet-Cookie handling
'same-origin'Permits eligible cookies only for same-origin requestsRespected for same-origin responses
'include'Permits eligible cookies for same- or cross-origin requestsMay be respected when other browser rules allow it
'omit'Excludes browser-managed credentialsSet-Cookie is not respected

Do not confuse cookie permission with header construction

Bearer headers are independent of credentials mode

A bearer header is application-supplied transport. Your code must already have an accessToken value and explicitly place it in Authorization.

credentials: 'omit' excludes browser-managed credentials such as cookies. It does not remove an Authorization header that the application explicitly supplies. Likewise, changing the mode does not retrieve a value from localStorage, sessionStorage, or an in-memory credential.

Explicit bearer header with browser credentials omitted

Illustrative exchange: the constructed request header is Authorization: Bearer DEMO_ACCESS_TOKEN.

javascript
const accessToken = 'DEMO_ACCESS_TOKEN';

const response = await fetch('https://api.example.test/api/me', {
  credentials: 'omit',
  headers: {
    Authorization: `Bearer ${accessToken}`
  }
});

Tip

Review rule

Use omit when you intend to exclude browser-managed cookies. It is not a security cleanup operation for headers your code has already added.

Apply the transport choices

Configure and predict credential handling

Match each request goal to its fetch configuration and credential handling. Assume atlas_session exists and is eligible wherever a cookie is mentioned. Ignore cross-origin response-readability requirements for this activity.

Tap an item and then its matching pair.

Step 6 of 8

Check Credentialed Cross-Origin Response Access

Diagnose the distinct browser and server checks that determine whether Atlas Workspace can read a credentialed cross-origin API response.

Read a credentialed cookie response

A readable cross-origin cookie response

A cross-origin cookie request has two separate browser decisions. First, credentials: 'include' permits eligible browser-managed credentials to travel with the request. Second, the API response must explicitly grant https://app.example.test permission to read it.

For Atlas Workspace, a response to https://api.example.test/api/me is readable by page JavaScript only when it names the requesting origin and sends Access-Control-Allow-Credentials: true. Access-Control-Allow-Origin: * cannot grant readable response access when the request uses credentials: 'include'.

Two independent checks

Diagram showing Page JavaScript initiating a request, Browser cookie store conditionally supplying a cookie, and API server response permission as a separate CORS check.

CORS controls whether the page can read a cross-origin response. Cookie eligibility separately controls whether the browser attaches a cookie.

Cross-origin fetch

Atlas Workspace explicitly permits browser-managed credentials for this cross-origin request.

javascript
const response = await fetch('https://api.example.test/api/me', {
  credentials: 'include'
});

Cookie request and response

This is an illustrative exchange in which an eligible atlas_session cookie is attached and the response is readable by the page.

http
Illustrative exchange

GET /api/me HTTP/1.1
Host: api.example.test
Origin: https://app.example.test
Cookie: atlas_session=DEMO_SESSION_ID

HTTP/1.1 200 OK
Content-Type: application/json
Access-Control-Allow-Origin: https://app.example.test
Access-Control-Allow-Credentials: true

{ "projectCount": 4 }

Separate CORS permission from transport

Bearer headers are application-supplied

CORS permission is not cookie attachment. The response headers can allow page JavaScript to read a response, but they do not create a cookie or force an existing cookie to be eligible for the request. Conversely, an eligible cookie does not make a cross-origin response readable without the required CORS permission.

A bearer-header request uses a different transport mechanism: application code supplies Authorization. It can use credentials: 'omit'; that setting excludes browser-managed credentials but does not remove an Authorization header that the application explicitly supplies.

Bearer-header fetch

The bearer credential is available to application code, so the application constructs the header itself.

javascript
const accessToken = 'DEMO_ACCESS_TOKEN';

const response = await fetch('https://api.example.test/api/me', {
  headers: {
    Authorization: `Bearer ${accessToken}`
  },
  credentials: 'omit'
});

Authorization preflight

Authorization requires preflight permission. A browser may reuse a previously cached successful preflight, but the API must permit the header for the request to proceed under that permission.

http
Illustrative exchange

OPTIONS /api/me HTTP/1.1
Host: api.example.test
Origin: https://app.example.test
Access-Control-Request-Method: GET
Access-Control-Request-Headers: authorization

HTTP/1.1 204 No Content
Access-Control-Allow-Origin: https://app.example.test
Access-Control-Allow-Methods: GET
Access-Control-Allow-Headers: Authorization

GET /api/me HTTP/1.1
Host: api.example.test
Origin: https://app.example.test
Authorization: Bearer DEMO_ACCESS_TOKEN

Warning

Do not infer server-side outcome from one browser error

A CORS error is not, by itself, proof that the protected request did not reach the API server. A denied preflight prevents the corresponding actual request. But if a request was sent and its response fails a CORS response check, the server may have processed it while page JavaScript is still unable to read the response.

Check the response headers

Complete the credentialed response

Complete the two response-header values so page JavaScript at https://app.example.test can read this response to a cross-origin request using credentials: 'include'.

http
Illustrative exchange

HTTP/1.1 200 OK
Content-Type: application/json
Access-Control-Allow-Origin: 
Access-Control-Allow-Credentials: 

{ "projectCount": 4 }

Diagnose the failed condition

Classify cross-origin failures

Match each Atlas Workspace case to its primary diagnosis.

Tap an item and then its matching pair.

Step 7 of 8

Separate Local Sign-Out from Server Invalidation

Distinguish local cleanup, browser credential removal, and server-enforced invalidation during logout and expiration.

Separate the boundaries

Logout is not one switch

A logout flow has effects at different boundaries. Clearing React state, redirecting away from a private route, or clearing a JavaScript-held credential changes what the current page can do. That is local cleanup.

Local cleanup does not alter another copy of a credential and does not change the API server’s decision about whether that credential is valid. A client-side expiry timer is also interface behavior: it can sign this page out, but it is not the boundary that makes the API reject a request.

Browser credential removal changes browser retention. Server enforcement occurs when the API processes a protected request such as /api/me and rejects an expired or invalidated credential.

Three separate boundaries

Diagram separating Page JavaScript local cleanup, Browser cookie store removal, and API server rejection of a copied credential.

A page-state change, browser removal, and API acceptance are separate effects.

Combine browser removal with API enforcement

How an HttpOnly cookie can disappear

Page JavaScript cannot directly delete an HttpOnly cookie through cookie APIs. For application-directed logout, Atlas Workspace normally calls /api/logout; a successful API response can direct the browser to remove the cookie with an expiring Set-Cookie header.

The deletion must match the cookie identity and scope used when it was set, including its name and Path, plus Domain when applicable. An HttpOnly cookie can also disappear because its cookie lifetime expires, the browser evicts data, or the user clears site data. None of those browser events alone proves that the API has invalidated the credential.

Server-directed browser removal

Illustrative exchange: the API performs its defined invalidation behavior and directs the browser to remove the matching cookie.

http
Illustrative exchange

POST /api/logout HTTP/1.1
Host: api.example.test
Cookie: atlas_session=DEMO_SESSION_ID

HTTP/1.1 204 No Content
Set-Cookie: atlas_session=; Max-Age=0; Path=/; Secure; HttpOnly

Tip

Removal is not invalidation

Max-Age=0 directs the browser to remove its stored cookie. It does not, by itself, establish that the API will reject a copied DEMO_SESSION_ID.

Keep these controls distinct: cookie lifetime governs browser retention; server-enforced credential validity governs whether the API accepts a presented credential. A token design may continue accepting an issued credential until its expiry unless its API defines and successfully performs a revocation mechanism.

What each action accomplishes

Each row describes the primary effect of one action by itself.

Browser retention and API acceptance are independent checks.
ActionPrimary resultMakes the API reject a credential by itself?
Set React user state to signed outLocal cleanupNo
Client expiry timer firesInterface behaviorNo
Matching Set-Cookie with Max-Age=0Browser credential removalNo
Cookie lifetime expires or site data is clearedBrowser credential removalNo
API rejects expired or invalidated credential on /api/meServer enforcementYes

Assess a logout outcome

Evaluate the evidence

Atlas Workspace clears its React state after sending /api/logout, but the request fails before the application receives a response. Which conclusion is justified?

Failed logout request

Choose the justified conclusion.

Apply the logout model

Classify the logout boundaries

Classify these Atlas Workspace actions as local cleanup, browser credential removal, or server enforcement: (1) setting the React user state to signed out, (2) processing a matching Set-Cookie response with Max-Age=0, and (3) rejecting an invalidated credential during /api/me.

Then explain why a copied credential may still work after only React state is cleared, and why a failed /api/logout request cannot confirm revocation.

Write at least 220 characters (0/220).

Step 8 of 8

Recommend and Defend a Session Design

Synthesize a documented session design for Atlas Workspace and defend its browser and server boundaries.

Choose a coherent baseline

A recommendation is a set of separate choices

Atlas Workspace needs private project data, sign-in continuity after reload, a cooperating cross-origin API, and server-confirmed logout. A defensible baseline is an opaque session identifier as the credential format, kept in a retained HttpOnly cookie as the storage location, and sent through the browser-managed Cookie header as the transport mechanism.

This reduces direct credential copying by injected JavaScript compared with a JavaScript-readable persistent credential. It does not make XSS harmless: injected code can still act as the signed-in page, issue eligible requests, and read responses that the compromised page is allowed to read. The API server remains responsible for credential validity and authorization.

Who handles the recommended credential?

Diagram showing Page JavaScript, Browser cookie store, and API server. The browser cookie store sends the recommended Cookie header, while Page JavaScript would supply a bearer header only in an alternative design.

Browser-managed cookie transport differs from an application-supplied bearer header, even when both credentials represent an authenticated identity.

State the request, response, and lifecycle conditions

Atlas Workspace decision map

The comparison is not “cookies versus tokens.” It records the credential format, storage location, and transport mechanism, then adds the browser and server conditions that make the design work.

A documented design makes each responsibility explicit.
Decision dimensionRecommended designAlternative or required consequence
Credential formatOpaque session identifierAccess token is a credible alternative
Storage locationRetained HttpOnly cookielocalStorage is JavaScript-readable
Transport mechanismBrowser-managed CookieJavaScript must add Authorization for bearer transport
Cross-origin requestcredentials: 'include'Permits eligible browser-managed cookies; does not guarantee one is sent
Readable API responseExplicit origin and credential permissionAccess-Control-Allow-Origin names app origin; Access-Control-Allow-Credentials is true
Cookie protectionsSecure and HttpOnlySecure restricts HTTPS transmission; HttpOnly blocks direct JavaScript cookie reads
Logout cleanupSet-Cookie with Max-Age=0Matching cookie identity and scope remove the browser copy
Validity decisionAPI server expires or invalidates sessionReact state and cookie removal do not revoke a copied valid credential

Example

Trace the protected read and logout

Illustrative exchange

POST /api/session HTTP/1.1
Host: api.example.test
Origin: https://app.example.test

HTTP/1.1 200 OK
Set-Cookie: atlas_session=DEMO_SESSION_ID; Path=/; Secure; HttpOnly

GET /api/me HTTP/1.1
Host: api.example.test
Origin: https://app.example.test
Cookie: atlas_session=DEMO_SESSION_ID

HTTP/1.1 200 OK
Access-Control-Allow-Origin: https://app.example.test
Access-Control-Allow-Credentials: true

POST /api/logout HTTP/1.1
Host: api.example.test
Cookie: atlas_session=DEMO_SESSION_ID

HTTP/1.1 200 OK
Set-Cookie: atlas_session=; Path=/; Max-Age=0; Secure; HttpOnly

Tip

Keep the boundaries separate

Cookie eligibility and CORS are separate browser decisions. credentials: 'include' allows eligible browser-managed credentials on the cross-origin call. The explicit CORS response headers allow Page JavaScript to read the response. Neither condition forces a cookie to exist, and neither substitutes for API-server validation.

Warning

Scope boundary for the next tutorial

Cookie-based authentication also needs separate request-forgery analysis. This tutorial has not covered those defenses; the next tutorial addresses them. Include that boundary in a design review rather than assuming that Secure, HttpOnly, CORS, or server-confirmed logout solves every request-forgery concern.

Final application

Defend the design

Write a concise session-design recommendation for Atlas Workspace. Include all of the following:

  • the credential format, storage location, and transport mechanism you recommend;
  • one credible alternative and its trade-off for reload continuity and direct credential exposure to injected JavaScript;
  • a trace of one protected https://api.example.test/api/me request, including who attaches the credential;
  • the applicable Secure and HttpOnly protections and one XSS limitation that remains;
  • the cross-origin fetch and response-access requirements;
  • how cookie lifetime differs from server-enforced credential validity, and how server-confirmed logout handles both invalidation and browser cleanup;
  • the separate request-forgery-analysis boundary introduced on the previous screen.

Use Atlas Workspace and the documented origins and endpoints in your recommendation.

Write at least 700 characters (0/700).

Close the recommendation

Summary

Design-review checklist

  • Describe a session design with the independent dimensions: credential format, storage location, and transport mechanism.
  • For Atlas Workspace, an opaque session identifier in a retained HttpOnly cookie is a defensible baseline when the browser manages the Cookie transport and the API server controls validity.
  • Secure restricts cookie transmission to HTTPS, while HttpOnly prevents direct JavaScript cookie reads. Neither prevents authenticated actions by injected JavaScript.
  • For a readable credentialed cross-origin response, use credentials: 'include' and an API response with the explicit application origin plus Access-Control-Allow-Credentials: true.
  • Cookie lifetime controls browser retention. The API server must enforce expiration and logout invalidation; browser deletion with Max-Age=0 is a separate cleanup action.
  • Cookie-based authentication also needs separate request-forgery analysis, addressed in the next tutorial.

Tutorial complete

Congratulations! You completed: Compare Browser Session Storage and Transport

You can now compare browser session designs by tracing credentials across storage, transport, browser protections, CORS access, and server-enforced lifecycle behavior.

100 XP

Download the App now to have access to + 5000 free courses, exercises, certificates and lots of content without paying anything!

  • 100% free online courses from start to finish

    Thousands of online courses in video, ebooks and audiobooks.

  • More than 60 thousand free exercises

    To test your knowledge during online courses

  • Valid free Digital Certificate with QR Code

    Generated directly from your cell phone's photo gallery and sent to your email

Cursa app on the ebook screen, the video course screen and the course exercises screen, plus the course completion certificate