Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a quiz item about http only cookies to how clerk works #2097

Merged
merged 6 commits into from
Mar 25, 2025

Conversation

jescalan
Copy link
Contributor

@jescalan jescalan commented Mar 11, 2025

🔎 Previews:

What does this solve?

We sometimes get folks asking about why the session cookie is not HttpOnly, or feeling like it's a security issue. Wanted to add this section to add some context and clarity on this topic.

What changed?

I added a section that clarified it.

Checklist

  • I have clicked on "Files changed" and performed a thorough self-review
  • I have added the "deploy-preview" label and added the preview link(s) to this PR description
  • All existing checks pass

@jescalan jescalan requested a review from a team as a code owner March 11, 2025 23:48
Copy link

Hey, here’s your docs preview: https://clerk.com/docs/pr/2097

@alexisintech alexisintech force-pushed the je.add-httponly-quiz branch 2 times, most recently from ae920a9 to e1a58a1 Compare March 13, 2025 18:47
@alexisintech
Copy link
Member

TIL 'exfiltrated' 😆

I've pretty much just made this entire thing more concise. I had to re-read it multiple times to grasp what you're were trying to convey, so I've organized it in a way that it's more palatable.

@alexisintech alexisintech force-pushed the je.add-httponly-quiz branch from e1a58a1 to 52f8fdc Compare March 13, 2025 18:49
@alexisintech alexisintech force-pushed the je.add-httponly-quiz branch from 52f8fdc to eb97b62 Compare March 13, 2025 18:49
Copy link
Member

@alexisintech alexisintech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its approved so if you're happy with the changes, feel free to merge 😸💖

Copy link
Contributor Author

@jescalan jescalan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a couple lil things!

@@ -270,26 +270,20 @@ For more information on the differences between development and production envir
- **HttpOnly:** No - must be able to be accessed by client-side SDKs
- **SameSite:** Lax

When your app makes a request from the frontend to your backend, if the backend is on the same origin, the `__session` cookie will automatically be sent along with the request. Your backend can then [cryptographically verify](/docs/backend-requests/manual-jwt) the session token's signature and extract the user ID and other claims.
When your app makes a request from the frontend to your backend, if the backend is on the same origin, the `__session` cookie, also referred to as the session token, will automatically be sent along with the request. Your backend can then [cryptographically verify](/docs/backend-requests/manual-jwt) the session token's signature and extract the user ID and other claims.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This edit isn't exactly accurate. The session token and session cookie are two different things - the cookie is the vehicle which contains the token. You could say "the session token is sent" or "the session cookie is sent" colloquially and those would mean the same thing - the former implying that it's sent either via cookie or header, but technically saying that the session token and cookie are the same is not true.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we refer to it as "session token" thru out the docs, and even thru out this particular doc. the quiz was written as "Why are session tokens not HttpOnly? Is this a security issue?" and technically, the session token is not HttpOnly, the session cookie is.

so shall we update this doc to be more clear according to this suggestion? or what do u think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think we should for sure - the quiz title as quoted there should for sure be corrected, thats not right!

> The drawback is that it does make the session token vulnerable to XSS attacks, since it's not `HttpOnly`. However, Clerk mitigates this risk substantially with the token's very fast expiration time of 60 seconds. In order for an XSS attack to be able to take advantage of this, the developer would need to ship a vulnerability on their site, and the attacker would need to exfiltrate users' tokens and use them to take over accounts in an average of less than 30 seconds. While this is absolutely possible for a very specific targeted attack, it's quite challenging, and extremely unlikely to be an issue for the most common type of XSS attacks, which are broad sweeps across many sites to harvest tokens, typically after a CVE is disclosed, that can take advantage of those who didn't patch their sites in time.
>
> Additionally, there are a variety of ways that session tokens can be exfiltrated outside of only XSS attacks, and Clerk's fast-expiring token provides an extra layer of protection against these attacks that are not mitigated by using the `HttpOnly` flag on a long-lived session token.
> Clerk mitigates this risk substantially by setting the session token's expiration to a very short duration of 60 seconds. For an XSS attack to succeed, the developer would need to ship a vulnerability on their site, and the attacker would need to exfiltrate users' tokens and use them to take over accounts in an average of less than 30 seconds, which is an extremely difficult scenario. Additionally, Clerk's fast-expiring token provides an extra layer of protection against other attacks that `HttpOnly` cookies alone wouldn't mitigate.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a relevant detail that was cut:

and extremely unlikely to be an issue for the most common type of XSS attacks, which are broad sweeps across many sites to harvest tokens, typically after a CVE is disclosed, that can take advantage of those who didn't patch their sites in time.

@alexisintech
Copy link
Member

@jescalan check out the updates and lmk what u think !

@jescalan
Copy link
Contributor Author

good with this let's ship!

@jescalan jescalan merged commit aa68409 into main Mar 25, 2025
6 checks passed
@jescalan jescalan deleted the je.add-httponly-quiz branch March 25, 2025 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants