TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: How authentication works at HN?

5 pointsby abhas9over 8 years ago
Whenever I upvote a story, HN sends a request of type: `vote?id=12390292&amp;how=up&amp;auth=XXX` `XXX` is different for each story in the page.<p>I checked the cookies using dev tools. There is a cookie called user whose value is &lt;myusername&gt;&amp;[YYYY]<p>Here `YYYY` is a different token. Can anyone explain what is going on with all these tokens and why are they all different?<p>PS: Inspired by http:&#x2F;&#x2F;blog.watchandcode.com&#x2F;2016&#x2F;03&#x2F;17&#x2F;the-single-piece-of-javascript-on-hacker-news&#x2F;

1 comment

niftichover 8 years ago
For a voting URL, you want some value that the server can calculate based on info it has, and that&#x27;s sufficiently large to not be brute-forceable, and sufficiently unpredictable to not be enumerable. They are &#x27;capability URLs&#x27; [1] like a private Google Docs link, or a &#x27;click here to reset your password&#x27; token. So &#x27;auth&#x27; parameter in the URL is likely the output of a deterministic function of the user and a server-side secret, and possibly a time factor; you can accomplish this with an HMAC.<p>HOTP [2] and TOTP [3] are two concrete schemes that use this method and truncate to a human-friendly size at the end to use it as part of a challenge-response, but you don&#x27;t want to truncate this here because then the range of values would be brute-forceable. So it&#x27;s likely just the output of a LARGE-HMAC(secret-key, MixingFunction(user, timewindow)). Or, if time isn&#x27;t present, then LARGE-HMAC(secret-key, user).<p>Since the voting URLs are server-generated, the Cookie value must be unrelated. Logging in with a web browser, copying the cookie, and mimicking the same cookies with curl, I&#x27;m logged in with curl, but changing either my username or my token I&#x27;m not logged in. The opaque value in the cookie is consistent with what you&#x27;d expect from a Session ID, which is not surprising. I&#x27;m speculating, but the addition of the username may serve as a countermeasure against session guessing attacks (like, being able to quickly distinguish a tampered Session ID from a good one, like these other apps try to [4][5]), or may simply be an implementation detail.<p>[1] <a href="https:&#x2F;&#x2F;www.w3.org&#x2F;TR&#x2F;capability-urls&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.w3.org&#x2F;TR&#x2F;capability-urls&#x2F;</a><p>[2] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;HMAC-based_One-time_Password_Algorithm" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;HMAC-based_One-time_Password_A...</a><p>[3] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Time-based_One-time_Password_Algorithm" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Time-based_One-time_Password_A...</a><p>[4] <a href="http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;18751565&#x2F;detecting-rails-4-session-cookie-tampering" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;18751565&#x2F;detecting-rails-...</a><p>[5] <a href="https:&#x2F;&#x2F;github.com&#x2F;expressjs&#x2F;session&#x2F;issues&#x2F;176" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;expressjs&#x2F;session&#x2F;issues&#x2F;176</a>
评论 #12392831 未加载