Bypassing API Restrictions for Fun and Profit
The application restricted a premium API endpoint to dashboard use only, but the same endpoint was accessible by adding a static API token header and a session token obtained from login. An attacker could programmatically use the restricted endpoint without upgrading to premium.
Published on arnavtripathy98.medium.com
Recently, I downloaded and started testing an application locally which provided dashboard access along with rest API endpoints for it’s users to easily interact with it’s functionality. However, while playing with it’s API’s using the available documentation, I realized that some of the API’s were not accessible.
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
The target in this write-up is an application the researcher downloaded and ran locally. It offers users dashboard access plus REST API endpoints so they can interact with its functionality programmatically. The application has a free tier and a premium tier. Some API endpoints are available in the free tier, while others are reserved for premium subscribers, although the same actions can still be performed through the dashboard.
For the write-up the components are labelled as follows:
- The app is redacted.com.
- The API available in the free tier is
GET /start/transaction. - The API unavailable in the free tier, but available in the premium version, is
POST /stop/transaction.
In practice, a user can start a transaction through the given API, but to stop a transaction they would either have to use the dashboard or upgrade to premium.
Setup
The researcher tested the application locally and used the application's own documentation to explore its APIs. A token was generated in the app to use as an API key, and requests were sent with Postman. Dashboard traffic was proxied through Burp Suite. The login workflow was also analysed through Burp. The final automation was written in Python using the requests library.
Finding it
While testing the documented endpoints with Postman, the start endpoint returned proper results, but the stop endpoint returned the following error:
{ "API is accessible only from dashboard. Please upgrade to premium for programmatic access."}
The message was clear enough, but the researcher searched for information about the app anyway. It turned out that the application had retired certain APIs in the latest versions of the free tier, even though the same action was still possible through the dashboard.
The next step was to proxy all dashboard traffic through Burp Suite. The exact endpoints were being reused in the dashboard, which confirmed that the endpoints existed. The open question was how the application was blocking the Postman requests while the dashboard worked.
Exploitation
Step 1: Inspect the dashboard request
The request sent to the stop transaction endpoint through Burp looked like this:
POST /stop/transactionHost: redacted.comContent-Length: 3144Sec-Ch-Ua: “Chromium”;v=”109", “Not_A Brand”;v=”99"Sec-Ch-Ua-Platform: “macOS”X-Api-Token: "$api_token"Sec-Ch-Ua-Mobile: ?0User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.5414.120 Safari/537.36X-Cookie: token="$token"Content-Type: application/jsonAccept: */*Sec-Fetch-Site: same-originSec-Fetch-Mode: corsSec-Fetch-Dest: emptyReferer: https://redacted.com/Accept-Encoding: gzip, deflateAccept-Language: en-GB,en-US;q=0.9,en;q=0.8Connection: close{"Json data"}
Most of the headers are what you would expect from a browser-made request. Two additional fields stood out:
X-Api-Token, which held a token different from the API key generated in the app.X-Cookie, which was probably the session token.
Step 2: Reproduce the request in Postman
The two additional fields were added in Postman and the field with the API key was removed. The request then threw an error that looked like a content length issue. After adding the Content-Length header, the endpoint could be used like a regular API.
At this point the requirements for using the endpoint as an API were clear. The request needed to:
- Have the
X-Api-Tokenheader value. - Have the session token calculated and appended.
- Have the correct content length calculated and appended.
Step 3: Handle the X-Api-Token value
After analysing the application for a few days, the researcher found that the X-Api-Token value did not change. It may have been unique to each application setup. That made the first part of the request headers easy.
Step 4: Obtain the session token
The login workflow was analysed through Burp. The login request looked something like this:
POST /session HTTP/1.1Host: redacted.comContent-Length: 55Sec-Ch-Ua: "Chromium";v="109", "Not_A Brand";v="99"Sec-Ch-Ua-Platform: "macOS"X-Api-Token: "$api_token"Sec-Ch-Ua-Mobile: ?0User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.5414.120 Safari/537.36Content-Type: application/jsonAccept: */*Origin: https://redacted.comSec-Fetch-Site: same-originSec-Fetch-Mode: corsSec-Fetch-Dest: emptyReferer: https://redacted.com/Accept-Encoding: gzip, deflateAccept-Language: en-GB,en-US;q=0.9,en;q=0.8Connection: close{"username":"admin","password":"admin"}
The response to this request was:
HTTP/1.1 200 OKCache-Control: no-cache, no-store, must-revalidateX-Frame-Options: DENYContent-Type: application/jsonConnection: closeContent-Length: 179Expires: 0Expect-CT: max-age=0Pragma: no-cache{"token":"$token"}
The login response returns the token in a JSON body. All that was left was to craft a POST request to log in and fetch the token from the response. The content length could be calculated dynamically from the script.
Step 5: Automate the bypass
The final script that bypassed the API restrictions is below:
The script builds the headers with a dynamically calculated Content-Length, the Content-Type and the X-API-Token. For the login request it returns those headers only. For the stop request it also appends X-Cookie with the token obtained from the login response. It logs in against /session, extracts the token from the JSON response, and then sends the stop request to the stop endpoint with the session cookie attached.
Using this script, the researcher was able to stop a transaction programmatically without upgrading to a premium plan.
Root cause
The report does not explain why the dashboard headers were accepted. One plausible reading is that the application distinguishes dashboard traffic from API traffic by the presence of headers the dashboard sends, in particular X-Api-Token and the session cookie in X-Cookie. Because the dashboard itself uses the same endpoint, a request that carries the same headers is accepted. The API key generated for programmatic use was not sufficient on its own; the request that worked carried the dashboard's headers instead. The report does not describe the server-side implementation, so the exact check is not known.
Impact
The impact was not high for this application. The researcher was able to stop a transaction programmatically without paying for the premium plan, which is a payment bypass and a logic flaw. The write-up notes that you never know what you might come across.
Fix
- Compare dashboard requests with API requests for the same action and look for headers that only the dashboard sends. A positive result is an API request that succeeds once those headers are copied.
- Check whether any token used by the dashboard is static across sessions or setups. A positive result is a value that does not change and can be reused.
- Look for endpoints that are retired in the free tier but still used by the dashboard. A positive result is the same endpoint responding to a crafted request.
- Test whether the session token can be obtained from the login response and replayed in the header the dashboard uses. A positive result is a successful action performed with that token outside the dashboard.
- Test whether the server enforces the entitlement on the action or only on the route. A positive result is a premium-only action succeeding through a route that is otherwise available.
What happened, in plain words
A security researcher downloaded a small application and ran it on their own computer. The application has two ways to use it: a dashboard (a web page with buttons and screens, like the control panel of a website) and an API (a way for another program to talk to the application directly, without clicking anything). The application comes in a free version and a paid "premium" version. Some actions work in the free version, and some are supposed to need premium.
The researcher found that one action, stopping a transaction, was blocked when they tried to do it through the API, with a message saying they had to upgrade to premium. But the same action still worked when done from the dashboard. So the API route to the action was blocked, while the dashboard could still perform it. By copying the extra headers the dashboard sends along with its requests, the researcher got the endpoint to accept the request, and wrote a small script that did it automatically. That is a payment bypass (getting a paid feature without paying) and a logic flaw (the application's rules can be worked around because the checks are in the wrong place).
This article walks through the same steps the researcher took, explaining each idea from scratch.
The pieces involved
Before the steps, here is what each part of the application is, in the researcher's own labels:
- The application is called redacted.com.
- The API that works in the free version is
GET /start/transaction. - The API that is not available in the free version, but is available in the premium version, is
POST /stop/transaction.
A few words that appear in those lines:
- API: think of it as a service counter. Instead of you clicking buttons on a screen, your program hands a written request to the counter and gets a written answer back. The application offers this so that other software can use it without a human clicking.
- Endpoint: one specific counter at that service desk.
GET /start/transactionis the counter for starting a transaction;POST /stop/transactionis the counter for stopping one. The path after the domain name is what identifies the counter. - GET and POST: two kinds of request.
GETis normally used to ask for information ("give me this").POSTis normally used to send information and cause a change ("do this for me"). - Transaction: whatever unit of work the application manages. In this app you can start one and stop one.
So in everyday terms: the free version lets you start a transaction through the API, but to stop one you are supposed to either use the dashboard or pay for premium.
Setting up
The researcher ran the application locally (on their own machine) and read the application's own documentation to learn which APIs exist. They generated a token inside the application to use as an API key, and sent requests with a tool called Postman. They also sent all the dashboard's web traffic through another tool, Burp Suite, so they could read and change each request. The login process was studied the same way. The final automation was a Python script using the requests library.
Some of those terms:
- Token / API key: a long random-looking string that acts like a password for a program. Instead of typing a username and password every time, the program includes the token in each request, and the server recognises it. Think of a cloakroom ticket: whoever holds the ticket gets the coat.
- Postman: a program for building and sending API requests by hand, without writing code. Useful for trying one request at a time.
- Burp Suite: a program that sits between your browser and the website, so every request and response passes through it and you can read, pause and edit them. Think of a postal worker who opens every letter, copies it, and can rewrite it before delivering.
- Proxy: the middleman position Burp puts itself in. Your browser sends to Burp, Burp forwards to the site.
- Python: a programming language. The
requestslibrary is a set of ready-made Python functions for sending web requests, so the script can log in and call the API without a browser.

Finding it
While testing the documented endpoints with Postman, the start endpoint returned proper results. The stop endpoint returned this error instead:
{ "API is accessible only from dashboard. Please upgrade to premium for programmatic access."}
Line by line: this is a short JSON response, which is just a text format for structured data, made of names and values in curly brackets. Here it contains a single unnamed message. The message says the API can only be reached from the dashboard, and asks the user to upgrade to premium to use it from a program. "Programmatic access" means access from software rather than from a person clicking.
The message was clear enough, but the researcher searched online for information about the application anyway. It turned out the application had retired certain APIs in the latest free versions, even though the same action was still possible through the dashboard.
That is the interesting part. If the action is still possible from the dashboard, then the application still knows how to do it. The only thing being blocked is the API route to it. So the next step was to watch what the dashboard actually sends when it performs the stop action, by proxying all dashboard traffic through Burp Suite. The exact endpoints were being reused in the dashboard, which confirmed the endpoints existed. The open question became: how is the application blocking the Postman requests while the dashboard works?
Exploitation
Step 1: Inspect the dashboard request
The request sent to the stop transaction endpoint through Burp looked like this:
POST /stop/transactionHost: redacted.comContent-Length: 3144Sec-Ch-Ua: “Chromium”;v=”109", “Not_A Brand”;v=”99"Sec-Ch-Ua-Platform: “macOS”X-Api-Token: "$api_token"Sec-Ch-Ua-Mobile: ?0User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.5414.120 Safari/537.36X-Cookie: token="$token"Content-Type: application/jsonAccept: */*Sec-Fetch-Site: same-originSec-Fetch-Mode: corsSec-Fetch-Dest: emptyReferer: https://redacted.com/Accept-Encoding: gzip, deflateAccept-Language: en-GB,en-US;q=0.9,en;q=0.8Connection: close{"Json data"}
This block is one HTTP request. HTTP is the language browsers and servers speak. A request has three parts: a first line saying what to do, a set of headers (name and value pairs carrying extra information), and a body (the data being sent). In the block above the line breaks have been lost, so it reads as one long line, but you can still pick out the pieces:
POST /stop/transactionis the first line: the method (POST, meaning "do this") and the endpoint being called.Host: redacted.comsays which site the request is for. One server can host many sites, so the server needs to know which one you mean.Content-Length: 3144says how many bytes long the body is. The server uses it to know when it has received the whole body.Sec-Ch-Ua,Sec-Ch-Ua-Platform,Sec-Ch-Ua-Mobileare headers the browser adds to describe itself: which browser family, which operating system, whether it is a mobile device. They are informational.X-Api-Token: "$api_token"is a custom header (custom headers usually start withX-) carrying a token. The value is shown as a placeholder here.User-Agentis the browser's self-description: name, version and operating system.X-Cookie: token="$token"is another custom header, carrying what is probably the session token.Content-Type: application/jsonsays the body is JSON, so the server should read it as structured data.Accept: */*says the client will accept any kind of response.Sec-Fetch-Site,Sec-Fetch-Mode,Sec-Fetch-Destare headers modern browsers add to describe the context of the request: same site or not, whether it is a cross-origin request, and what kind of resource is being fetched.Referer: https://redacted.com/says which page the request came from.Accept-Encoding: gzip, deflatesays the client can accept compressed responses.Accept-Language: en-GB,en-US;q=0.9,en;q=0.8says which languages the user prefers, with weights.Connection: closesays the connection can be closed after this request.{"Json data"}is the body: a placeholder for the JSON data being sent.
Most of these headers are what you would expect from a request made by a browser. Two stood out:
X-Api-Token, which held a token different from the API key generated in the app.X-Cookie, which was probably the session token.
Those two headers were the ones that stood out in the dashboard request. The report does not say how the server used them.
Step 2: Reproduce the request in Postman
The two additional fields were added in Postman and the field with the API key was removed. The request then threw an error that looked like a content length issue. After adding the Content-Length header, the endpoint could be used like a regular API.
The field with the API key was removed, as the report describes. The request threw an error that looked like a content length issue, and adding the Content-Length header fixed it. Once the length was correct, the endpoint answered normally.
At this point the requirements for using the endpoint as an API were clear. The request needed to:
- Have the
X-Api-Tokenheader value. - Have the session token calculated and appended.
- Have the correct content length calculated and appended.
Step 3: Handle the X-Api-Token value
After analysing the application for a few days, the researcher found that the X-Api-Token value did not change. It may have been unique to each application setup. That made the first part of the request headers easy.
Why does a value that never changes matter? Because if it changed every session, the script would have to fetch a fresh one each time. If it is fixed, it can simply be written into the script once. The researcher suggested it may have been unique to each application setup.
Step 4: Obtain the session token
The login workflow was analysed through Burp. The login request looked something like this:
POST /session HTTP/1.1Host: redacted.comContent-Length: 55Sec-Ch-Ua: "Chromium";v="109", "Not_A Brand";v="99"Sec-Ch-Ua-Platform: "macOS"X-Api-Token: "$api_token"Sec-Ch-Ua-Mobile: ?0User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.5414.120 Safari/537.36Content-Type: application/jsonAccept: */*Origin: https://redacted.comSec-Fetch-Site: same-originSec-Fetch-Mode: corsSec-Fetch-Dest: emptyReferer: https://redacted.com/Accept-Encoding: gzip, deflateAccept-Language: en-GB,en-US;q=0.9,en;q=0.8Connection: close{"username":"admin","password":"admin"}
Again, the line breaks are lost, but the structure is the same as before:
POST /session HTTP/1.1is the first line: send data to the/sessionendpoint, using version 1.1 of HTTP.Host,Content-Length, theSec-Ch-*headers,User-Agent,Content-Type,Accept,Sec-Fetch-*,Referer,Accept-Encoding,Accept-LanguageandConnectionare the same kinds of headers as in the previous request.X-Api-Token: "$api_token"is the same custom token header, also sent on login.Origin: https://redacted.comsays which site the request is coming from. Browsers add it on cross-origin requests and on some same-origin ones; servers use it for security decisions.{"username":"admin","password":"admin"}is the body: a JSON object with two fields, the username and the password.
The response to this request was:
HTTP/1.1 200 OKCache-Control: no-cache, no-store, must-revalidateX-Frame-Options: DENYContent-Type: application/jsonConnection: closeContent-Length: 179Expires: 0Expect-CT: max-age=0Pragma: no-cache{"token":"$token"}
A response has the same shape as a request: a first line, headers, and a body. Here:
HTTP/1.1 200 OKis the status line.200means success, andOKis its human-readable label.Cache-Control: no-cache, no-store, must-revalidatetells browsers and proxies not to store this response. Sensitive responses should not be cached, because a cached copy could be read later by someone else.X-Frame-Options: DENYtells the browser not to display this page inside a frame on another site, which prevents a class of clickjacking attacks.Content-Type: application/jsonsays the body is JSON.Connection: closesays the connection will be closed after this response.Content-Length: 179says the body is 179 bytes long.Expires: 0andPragma: no-cacheare older cache-control headers, also saying not to cache.Expect-CT: max-age=0relates to certificate transparency, a mechanism for detecting misissued HTTPS certificates.{"token":"$token"}is the body: a JSON object with one field,token, whose value is the session token. The value is shown as a placeholder.
So the login response hands back the session token in its body. All that was left was to craft a POST request to log in and fetch the token from the response. The content length could be calculated dynamically from the script, meaning the script counts the bytes of whatever it is about to send and puts that number in the header, instead of a hard-coded value.
Step 5: Automate the bypass
The final script that bypassed the API restrictions is below:
Line by line, in plain words:
import requestsloads therequestslibrary, the set of functions for sending web requests.import jsonloads Python's JSON library. It is imported here, though the script builds its JSON by hand with string concatenation.#Credentials needed to automate sessionis a comment, ignored by Python, explaining the next lines.username= "admin"andpassword= "admin"store the login credentials in variables. These are placeholders for the test account.x_api_token="1AB-345-678"stores the fixedX-Api-Tokenvalue found in step 3. The value shown is a placeholder.#Function to generate headers for Loginintroduces a function, a named block of code you can call repeatedly.def headers_data(request_data,if_login,token=0):defines that function. It takes the data about to be sent, a flag saying whether this is the login request, and an optional token that defaults to0.data_len= str(len(request_data))counts the length of the data and turns the number into text, because header values are text.headers_request = {starts a dictionary, Python's way of storing name-and-value pairs, which is exactly what a set of headers is.'Content-Length': data_len,puts the calculated length in as theContent-Lengthheader. This is the dynamic calculation that solved the earlier error.'X-API-Token': x_api_tokenadds the fixed token header.}closes the dictionary.if if_login:checks whether this is the login request.return headers_requestif it is, returns the three headers and stops. Login does not need a session cookie, because you do not have one yet.else:otherwise, for the stop request:headers_request['X-Cookie']= 'token='+tokenadds theX-Cookieheader, with the wordtoken=followed by the session token obtained from login. This is the header the dashboard sends and the plain API request did not.return headers_requestreturns the full set.#Login to application and store tokenis a comment.login_data= '{"username":' + '"' + username + '"'+',"password":' + '"' + password + '"'+'}'builds the JSON login body by gluing strings together: the field names in quotes, the values from the variables, and the punctuation JSON needs.login_headers = headers_data(login_data,True)calls the function with the login body and the login flag, so it returns headers without a cookie.try:starts a block where errors are caught rather than crashing the script.login_tokens = requests.post('https://redacted.com/session', headers=login_headers, data=login_data, verify=False)sends the login request to/sessionwith those headers and that body.verify=Falsetells the library not to check the server's HTTPS certificate, which is convenient for a local test setup but weakens security.token= login_tokens.json().get('token')reads the response as JSON and pulls out thetokenfield, storing it in a variable. This is the session token from step 4.print("Login Successful !")prints a message so you can see it worked.except:catches any error in the block above.raise Exception("Login Automation failed")stops the script with a clear message if login failed.#Post request to stop endpoint.is a comment.payload_data= { "Some json data to be posted to stop transaction"}is a placeholder for the body to send to the stop endpoint.update_ip_headers = headers_data(payload_data,False,token)calls the function again, this time with the stop body, the flag set to false, and the session token, so it returns headers that includeX-Cookie.stop_transaction_response= requests.put('https://redacted.com/stop/transaction', headers=update_ip_headers, data=payload_data, verify=False)sends the stop request. Note that it usesrequests.put, while the endpoint was described earlier asPOST /stop/transaction; the script as written uses PUT.print("Transaction stopped via API")prints a final message.
In short, the script builds the headers with a dynamically calculated Content-Length, the Content-Type and the X-API-Token. For the login request it returns those headers only. For the stop request it also appends X-Cookie with the token obtained from the login response. It logs in against /session, extracts the token from the JSON response, and then sends the stop request to the stop endpoint with the session cookie attached.
Using this script, the researcher was able to stop a transaction programmatically without upgrading to a premium plan.
Why it worked
The report does not explain why the dashboard headers were accepted. One plausible reading is that the application distinguishes dashboard traffic from API traffic by the presence of headers the dashboard sends, in particular X-Api-Token and the session cookie in X-Cookie. Because the dashboard itself uses the same endpoint, a request that carries the same headers is accepted. The API key generated for programmatic use was not sufficient on its own; the request that worked carried the dashboard's headers instead.
Impact
The impact was not high for this application. The researcher was able to stop a transaction programmatically without paying for the premium plan, which is a payment bypass and a logic flaw. The write-up notes that you never know what you might come across.
Fix
Variants to test
- Compare dashboard requests with API requests for the same action and look for headers that only the dashboard sends. A positive result is an API request that succeeds once those headers are copied.
- Check whether any token used by the dashboard is static across sessions or setups. A positive result is a value that does not change and can be reused.
- Look for endpoints that are retired in the free tier but still used by the dashboard. A positive result is the same endpoint responding to a crafted request.
- Test whether the session token can be obtained from the login response and replayed in the header the dashboard uses. A positive result is a successful action performed with that token outside the dashboard.
- Test whether the server enforces the entitlement on the action or only on the route. A positive result is a premium-only action succeeding through a route that is otherwise available.
Glossary
- API: a way for one program to talk to another, by sending requests and receiving responses, without a human clicking a screen.
- API key: a long string used like a password by a program, so the server can recognise who is calling.
- Authorisation check: the server deciding whether this particular caller is allowed to do this particular action.
- Body: the data part of a request or response, separate from the headers.
- Burp Suite: a tool that sits between your browser and a website so you can read, pause and edit every request and response.
- Cache-Control: a response header telling browsers and proxies whether they may store the response.
- Content-Length: a header saying how many bytes long the body is.
- Content-Type: a header saying what format the body is in, such as JSON.
- Cookie: a small piece of data a site stores in your browser, often used to remember that you are logged in.
- Dashboard: the web page with buttons and screens that a person uses to operate an application.
- Dictionary: in Python, a collection of name-and-value pairs, which maps neatly onto HTTP headers.
- Endpoint: one specific address in an API, such as
/stop/transaction, that performs one specific job. - Entitlement: the right to use a paid feature, which the server should check before allowing the action.
- Function: a named block of code that can be called repeatedly with different inputs.
- GET: an HTTP method normally used to ask for information.
- Header: a name-and-value pair sent with a request or response, carrying extra information such as the format of the body or a token.
- HTTP: the language browsers and servers use to exchange requests and responses.
- HTTPS: HTTP carried over an encrypted connection, so others cannot read it in transit.
- JSON: a text format for structured data, made of names and values in curly brackets.
- Logic flaw: a bug where the application's rules can be worked around because a check is missing or in the wrong place, even though nothing crashes.
- Origin: a header saying which site a request comes from, used by servers for security decisions.
- Payment bypass: getting a paid feature without paying for it.
- POST: an HTTP method normally used to send data and cause a change.
- Postman: a program for building and sending API requests by hand.
- Premium tier: the paid version of an application, with features the free version does not have.
- Proxy: a middleman that forwards traffic between your browser and a site, so it can be inspected.
- Python: a programming language, used here to automate the requests.
- Referer: a header saying which page a request came from.
- requests (library): a set of ready-made Python functions for sending web requests.
- Response: what the server sends back: a status line, headers and a body.
- REST: a common style for designing APIs around endpoints and HTTP methods.
- Session token: a value issued at login that identifies your logged-in session on later requests.
- Status code: the number in a response's first line, such as
200, saying broadly what happened. - Token: a string used in place of a password to prove identity to a server.
- User-Agent: a header in which the browser describes itself: name, version and operating system.
- X-Api-Token: a custom header used by this application to carry a token; custom headers often start with
X-. - X-Cookie: a custom header used by this application to carry the session token.