How I bought my way to subdomain takeover on tokopedia
A subdomain of Tokopedia pointed via CNAME to an expired domain that the researcher could buy. After purchasing and pointing it to a free host, the researcher took over the subdomain and could potentially steal cookies via XSS, though a certificate warning limited the attack.
Published on medium.com
{{media:0}}
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.
Context
Tokopedia runs a public bug bounty programme, and its rules are published at https://github.com/tokopedia/Bug-Bounty. The scope is mainly wildcard domains: *.tokopedia.com and *.tokopedia.net. The finding described here is a subdomain takeover: a hostname under tokopedia.com was configured as a CNAME to a domain that had expired and was available for anyone to register.
When a subdomain is an alias for a domain that nobody controls, whoever registers that domain inherits the subdomain. The browser resolves the Tokopedia name, follows the CNAME, and loads content from the new owner's server, while the address bar still shows the Tokopedia hostname.
Setup
The work needed no account on the target and no special tooling beyond a shell and a browser:
- Subdomain enumeration with open source tools such as sublist3r, knockpy and massdns.
digto inspect DNS records.- A whois lookup to check the registration status of the CNAME target.
- namecheap.com to check availability and buy the expired domain.
- A free hosting service and a free SSL certificate for the proof of concept.
The precondition for the whole attack is that the CNAME target is expired and unregistered, and that the researcher can afford to register it.
Finding it
Enumeration of the wildcard scope produced a number of subdomains, and one of them, referred to in the write-up as REDACTED.tokopedia.com, stood out because opening it returned an ERR_NAME_NOT_RESOLVED error page from the browser.
A dig query showed why: the CNAME configuration pointed to another top level domain, REDACTED.com. In other words, REDACTED.tokopedia.com was an alias for REDACTED.com, a domain outside Tokopedia's control.
The whois record for that domain showed it had expired. Checking namecheap.com confirmed it was available to buy.
At this point the researcher was not certain the subdomain was actually takeoverable, and considered reporting without buying the domain, but judged that a weak idea. The researcher could not afford a domain at 8 bucks, so the money was borrowed from a friend and the domain was purchased.
Exploitation
Step 1: register the expired CNAME target
The expired domain REDACTED.com was bought through namecheap.com. Registering it puts the CNAME target back under the researcher's control, so any name that aliases it now resolves to infrastructure the researcher chooses.
Step 2: point the domain at attacker-controlled hosting
The domain was pointed at a free hosting service. Opening REDACTED.tokopedia.com again then loaded content from the researcher's own server, confirming the takeover: the Tokopedia subdomain now served attacker content.

Step 3: attempt an XSS proof of concept
The plan was to build an XSS proof of concept on the taken-over subdomain. That ran into a problem: the site's cookies are set with the secure flag, so the proof of concept has to be served over HTTPS.
A free SSL certificate was obtained for REDACTED.com. That created a second problem: the browser shows a privacy warning, because the site is accessed as REDACTED.tokopedia.com while the certificate is signed for REDACTED.com. The names do not match, so the certificate is not valid for the hostname in the address bar.

I got this from stackoverflow, the warning is different but you got the idea.
A *.tokopedia.com certificate was not an option, since the researcher could not obtain one for a domain Tokopedia owns. Rather than pursue the proof of concept further, the report was sent at that point. The reasoning given is that cookie theft is still possible if the user clicks the proceed to… button on the warning and continues to the site anyway.

