Skip to content
Subdomain takeover Write-up Intermediate

CafeBazaar and Subdomain Takeover

A dangling CNAME record pointed a Cafe Bazaar subdomain to a third-party form-building service where the account had been deleted, allowing anyone to re-register that account and take over the subdomain. The attacker could then host content on the trusted subdomain, potentially read cookies, phish users, or chain with an open redirect for account takeover.

Sina Kheirkhah Follow

Published on sinsinology.medium.com

{{media:0}}

Sina Kheirkhah (SinSin), on sinsinology.medium.com

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. 6 min read.

Context

Cafe Bazaar is an Iranian Android marketplace founded in April 2011; in April 2019 it announced it had surpassed 40 million users. This write-up is about a subdomain takeover on a Cafe Bazaar subdomain, and about how the researcher turned a dangling DNS record into something he could demonstrate as critical.

The feature at the centre of it is a temporary survey campaign. The organisation wants a feedback form and does not want to build one, so it uses a third-party form builder. The form builder gives each customer a subdomain of its own domain: if the form builder is formmakers.com and the customer picks the username cafebazaar, the form lives at cafebazaar.formmakers.com. The customer then points a subdomain of its own domain at that host with a CNAME record, so that users who visit form.cafebazaar.ir see the form builder's content while the browser address bar keeps showing form.cafebazaar.ir. That keeps the organisation's branding and credibility in search results and in front of users.

A CNAME (Canonical Name) record is a DNS pointer from one name to another. The important property, and the one the whole attack rests on, is that it is not an HTTP redirect: the content is served by the target host, but the name in the address bar remains the source domain.

Setup

The researcher's preconditions were simple: the ability to query DNS for the Cafe Bazaar zone, and the ability to register an account on the third-party form builder. No credentials for Cafe Bazaar itself were needed. The write-up uses formmakers.com and the example hostnames throughout.

Finding it

The campaign ends. Cafe Bazaar deletes its account on the form builder, but the CNAME record on its own DNS server is left in place, still pointing at cafebazaar.formmakers.com. From then on, anyone visiting form.cafebazaar.ir gets an error from the form builder saying there is no such form-building account, and the form builder states that no domain such as cafebazaar.formmakers.com exists.

That error message is the finding. If the form builder says the account does not exist, the account name is free, and anyone can register it. The DNS record on the Cafe Bazaar side still delegates the name to that host, so whoever registers the account inherits form.cafebazaar.ir.

Exploitation

Step 1: read the CNAME to learn the destination name

To register the right account, the attacker needs the exact name the source domain points at. The researcher queried the CNAME record for the Cafe Bazaar subdomain and read its value.

The write-up does not print the query or the raw answer. What it establishes is the value: the source domain points at cafebazaar.formmakers.com.

Step 2: register the dangling name

With the destination name known, the researcher registered on the form builder and chose cafebazaar as the username, exactly as the original customer had. The form builder then handed him cafebazaar.formmakers.com. The write-up shows the registration step and the settings page where the target domain is applied.

Step 3: confirm the takeover

The attacker does not need to hand out cafebazaar.formmakers.com to anybody. Because the Cafe Bazaar DNS server still holds the old CNAME record, and that record's value is form.cafebazaar.ir, the attacker now controls form.cafebazaar.ir as well. The write-up attributes the whole thing to a misconfiguration on the DNS server: the record outlived the account it pointed to.

Step 4: get JavaScript execution on the taken-over host

Owning the name is not enough on its own. To read cookies belonging to other subdomains and to chain into the other risks, the attacker needs to run JavaScript on the acquired domain. The form builder did not let JavaScript into the form, so the researcher went looking for XSS in the form builder itself.

He found five reflected XSS vulnerabilities over three days, but rejected them: each needed a crafted link to be sent to a victim, which made the issue low severity, and he did not want to depend on user interaction. On day seven, after hours of testing, he found a stored XSS vulnerability, which he describes as where the vulnerability was at its highest, critical.

The write-up does not give the payloads, the parameters or the affected pages for any of these XSS findings.

Step 5: get past the scope objection

He reported the issue to the Cafe Bazaar team. Initially they said the vulnerability was out of scope. Rather than stopping, he went back to the programme's in-scope list and made the argument from the DNS side: the flaw was not in the form.cafebazaar.ir application, it was in the old DNS record, and that record had to be fixed. He also showed that the DNS server for Cafe Bazaar sits in the programme's in-scope IP range. The write-up does not reproduce the ranges or the list text.

