[Security] Checkout's anonymous basket cookie path skips GUID validation (unreachable today)

Open
#334 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
Half a day
Newbie friendliness
62/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp

Research direction

Compare GetOrSetBasketCookieAndUserName() in src/Web/Pages/Basket/Checkout.cshtml.cs against the version in Pages/Basket/Index.cshtml.cs; the latter is the reference for the GUID check. Read Program.cs to confirm the [Authorize]/AuthorizePage("/Basket/Checkout") wiring that makes the anonymous branch unreachable, then decide where one shared cookie helper should live so the HttpOnly/Secure/SameSite/IsEssential flags are set in one place. Done means the dead branch is gone or consolidated with the GUID check, and a functional test under the Web functional tests asserts an anonymous request to Checkout redirects to login.

Written by the indexing model from the issue text.

Description

bug

Summary

src/Web/Pages/Basket/Checkout.cshtml.cs has its own GetOrSetBasketCookieAndUserName() for anonymous users. Unlike the version in Pages/Basket/Index.cshtml.cs, it does not check that the basket cookie value is a GUID. It uses whatever the cookie contains as the basket owner's "username". The basket cookie it creates also has no HttpOnly, Secure, SameSite or IsEssential settings.

Why it is not exploitable today

The page is [Authorize], and Program.cs also adds AuthorizePage("/Basket/Checkout"). So SetBasketModelAsync() always takes the signed-in branch and the anonymous branch never runs.

Why it is still worth fixing

If authorization on Checkout were ever relaxed (for example to support guest checkout), an anonymous attacker could set the basket cookie to a victim's email address. They could then view the victim's basket and place an order from it, which also deletes the basket. The missing GUID check is exactly what prevents this on the Basket page.

Suggested fix

  • Remove the unreachable anonymous branch from Checkout, or share one helper with Basket/Index that includes the GUID check.
  • Give the basket cookie HttpOnly = true, Secure = true, SameSite = Lax and IsEssential = true, in one place.
  • Add a functional test that an anonymous request to Checkout redirects to login, so the protection this relies on is covered.
Dominant language
C#
Stars
643
Forks
329
Avg merge
1h 48m
Merged PRs (30d)
21

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NimblePros/eShopOnWeb

All issues in NimblePros/eShopOnWeb

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.