A note on what to serve
The write-up adds a caution for anyone reproducing this: do not put anything unnecessary on the front page of a taken-over subdomain. Real users can see it, the company will not like it, and it damages their reputation. The author notes that displaying "Subdomain taken over" on the front page, as was done here in earlier days as a hunter, is not the best idea. A better approach is to keep the proof of concept in a hidden HTML tag and show something like "Under Maintenance" on the front page, and to randomise the file names hosted on the subdomain so users do not stumble on them by accident.
Root cause
The mistake is a dangling DNS record: REDACTED.tokopedia.com was configured as a CNAME to REDACTED.com, and that target domain was allowed to expire. Once the registration lapsed, the alias pointed at a name anyone could buy, and buying it was enough to serve content under the Tokopedia hostname. The CNAME target was allowed to expire, so the alias pointed at a name anyone could buy.
The HTTPS limitation is a separate matter and not a defence: the mismatch between the hostname and the certificate only produces a browser warning that the user can click through, and the write-up notes that cookies could still be stolen if the user proceeds.
Impact
The Security Team verified the report as a valid security bug with High Severity. The demonstrated impact is that registering the expired domain let the researcher serve content on a tokopedia.com subdomain. Because the cookies are set with the secure flag, the interesting payloads need HTTPS, and with a certificate for the attacker's own domain the browser shows a warning; a user who clicks through the warning can still have cookies stolen. The write-up does not go further than that in describing what was or could be taken.
Fix
The timeline in the write-up records that on July 31 2019 the bug was fixed and the researcher was asked to re-test it, and that the same message asked for bank details to send the reward. The report does not describe the specific change made to the DNS record. In general terms, the fix for this class of bug is to remove or repoint the dangling CNAME, and to keep track of domains referenced by DNS records so they are renewed before they expire.
Timeline
| Date | Event |
|---|---|
| July 27 2019 | Report sent |
| July 29 2019 | Security team verified the report, valid with High Severity |
| July 31 2019 | Bug fixed; researcher asked to re-test; bank details requested for the reward |
| November 20 2019 | Bounty awarded |
The bounty is described as three digits, against the 8 bucks the researcher spent.

Variants to test
- Expired CNAME targets on any in-scope wildcard. Enumerate subdomains, resolve each one, and look for CNAMEs pointing outside the organisation. A positive result is a CNAME whose target returns no registration in whois and is listed as available at a registrar.
ERR_NAME_NOT_RESOLVEDon a live subdomain. A hostname in scope that fails to resolve while its CNAME points elsewhere is the same signal seen here. Confirm withdigthat the alias target is the unregistered name.- Recently lapsed domains. Check the expiry date on whois for every external CNAME target; a domain close to expiry is a candidate to watch and register when it drops.
- Cookie scope after takeover. Once a subdomain is controlled, check whether cookies are set with the
secureflag and whether the parent domain's cookies are readable from the subdomain. A positive result is session material reachable from the taken-over host, subject to the HTTPS warning described above. - Other DNS record types. The same dangling-reference problem applies to records other than CNAMEs that point at names the organisation no longer owns; a positive result is any such record whose target can be registered by a third party.
What happened, in plain words
Tokopedia is a large Indonesian online shopping site. Like many big companies, it runs a bug bounty programme: a public invitation for outside people to look for security mistakes in its systems and report them, with a reward (the bounty) for good findings. The rules of Tokopedia's programme are published at https://github.com/tokopedia/Bug-Bounty, and the researcher read them before starting.
The rules say the interesting targets are wildcard domains: *.tokopedia.com and *.tokopedia.net. The asterisk is a stand-in for "anything". So *.tokopedia.com means every name that ends in .tokopedia.com, such as shop.tokopedia.com or help.tokopedia.com. A company owns a whole family of such names, and each one can point at a different server.
The researcher found one of those names, written here as REDACTED.tokopedia.com, that did not work at all: the browser showed an error page saying the name could not be found. Digging into the technical records behind that name showed it was set up as an alias for a completely different domain, REDACTED.com, which Tokopedia does not own. And that other domain had expired: nobody had renewed it, so anyone in the world could buy it.
That is the whole bug, called a subdomain takeover. The Tokopedia name still points at the other domain. If a stranger buys that other domain, the Tokopedia name starts loading the stranger's content, while the address bar still shows a Tokopedia address. The researcher bought the domain, pointed it at free hosting, and the Tokopedia subdomain started serving the researcher's own page. The report was accepted as a valid bug with High Severity and paid a three-digit bounty.
The setup
The work needed no account on Tokopedia and no special software beyond a terminal (the text window where you type commands) and a browser:
- Subdomain enumeration with open source tools such as sublist3r, knockpy and massdns. Enumeration means making a list of names that exist under a domain, by trying many guesses and seeing which ones answer.
dig, a command that asks the internet's address book (DNS) what a name points to.- A whois lookup, which asks the public registration records who owns a domain and whether the registration is still valid.
- namecheap.com, a website where domains are bought.
- A free hosting service and a free SSL certificate for the proof of concept.
The precondition for the whole attack is that the alias target is expired and unregistered, and that the researcher can afford to register it.
Finding it
Enumeration of the wildcard scope produced a number of subdomains. One of them, referred to in the write-up as REDACTED.tokopedia.com, stood out because opening it returned an ERR_NAME_NOT_RESOLVED error page from the browser.
That error is the browser saying: I asked the internet where this name lives, and got no answer. For a live company site that is odd, and odd is exactly what a hunter looks for.
A dig query showed why. The CNAME configuration pointed to another top level domain, REDACTED.com. A CNAME record is the DNS way of saying "this name is just another name for that name". Think of it as a forwarding note on a letterbox: post for this address should be delivered to that other address. So REDACTED.tokopedia.com was an alias for REDACTED.com, a domain outside Tokopedia's control.
The whois record for that domain showed it had expired. Checking namecheap.com confirmed it was available to buy.
At this point the researcher was not certain the subdomain was actually takeoverable, and considered reporting without buying the domain, but judged that a weak idea. A report saying "this might be takeable" is much less convincing than a report showing it was taken. The researcher could not afford a domain at 8 bucks, so the money was borrowed from a friend and the domain was purchased.
Exploitation
Step 1: register the expired CNAME target
The expired domain REDACTED.com was bought through namecheap.com. Registering it puts the CNAME target back under the researcher's control, so any name that aliases it now resolves to infrastructure the researcher chooses. This is the key move: the Tokopedia side was never touched. The weakness was that Tokopedia's record pointed at something nobody was keeping alive.
Step 2: point the domain at attacker-controlled hosting
The domain was pointed at a free hosting service. Opening REDACTED.tokopedia.com again then loaded content from the researcher's own server, confirming the takeover: the Tokopedia subdomain now served attacker content.