After that information was sent, the report was approved and rewarded.

Root cause

The mistake is a dangling CNAME. When the campaign ended, the account on the third-party form builder was deleted, but the CNAME record pointing at it was not. DNS kept advertising the delegation, and the third-party service treated the freed name as available to anyone. Neither side had a check that the other still existed.

The existing defences did not help. The form builder's own error message, which openly states that the account does not exist, is what tells an attacker the name is claimable. The scope process initially treated the issue as out of scope.

Impact

Once the subdomain is controlled, the write-up lists the following consequences, with its own hedges:

  1. Cookie theft across subdomains. Per the browser cookie standard RFC6265, cookies set on a domain are sent to its subdomains, and subdomains can read them, in certain conditions. The write-up claims the ability to read HTTPOnly cookies from JavaScript and to read secure cookies because the acquired domain has SSL, noting that access to incoming HTTP requests would require local file read or even RCE.
  2. Collecting user information through a survey form served from the trusted domain form.cafebazaar.ir.
  3. Open redirect chaining. Cafe Bazaar has a whitelist that allows redirects to YYY.cafebazaar.ir subdomains; with form.cafebazaar.ir acquired, the attacker can substitute it for YYY and, following the OAuth mechanism implemented in CafeBazaar, start an account takeover.
  4. Distributing malicious applications through the largest Android app marketplace, from the trusted domain form.cafebazaar.ir.
  5. Spreading false news and damaging the credibility of the trusted domain.

The write-up also states the general point that a subdomain takeover compromises the main domain and all subdomains of an organisation, with the qualifier "kind of".

Fix

The write-up says the vulnerability is now patched. The fix it argues for is on the DNS side: the old DNS record had to be fixed, because the flaw was in that record and not in the form.cafebazaar.ir application. It does not describe any change on the form builder side.

Variants to test

  • Enumerate CNAME records across a target's zone and resolve each target. A positive result is a CNAME whose destination returns a provider error saying the name or account does not exist, as the form builder did here.
  • Check third-party services that hand out per-customer subdomains: form builders, survey tools, status pages, documentation hosts, marketing landing pages. A positive result is a freed name that can be registered by anyone while the customer's CNAME still points at it.
  • After claiming a name, test whether the acquired host can serve JavaScript. A positive result is stored XSS in the third-party application, which the researcher sought to make the takeover critical.
  • Look for redirect whitelists that accept *.target.tld and for OAuth flows that trust any subdomain. A positive result is a redirect or token issued to the acquired subdomain.
  • When a programme rejects a DNS finding as out of scope, check whether the authoritative name servers fall inside the programme's in-scope IP ranges, as the researcher did here.

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. 14 min read.

What happened, in plain words

Cafe Bazaar is an Iranian Android app marketplace, founded in April 2011. In April 2019 it announced it had passed 40 million users. This is the story of a bug found on one of its subdomains, and of how the researcher turned a small leftover setting into something serious enough to be rewarded.

Before any of the technical words, here is the shape of the story. A company can borrow a web page from another company instead of building it. When it stops using that borrowed page, it is supposed to clean up two things: the account at the other company, and a small pointer in its own address system. Cafe Bazaar cleaned up the first and forgot the second. Because of that, a stranger could claim the borrowed name and, through it, take control of a Cafe Bazaar address that users trust.

Everything below explains, from zero, what each of those pieces means, what the researcher did, and why.

The feature at the centre: a borrowed survey form

Cafe Bazaar wanted to run a temporary campaign to collect feedback from users. It did not want to build a survey form itself, so it used a third-party form builder: a website where you sign up, design a form with ready-made templates, and publish it.

Think of it like renting a stall in a shopping centre instead of building your own shop. The stall is yours to use, but it sits inside someone else's building, and the building owner gives you an address inside their building.

The form builder gives every customer a subdomain of its own domain. A subdomain is a name that sits to the left of a main domain name, separated by a dot: in mail.example.com, mail is the subdomain and example.com is the main domain. If the form builder's domain is formmakers.com and a customer picks the username cafebazaar, the form lives at cafebazaar.formmakers.com.

