question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[πŸ›] ngx-cookie-service makes CSRF challenge hard to solve

See original GitHub issue

πŸ› Bug report

Description

Sorry for the long description, but I think this is a tricky one…

Current situation

The CSRF Challenge is hard to solve in its current state, as it requires the use of seriously outdated browsers (see issue #1421) for the attack to work. While this was initially thought to be a consequence of changing cookie defaults (SameSite=Lax instead of SameSite=None) advocated by initiatives such as Incrementally Better Cookies (see #1421), the behavior cannot be attributed only to this.

Another explanation

A closer look revealed the following connection to a third-party dependency:

This resulted in a changed behavior when setting new cookies.

Role of e2e tests

As Google gradually rolled out SameSite=Lax in Chrome during the same time, the failure in the e2e test as discussed in #1421 was attributed to that rollout and not to the changed behavior of ngx-cookie-service.

Current impact on the CSRF challenge

The frontend sets the token cookie using the set method of CookieService: https://github.com/bkimminich/juice-shop/blob/e07059edd3b4ed0527add13d0dd5c8570daa3bcc/frontend/src/app/login/login.component.ts#L78

The optional SameSite parameter is not specified by the frontend, which causes ngx-cookie-service to set it to Lax before passing the call to the cookie API of the browser. The default behavior of the browser does thus not matter, as it is only considered when the value for SameSite is left unspecified.

Overall, the CSRF challenge is thus unnecessarily hard to solve, as it requires very old browser versions which do not have support for the SameSite attribute (e.g. Firefox versions < 60). In comparison, even versions of Firefox as of February 2021 still set cookies with SameSite=None by default and it should thus still be reasonably easy to solve the challenge.

Suggested solution

To make the challenge solvable with more browsers, the frontend should use a cookie library which keeps the SameSite attribute unspecified when setting the token cookie. ngx-cookie-service will always specify a value before calling the browser API and is thus not suitable. Explicitly specifying SameSite=None is not an option, as it also forces the Secure flag to be set, which breaks usage on localhost and other unencrypted deployment scenarios.

Is this a regression?

No. The issue exists since the CSRF challenge was released in Juice Shop 10.1.0.

πŸ”¬ Minimal Reproduction

  1. Verify that the browser used for the test defaults to SameSite=None, e.g. using https://samesite-sandbox.glitch.me/ - the entry for β€œCross-site?” in the first line should say β€œset”.
  2. Follow the steps for the documented challenge solution.
  3. Observe that the cookie is not sent in the request to the profile page, the challenge is not solved.

πŸ”₯ Exception or Error

The exception for missing session cookie is shown.

🌳 Your Environment

Tested with release 10.1.0 and the latest develop branch.

Additional Information

Tested with Firefox 73.3.0esr on Kali Linux.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:27 (20 by maintainers)

github_iconTop GitHub Comments

2reactions
adityaofficial10commented, Mar 5, 2021

Okay @bkimminich! I’ll come up with a PR shortly.

2reactions
bkimminichcommented, Mar 1, 2021

Hands down, this is probably the best bug report I’ve ever read in my entire professional and open source carreer… πŸ˜†

🏁 Looks like we’re looking for a slightly less security aware cookie module then! Ideas are welcome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[πŸ›] ngx-cookie-service makes CSRF challenge hard to solve
The CSRF Challenge is hard to solve in its current state, as it requires the use of seriously outdated browsers (see issue #1421)...
Read more >
How do I send cookies in a request from an Angular 2+ ...
I need to send the CSRF cookie back to Django, stored and accessed as a cookie. Note: Simply sending the CSRF in headers...
Read more >
Challenge solutions - Pwning OWASP Juice Shop
Verify that the username got changed to "CSRF" by checking the profile page. In an actual attack scenario, the attacker will try to...
Read more >
Cross-Site Request Forgery Prevention Cheat Sheet
A CSRF attack works because browser requests automatically include all cookies including session cookies. Therefore, if the user is authenticated to the site,Β ......
Read more >
What is SameSite Cookies and CSRF Protection?
CSRF stands for Cross-Site Request forgery. It allows an attacker to craft a manipulated request via an email or by other means and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found