Step 3: attempt an XSS proof of concept
The plan was to build an XSS proof of concept on the taken-over subdomain. XSS, cross-site scripting, means getting your own code to run inside a page that the victim's browser believes belongs to the real site. The classic goal is to read the victim's cookies: small pieces of data the browser stores for a site, often including a session identifier that proves you are logged in. Steal the cookie and you can act as the user.
That ran into a problem: the site's cookies are set with the secure flag, so the proof of concept has to be served over HTTPS. The secure flag is an instruction to the browser: only ever send this cookie over an encrypted connection. HTTPS is the padlock version of the web, where traffic is encrypted and the server proves its identity with a certificate. So a page served over plain HTTP could not get the cookie at all.
A free SSL certificate was obtained for REDACTED.com. That created a second problem: the browser shows a privacy warning, because the site is accessed as REDACTED.tokopedia.com while the certificate is signed for REDACTED.com. The names do not match, so the certificate is not valid for the hostname in the address bar. A certificate is like a passport: it states a name, and the browser checks that the name matches the address you typed. Here the passport says REDACTED.com but you are visiting REDACTED.tokopedia.com, so the browser complains.

I got this from stackoverflow, the warning is different but you got the idea.
A *.tokopedia.com certificate was not an option, since the researcher could not obtain one for a domain Tokopedia owns. A certificate authority will not issue a certificate for a name you cannot prove you control. Rather than pursue the proof of concept further, the report was sent at that point. The reasoning given is that cookie theft is still possible if the user clicks the proceed to… button on the warning and continues to the site anyway. The warning is a speed bump, not a wall: many people click through it.