That address is ugly and does not look like Cafe Bazaar. So Cafe Bazaar points one of its own subdomains at it, using a DNS record called a CNAME. Visitors who type form.cafebazaar.ir see the form builder's content, but the address bar keeps showing form.cafebazaar.ir. That keeps the organisation's branding, and it helps in search results and in front of users, who trust a name that belongs to the company they know.

DNS and the CNAME record, explained from scratch

DNS stands for Domain Name System. It is the internet's phone book. Humans type names like cafebazaar.ir; computers talk to each other using numeric addresses. DNS translates one into the other, and it also stores other kinds of entries, called records.

A CNAME (Canonical Name) record is a pointer from one name to another. It says: "whoever asks for this name, send them to that other name instead." It is like a note on a door saying "I have moved, please go to this other address".

The property the whole attack rests on is that a CNAME is not the same as an HTTP redirect. An HTTP redirect is a message from a web server telling your browser "the page is over there, go and load it", and your browser then changes the address bar to the new place. A CNAME works one level lower, in DNS: your browser never learns that another name is involved. The content is served by the target host, but the name in the address bar stays the source domain. That is exactly why companies use it for branding.

Setup: what the researcher needed before starting

The preconditions were simple:

  1. The ability to query DNS for the Cafe Bazaar zone, meaning to ask the phone book what records exist for its names. Anyone can do this; there are free tools and websites for it.
  2. The ability to register an account on the third-party form builder, like signing up for any website.

No credentials for Cafe Bazaar itself were needed. The write-up uses formmakers.com and the example hostnames throughout.

Finding it: the error message that gives the game away

The campaign ends. Cafe Bazaar deletes its account on the form builder, but the CNAME record on its own DNS server is left in place, still pointing at cafebazaar.formmakers.com.

From then on, anyone visiting form.cafebazaar.ir gets an error from the form builder saying there is no such form-building account, and the form builder states that no domain such as cafebazaar.formmakers.com exists.

That error message is the finding. If the form builder says the account does not exist, the account name is free, and anyone can register it. The DNS record on the Cafe Bazaar side still delegates the name to that host, so whoever registers the account inherits form.cafebazaar.ir.

This class of bug is called subdomain takeover. The word takeover is literal: someone else takes over a name that still belongs, on paper, to the original organisation. The write-up describes it as registering a non-existent domain to acquire all existing domains, and says that if this vulnerability is found, the main domain as well as all subdomains of an organisation will be compromised, with the qualifier "kind of".

Exploitation, step by step

Step 1: read the CNAME to learn the destination name

To register the right account, the attacker needs the exact name the source domain points at. Guessing is not good enough: the form builder may have thousands of customers, and the freed name has to match exactly.

The researcher queried the CNAME record for the Cafe Bazaar subdomain and read its value. The write-up does not print the query or the raw answer. What it establishes is the value: the source domain points at cafebazaar.formmakers.com.

Why this step matters: the CNAME value is the name you have to claim. Without it you are just hoping.

Step 2: register the dangling name

With the destination name known, the researcher registered on the form builder and chose cafebazaar as the username, exactly as the original customer had. The form builder then handed him cafebazaar.formmakers.com.

The write-up shows the registration step and the settings page where the target domain is applied.

Why this works: the form builder has no way of knowing that the person signing up is not the original customer. The name was released when the old account was deleted, and the service treats a freed name as available to anyone, first come first served.

Step 3: confirm the takeover

The attacker does not need to hand out cafebazaar.formmakers.com to anybody. Because the Cafe Bazaar DNS server still holds the old CNAME record, and that record's value is form.cafebazaar.ir, the attacker now controls form.cafebazaar.ir as well.

The write-up attributes the whole thing to a misconfiguration on the DNS server: the record outlived the account it pointed to. A misconfiguration simply means a setting that was left in a state that causes harm, here a pointer that was never removed.

Step 4: get JavaScript execution on the taken-over host

Owning the name is not enough on its own. To read cookies belonging to other subdomains and to chain into the other risks, the attacker needs to run JavaScript on the acquired domain.

JavaScript is the programming language that runs inside your browser and makes pages interactive. If an attacker can make a page run JavaScript that the attacker wrote, that code runs with the trust of the site it is on: it can read what the site can read, and act as the site can act.

XSS, short for cross-site scripting, is the vulnerability class where an attacker gets their own JavaScript into a page that other people load. There are two common flavours:

  • Reflected XSS: the malicious script travels in a link. The victim has to click the crafted link for the script to run. It is like a forged letter that only works if the recipient opens it.
  • Stored XSS: the malicious script is saved on the server, for example in a form field or a profile, and is served to anyone who later views that page. It is like writing graffiti on a wall that everyone walks past.

The form builder did not let JavaScript into the form, so the researcher went looking for XSS in the form builder itself.

He found five reflected XSS vulnerabilities over three days, but rejected them: each needed a crafted link to be sent to a victim, which made the issue low severity, and he did not want to depend on user interaction. On day seven, after hours of testing, he found a stored XSS vulnerability, which he describes as where the vulnerability was at its highest, critical.

The write-up does not give the payloads, the parameters or the affected pages for any of these XSS findings.

Why stored XSS was the one that mattered: it runs without asking the victim to click anything, and the researcher describes it as where the vulnerability was at its highest, critical.

Step 5: get past the scope objection

He reported the issue to the Cafe Bazaar team. Initially they said the vulnerability was out of scope. Scope is the list a bug bounty programme publishes saying which systems and addresses it will pay for. If your finding is not on the list, the programme can decline it, even if the bug is real.

Rather than stopping, he went back to the programme's in-scope list and made the argument from the DNS side: the flaw was not in the form.cafebazaar.ir application, it was in the old DNS record, and that record had to be fixed. He also showed that the DNS server for Cafe Bazaar sits in the programme's in-scope IP range. The write-up does not reproduce the ranges or the list text.

Why this argument works: the programme had been looking at the third-party form builder, which it does not own, and concluding the bug was not theirs. The researcher pointed at the piece Cafe Bazaar does own and does control: its own DNS records. That is the part that has to change for the bug to go away.

After that information was sent, the report was approved and rewarded.

Root cause

The mistake is a dangling CNAME. When the campaign ended, the account on the third-party form builder was deleted, but the CNAME record pointing at it was not. DNS kept advertising the delegation, and the third-party service treated the freed name as available to anyone. Neither side had a check that the other still existed.

The existing defences did not help. The form builder's own error message, which openly states that the account does not exist, is what tells an attacker the name is claimable. The scope process initially treated the issue as out of scope.

Impact: what an attacker could do with the name

Once the subdomain is controlled, the write-up lists the following consequences, with its own hedges.

First, some background on cookies, because the first item depends on them. A cookie is a small piece of data a website asks your browser to store and send back on later requests. It is how a site remembers that you are logged in: the cookie is like a wristband you get at an event, and showing it at the door proves you already checked in. HTTPOnly is a flag that tells the browser to keep a cookie away from JavaScript. Secure is a flag that tells the browser to send the cookie only over an encrypted connection.

  1. Cookie theft across subdomains. Per the browser cookie standard RFC6265, cookies set on a domain are sent to its subdomains, and subdomains can read them, in certain conditions. The write-up claims the ability to read HTTPOnly cookies from JavaScript and to read secure cookies because the acquired domain has SSL, noting that access to incoming HTTP requests would require local file read or even RCE. RCE means remote code execution: an attacker running commands on the server itself.
  2. Collecting user information through a survey form served from the trusted domain form.cafebazaar.ir. Users see a Cafe Bazaar address and type their answers into it.
  3. Open redirect chaining. An open redirect is a link on a trusted site that will send the visitor to any address an attacker puts in it. Cafe Bazaar has a whitelist that allows redirects to YYY.cafebazaar.ir subdomains; with form.cafebazaar.ir acquired, the attacker can substitute it for YYY and, following the OAuth mechanism implemented in CafeBazaar, start an account takeover. OAuth is the mechanism behind "log in with another service" buttons: a site asks a trusted identity provider to confirm who you are. If that provider trusts any subdomain of the company, a taken-over subdomain can be used to obtain a login for someone else.
  4. Distributing malicious applications through the largest Android app marketplace, from the trusted domain form.cafebazaar.ir. A download link on a trusted address looks legitimate.
  5. Spreading false news and damaging the credibility of the trusted domain.

The write-up also states the general point that a subdomain takeover compromises the main domain and all subdomains of an organisation, with the qualifier "kind of".

Fix