A note on what to serve
The write-up adds a caution for anyone reproducing this: do not put anything unnecessary on the front page of a taken-over subdomain. Real users can see it, the company will not like it, and it damages their reputation. The author notes that displaying "Subdomain taken over" on the front page, as was done here in earlier days as a hunter, is not the best idea. A better approach is to keep the proof of concept in a hidden HTML tag and show something like "Under Maintenance" on the front page, and to randomise the file names hosted on the subdomain so users do not stumble on them by accident. In other words: prove you control the page without shouting about it to shoppers.
Root cause
The mistake is a dangling DNS record: REDACTED.tokopedia.com was configured as a CNAME to REDACTED.com, and that target domain was allowed to expire. Once the registration lapsed, the alias pointed at a name anyone could buy, and buying it was enough to serve content under the Tokopedia hostname. The CNAME target was allowed to expire, so the alias pointed at a name anyone could buy.
The HTTPS limitation is a separate matter and not a defence: the mismatch between the hostname and the certificate only produces a browser warning that the user can click through, and the write-up notes that cookies could still be stolen if the user proceeds.
Impact
The Security Team verified the report as a valid security bug with High Severity. The demonstrated impact is that registering the expired domain let the researcher serve content on a tokopedia.com subdomain. Because the cookies are set with the secure flag, the interesting payloads need HTTPS, and with a certificate for the attacker's own domain the browser shows a warning; a user who clicks through the warning can still have cookies stolen. The write-up does not go further than that in describing what was or could be taken.
Fix
The timeline in the write-up records that on July 31 2019 the bug was fixed and the researcher was asked to re-test it, and that the same message asked for bank details to send the reward. The report does not describe the specific change made to the DNS record. In general terms, the fix for this class of bug is to remove or repoint the dangling CNAME, and to keep track of domains referenced by DNS records so they are renewed before they expire.
Timeline
| Date | Event |
|---|---|
| July 27 2019 | Report sent |
| July 29 2019 | Security team verified the report, valid with High Severity |
| July 31 2019 | Bug fixed; researcher asked to re-test; bank details requested for the reward |
| November 20 2019 | Bounty awarded |
The bounty is described as three digits, against the 8 bucks the researcher spent.

Variants to test
- Expired CNAME targets on any in-scope wildcard. Enumerate subdomains, resolve each one, and look for CNAMEs pointing outside the organisation. A positive result is a CNAME whose target returns no registration in whois and is listed as available at a registrar.
ERR_NAME_NOT_RESOLVEDon a live subdomain. A hostname in scope that fails to resolve while its CNAME points elsewhere is the same signal seen here. Confirm withdigthat the alias target is the unregistered name.- Recently lapsed domains. Check the expiry date on whois for every external CNAME target; a domain close to expiry is a candidate to watch and register when it drops.
- Cookie scope after takeover. Once a subdomain is controlled, check whether cookies are set with the
secureflag and whether the parent domain's cookies are readable from the subdomain. A positive result is session material reachable from the taken-over host, subject to the HTTPS warning described above. - Other DNS record types. The same dangling-reference problem applies to records other than CNAMEs that point at names the organisation no longer owns; a positive result is any such record whose target can be registered by a third party.
Glossary
- Bug bounty programme: a public offer by a company to pay people who find and report security problems in its systems.
- Bounty: the reward paid for an accepted report.
- Wildcard domain: a rule covering every name ending in a given domain, written with an asterisk, as in
*.tokopedia.com. - Subdomain: a name that sits under a main domain, such as
shop.example.comunderexample.com. - Subdomain takeover: taking control of a company subdomain by registering something the subdomain points at but nobody owns any more.
- DNS: the internet's address book, which turns names into the addresses of servers.
- CNAME record: a DNS entry saying one name is an alias for another name.
- Dangling DNS record: a DNS entry that points at a name nobody controls any more, such as an expired domain.
- Enumeration: systematically listing names or resources that exist, usually by trying many candidates.
- sublist3r, knockpy, massdns: open source tools used to find subdomains and resolve them in bulk.
dig: a command line tool that queries DNS and shows the records for a name.- whois: a public lookup service that shows who registered a domain and until when.
- Top level domain: the last part of a domain name, such as
.comor.net. - Registrar: a company that sells and renews domain registrations, such as namecheap.com.
ERR_NAME_NOT_RESOLVED: a browser error meaning the name could not be looked up in DNS.- XSS (cross-site scripting): getting your own code to run inside a page the victim's browser treats as belonging to a real site.
- Cookie: a small piece of data a site stores in the browser, often used to keep you logged in.
secureflag: a cookie setting that tells the browser to send the cookie only over HTTPS.- HTTPS: the encrypted version of the web, where the server proves its identity with a certificate.
- SSL certificate: a file that binds a domain name to a server, checked by the browser to confirm the site is genuine.
- Certificate authority: an organisation trusted to issue certificates after checking that you control the name.
- Privacy warning: the browser message shown when a certificate does not match the address being visited, which the user can click through.
- Proof of concept (PoC): a small demonstration that a vulnerability is real and exploitable.
- High Severity: a rating given to a bug with serious potential impact.
- Session identifier: the value in a cookie that proves which logged-in user the browser belongs to.
- Hidden HTML tag: page markup that is present in the code but not shown to the visitor, useful for hiding a proof of concept.