The write-up says the vulnerability is now patched. The fix it argues for is on the DNS side: the old DNS record had to be fixed, because the flaw was in that record and not in the form.cafebazaar.ir application. It does not describe any change on the form builder side.

In everyday terms: when you move out of the rented stall, take down the sign that points people to it.

Variants to test

If you want to look for this kind of bug yourself, these are the checks the write-up suggests, each with what a positive result looks like.

  • Enumerate CNAME records across a target's zone and resolve each target. A positive result is a CNAME whose destination returns a provider error saying the name or account does not exist, as the form builder did here.
  • Check third-party services that hand out per-customer subdomains: form builders, survey tools, status pages, documentation hosts, marketing landing pages. A positive result is a freed name that can be registered by anyone while the customer's CNAME still points at it.
  • After claiming a name, test whether the acquired host can serve JavaScript. A positive result is stored XSS in the third-party application, which the researcher sought to make the takeover critical.
  • Look for redirect whitelists that accept *.target.tld and for OAuth flows that trust any subdomain. A positive result is a redirect or token issued to the acquired subdomain.
  • When a programme rejects a DNS finding as out of scope, check whether the authoritative name servers fall inside the programme's in-scope IP ranges, as the researcher did here.

Glossary

  • API: a defined way for one piece of software to talk to another, like a service counter with set requests you can make.
  • Bug bounty programme: a scheme where an organisation publishes what it will pay for and invites researchers to report security bugs.
  • CNAME (Canonical Name) record: a DNS entry that points one name at another name, so requests for the first are answered by the second.
  • Cookie: a small piece of data a website asks your browser to store and send back on later requests, commonly used to remember that you are logged in.
  • Cross-site scripting (XSS): a vulnerability where an attacker gets their own JavaScript into a page that other people load.
  • Dangling CNAME: a CNAME record that still points at a name whose account or service no longer exists, leaving the name free for anyone to claim.
  • DNS (Domain Name System): the internet's phone book, translating human-readable names into the addresses computers use, and storing records about names.
  • DNS record: an entry in DNS, such as a CNAME, that describes something about a name.
  • Domain: a name on the internet, such as cafebazaar.ir, that identifies a site or organisation.
  • HTTP redirect: a message from a web server telling the browser to load a different address, which changes the address bar.
  • HTTPOnly: a cookie flag that stops JavaScript from reading that cookie.
  • In scope: listed by a bug bounty programme as something it will accept and pay for.
  • IP range: a block of numeric internet addresses, often used to say which servers belong to an organisation.
  • JavaScript: the programming language that runs inside browsers and makes pages interactive.
  • Misconfiguration: a setting left in a state that causes harm, such as a pointer that was never removed.
  • OAuth: the mechanism behind "log in with another service" buttons, where a site asks a trusted identity provider to confirm who you are.
  • Open redirect: a link on a trusted site that will send the visitor to any address an attacker puts in it.
  • Out of scope: not on a bug bounty programme's list, so the programme can decline it even if the bug is real.
  • RCE (remote code execution): an attacker running their own commands on a server.
  • Reflected XSS: XSS where the malicious script travels in a link and only runs if the victim clicks it.
  • RFC6265: the standard document that describes how browser cookies behave.
  • Scope: the list a bug bounty programme publishes saying which systems and addresses it will pay for.
  • Secure (cookie flag): a cookie flag that tells the browser to send the cookie only over an encrypted connection.
  • SSL: encryption for connections between a browser and a server, shown by the padlock in the address bar.
  • Stored XSS: XSS where the malicious script is saved on the server and served to anyone who later views that page.
  • Subdomain: a name that sits to the left of a main domain name, separated by a dot, as in mail.example.com.
  • Subdomain takeover: registering a freed name that an organisation's DNS still points at, so that the organisation's subdomain ends up under the attacker's control.
  • Third-party form builder: an external website where you sign up, design a form and publish it under a subdomain of that website's domain.
  • Whitelist: a list of values that are explicitly allowed, such as subdomains a redirect may point to.
  • Zone: the set of DNS records that belong to one domain and are managed together.

More by Sina Kheirkhah

View all

17 more disclosed reports, best first.

More from CafeBazaar

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Subdomain takeover

The lesson behind this report.

A company's DNS still points at a cloud service it no longer uses, so anyone can claim it and serve content on the company's domain.