I Ignored a NEXT_PUBLIC_ Token for a Week. Then It Unlocked Blind SQLi and the Whole Database π
A leaked API token combined with a tenant identifier header allowed access to a member lookup endpoint whose 'fields' parameter was inserted directly into the SQL SELECT list as a column name. By aliasing a different table to the expected prefix, the attacker could read arbitrary tables, including tokens and roles, across all tenants on the shared backend.
Published on medium.com
Bug Bounty Tips
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
Akash Sundaramoorthi, a 20 year old bug hunter, was scrolling through reels when an ad for an Indian D2C company appeared. Curious, he decided to poke around the company's website. The feature that mattered was a member lookup endpoint that returned a member's first name and email address, with the caller choosing which columns came back through a fields parameter.
The write-up is his first, and it covers a chain that started with a leaked NEXT_PUBLIC_ environment block and ended in SQL injection across every tenant on the backend.
Setup
No special accounts or tooling beyond the usual were needed. The researcher began with subdomain enumeration, waybackurls and some JavaScript analysis. He later signed up for an ordinary account on one of the company's acquisitions to obtain his own member id, and replayed requests in Burp. The final exploit combined a leaked API token from the parent site's client-side JavaScript with a tenant id harvested from the acquisition's traffic.
Finding it
The initial recon turned up nothing. Then, out of habit, he opened the page source and found a NEXT_PUBLIC_ env block with an API key and API URL baked directly into the HTML.

Figure 1: Client-side JavaScript exposing NEXT_PUBLIC_ environment variables, including a publicly accessible API endpoint and token.*

He tried the token against the gateway:
curl -s https://api.target.in \ -H "Authorization: Bearer <LEAKED-TOKEN>"
Instead of the expected 401, the response was a 400:
{"message":"Failed to connect to tenant database: BadRequestException: Tenant not found: target","statusCode":400,"timestamp":"2026-06-25T20:44:54.652Z","path":"/"}
That distinction mattered. A 401 would have meant the key was dead. A 400 complaining about a tenant database meant the key had already cleared authentication, and the gateway simply did not know which database to point it at. It had guessed the tenant name target from the hostname.
He spent the next few hours guessing the right tenant value and watching the site's own network calls for a hint. Nothing worked, and he thought it was a dead, rotated key. He moved on to one of the company's acquisitions, on the reasoning that acquisitions often share the same backend and infrastructure as the parent.
He ran the same recon on the acquisition and fed the JavaScript files to Claude, asking it to extract every API route and endpoint. One stood out:
/api/member?id=<id>&fields=given_name,email_addr
He signed up for an account, grabbed his own id and hit the endpoint. It returned a 401. Digging through the JavaScript and replaying requests in Burp, he found a call carrying X-Tenant-Id: brand-name. He dropped that tenant id into his curl command and got another 401.
At that point the key and the tenant id looked like two separate dead ends. Then he realised they were two halves of the same lock: the API key did not need a tenant name, it needed a tenant id, and he now had one.
Exploitation
Step 1: combine the leaked token with the tenant id
curl -s https://api.acquisition.com/api/member?id=<my_id>&fields=given_name,email_addr \ -H "X-Tenant-Id: brand-name" \ -H "X-Api-Token: <LEAKED-TOKEN>"
The request sends the leaked token as X-Api-Token and the harvested tenant id as X-Tenant-Id. It returned his own data. On its own that is not a vulnerability, since it only exposed his own details. The interesting part was the fields=given_name,email_addr parameter: the endpoint let the caller name the columns it wanted back.
Step 2: probe the fields parameter with a non-existent column
GET /api/member?id=<my_id>&fields=zzzX-Tenant-Id: brand-nameX-Api-Token: <LEAKED-TOKEN>
The server responded with the error and, crucially, the query it had built:
{ "error": "column member.zzz does not exist", "query": "SELECT member.zzz FROM member WHERE member.id = <my_id>"}
Two things stood out. The input zzz had gone straight into the SQL as a column name, untouched. And the server echoed back the exact query it built, so the injection point was visible:
SELECT member.<MY_INPUT> FROM member WHERE member.id = <my_id>
Column names are identifiers, not values, and prepared statements can only parameterise values. A query that lets the caller pick columns by name almost always means the code is concatenating strings by hand with no escaping. That is what this was: the input was dropped into the SELECT list behind a fixed member. prefix.
Step 3: why the classic payloads failed
He reached for OR 1=1 and a quick subquery. Both failed instantly. Those payloads assume injection into a WHERE clause, where the attacker supplies a value that can be twisted into a condition:
SELECT * FROM member WHERE id = [INJECTION HERE] β OR 1=1 works here
His injection point was the column list right after SELECT, where the database expects an identifier, not a value:
SELECT member.[INJECTION HERE] FROM member WHERE id = <my_id> β OR 1=1 is meaningless here
There is no condition to flip and no quote to escape. The app also silently prefixed whatever he sent with member., so a subquery such as (SELECT token FROM secrets LIMIT 1) became member.(SELECT..., which is garbage to the parser. Rather than write the bug off as unexploitable, he asked what is actually valid right after SELECT member..
Step 4: defeat the prefix by re-aliasing member
The member. prefix could not be deleted, so he changed what member pointed at. By rewriting the FROM clause and aliasing a different table back to the name member, member.<anything> resolves against that other table:
fields=token,role FROM secrets AS member
The server assembled:
SELECT member.token, member.roleFROM secrets AS member
The app's own trailing FROM ... WHERE ... is commented out, leaving:
SELECT member.token, member.role FROM secrets AS member
The prefix that had blocked him now pointed at a table he was never supposed to see, and the response was:
{ "rows": [["tok_demo_INVENTED_0000", "admin"]] }
An auth token and a role came out of an endpoint that is only supposed to return a name and an email.
Step 5: enumerate the schema
The same trick, aimed at the database catalogue instead of a guessed table name:
fields=table_name FROM information_schema.tables AS member
It listed the tables. From there he could walk every table and every column and reach just about anything in the database, all through one fields parameter on an endpoint meant to return a first name.
Root cause
The fields parameter was concatenated directly into the SELECT list, behind a fixed member. prefix, with no escaping. Because column names are identifiers rather than values, prepared statements cannot parameterise them, so the usual defence did not apply here. The server also echoed the constructed query in its error response, which made the injection point and the query shape immediately visible. The X-Tenant-Id header meant the same injection point worked across every tenant on that backend, including the parent company and its other brands sharing the infrastructure.
Impact
The injection was not scoped to his account or to one company. Through the X-Tenant-Id header the same vulnerable fields parameter worked across every tenant on that backend, including the parent company and its other brands sharing the same infrastructure. He could walk every table and every column, including auth tokens and roles, from an endpoint that should only return a first name and an email address. One vulnerable parameter, multiplied across every customer the platform ran.
Once the injection was confirmed he stopped immediately, wrote up the full findings and sent the report directly to the CTO.
Fix
The team responded quickly and jumped on a call to walk through the methodology together. They patched it within a few days and confirmed the fix on retest. It came back as a Critical. The write-up does not describe the patch itself.
Variants to test
- Any
fields,select,sortororderparameter that names columns. Send a column that cannot exist and look for a database error naming it, or for the query being echoed back. A positive result is an error such ascolumn member.zzz does not existor a response containing the assembledSELECT. - Identifier positions behind a fixed table prefix. Try
token,role FROM secrets AS memberstyle payloads where the app prependstable.to your input. A positive result is rows from a table you did not name in the original query. - Schema enumeration through the same parameter. Try
table_name FROM information_schema.tables AS member. A positive result is a list of table names. - Tenant-selecting headers such as
X-Tenant-Id. Harvest the value from the application's own requests and replay it against other hosts sharing the backend. A positive result is the same endpoint responding under a different tenant. - Leaked
NEXT_PUBLIC_blocks in client-side JavaScript. Check whether a token that returns 401 on one host returns a different error, such as a tenant lookup failure, on another. A positive result is an error that shows authentication already succeeded.
What happened, in plain words
A security researcher was scrolling through short videos on his phone when an advert for an Indian direct-to-consumer (D2C) company appeared. D2C simply means a brand that sells straight to customers online rather than through shops. He was curious, so he opened the company's website to see whether anything was badly built.
The website is a modern web app. When you visit it, your browser downloads a bundle of files, including JavaScript, the programming language that runs inside the browser and makes pages interactive. Some of those files contained a secret-looking value: an API key and an API URL. An API (Application Programming Interface) is the back door a website uses to talk to its own servers: the page you see asks the API for data, and the API answers. An API key is like a membership card that the page shows to the API so the API knows the request is allowed. The URL is the address of that API.
The key was labelled with a NEXT_PUBLIC_ prefix. Next.js is a popular framework for building websites, and anything whose name starts with NEXT_PUBLIC_ is deliberately shipped to every visitor's browser. So this was not a secret that had leaked by accident in the usual sense: it was a value the developers chose to make public. The researcher's question became whether that public value was more powerful than it should be.
He tried the key against the API and got an error that was not the one he expected. Instead of "you are not allowed in", the server said it could not find the right database for a tenant called target. A tenant, in this context, is one customer organisation on a shared platform: the same software serves many companies, and each company's data lives in its own database. The error told him the key had passed the identity check, and the server only needed to know which tenant's database to use.
He could not guess the tenant name, so he moved to a company the target had acquired, on the theory that acquired brands often run on the same servers and the same code. There he found an endpoint (a specific address on the API that does one job) that returns a member's first name and email address. The endpoint accepted a fields parameter, which is a way for the caller to say which pieces of information they want back. He signed up for a normal account, found his own member id, and combined the old key with a tenant id he spotted in the acquisition's own network traffic. It worked, and returned his own details.
That alone is not a security bug: you are allowed to see your own name and email. The interesting part was the fields parameter. He sent it a column name that could not possibly exist, and the server replied with an error that included the exact database query it had built. That showed his input was being pasted straight into the query as a column name. From there he worked out how to make the query read a different table entirely, pulled out an authentication token and a role, then listed the database's own catalogue of tables. Because the tenant id header chose which database was used, the same flaw existed for every tenant on that backend.
He stopped as soon as the injection was confirmed, wrote everything up and sent it to the company's CTO (Chief Technology Officer, the senior executive responsible for technology). The team replied quickly, held a call to go through the method, patched it within a few days and confirmed the fix on a retest. It was rated Critical.
Who found it and how the story starts
Akash Sundaramoorthi, a 20 year old bug hunter, was scrolling through reels when an ad for an Indian D2C company appeared. Curious, he decided to poke around the company's website. The feature that mattered was a member lookup endpoint that returned a member's first name and email address, with the caller choosing which columns came back through a fields parameter.
A few of those words deserve unpacking before we go further.
- Front end: the part of the website that runs in your browser. It draws the page and reacts to clicks.
- API gateway: a single front door that sits in front of many internal services. Your browser talks to the gateway, and the gateway decides which internal service should answer. Think of a hotel reception desk: you never walk into the kitchen yourself, you ask reception and they route the request.
- Endpoint: one specific address on that API that performs one job, such as "look up a member".
- Parameter: a named value you attach to a request, like the
fieldspart of a URL. It is how you tell the endpoint what you want. - Column: a named field in a database table. If a table is a spreadsheet, columns are the headings (name, email, role) and rows are the individual records.
The write-up is his first, and it covers a chain that started with a leaked NEXT_PUBLIC_ environment block and ended in SQL injection across every tenant on the backend. SQL injection means tricking a database into running commands the developer never intended, by slipping extra instructions into a place where the developer expected only data. "Blind" means the attacker does not see the raw results directly in the page, but can still infer or extract information through the responses.
Setup
No special accounts or tooling beyond the usual were needed. The researcher began with subdomain enumeration, waybackurls and some JavaScript analysis. He later signed up for an ordinary account on one of the company's acquisitions to obtain his own member id, and replayed requests in Burp. The final exploit combined a leaked API token from the parent site's client-side JavaScript with a tenant id harvested from the acquisition's traffic.
Those tools and terms, from zero:
- Subdomain enumeration: finding all the smaller addresses under a company's main domain, such as
shop.example.comorapi.example.com. Each one is a separate door and may be built differently. - waybackurls: a tool that fetches old URLs that have been archived by the Internet Archive over the years. Old pages sometimes still exist on the live server and reveal forgotten features.
- JavaScript analysis: reading the code your browser downloads, looking for addresses, keys and hidden features. The browser has to be able to read it, so you can too.
- Burp: Burp Suite, a tool that sits between your browser and the website so you can pause a request, change it, and send it again. It is the standard workbench for this kind of testing.
- Replaying a request: sending the same request again, usually with a small change, to see how the server reacts.
- Token: a string of characters that acts like a temporary password or a stamped hand at a venue. Whoever holds it is treated as allowed, so a leaked token is dangerous.
- Harvested: collected from something already in front of you, in this case the application's own network traffic, rather than guessed.
Finding it
The initial recon turned up nothing. Then, out of habit, he opened the page source and found a NEXT_PUBLIC_ env block with an API key and API URL baked directly into the HTML.
"Page source" is what you see when you right-click a page and choose to view its source: the raw text the server sent, including the scripts the browser will run. "Env block" means a group of environment variables, which are settings passed into an application at startup. In Next.js, any setting whose name begins with NEXT_PUBLIC_ is copied into the browser bundle on purpose, because the front end needs it. The catch is that every visitor can read it.

Figure 1: Client-side JavaScript exposing NEXT_PUBLIC_ environment variables, including a publicly accessible API endpoint and token.*

He tried the token against the gateway:
curl -s https://api.target.in \ -H "Authorization: Bearer <LEAKED-TOKEN>"
Line by line:
curlis a command-line tool for sending web requests. It is the same kind of request your browser sends, just typed out.-smeans silent: do not print progress noise, only the response.https://api.target.inis the address being called.target.instands in for the real company domain.\at the end of a line means the command continues on the next line.-Hadds a header. Headers are extra pieces of information attached to a request, like the label on a parcel.Authorization: Bearer <LEAKED-TOKEN>is the standard way to present a token. "Bearer" means "whoever bears (carries) this token is authorised".<LEAKED-TOKEN>is a placeholder for the value found in the page source.
Instead of the expected 401, the response was a 400:
{"message":"Failed to connect to tenant database: BadRequestException: Tenant not found: target","statusCode":400,"timestamp":"2026-06-25T20:44:54.652Z","path":"/"}
Line by line:
- The whole thing is JSON, a text format for structured data. Curly braces hold an object, and each
"name": valuepair is one field. messageis the human-readable explanation: it failed to connect to a tenant database because the tenanttargetwas not found.statusCode: 400is the numeric HTTP status. HTTP status codes are the server's short answer: 200 means fine, 401 means "you are not authenticated", 403 means "authenticated but not allowed", 400 means "your request was malformed or could not be processed".timestampis when the error happened.pathis which part of the API was requested, here the root/.
That distinction mattered. A 401 would have meant the key was dead. A 400 complaining about a tenant database meant the key had already cleared authentication, and the gateway simply did not know which database to point it at. It had guessed the tenant name target from the hostname.
Why does that matter so much? Because it separates two questions that are easy to confuse: "are you allowed in?" and "which data do you want?". The key answered the first question correctly. Only the second was missing. A dead key would have been refused at the door; this key was already inside the building, just standing in the lobby unsure which floor to visit.
He spent the next few hours guessing the right tenant value and watching the site's own network calls for a hint. Nothing worked, and he thought it was a dead, rotated key. "Rotated" means the company replaced it with a new value, which is what a responsible team does when a key may have leaked. He moved on to one of the company's acquisitions, on the reasoning that acquisitions often share the same backend and infrastructure as the parent.
He ran the same recon on the acquisition and fed the JavaScript files to Claude, asking it to extract every API route and endpoint. One stood out:
/api/member?id=<id>&fields=given_name,email_addr
Line by line:
/api/memberis the endpoint: the member lookup feature.?starts the query string, the part of a URL that carries parameters.id=<id>says which member to look up.<id>is a placeholder for a real member id.&separates one parameter from the next.fields=given_name,email_addrasks for two columns: the given (first) name and the email address. The comma separates the requested columns.
He signed up for an account, grabbed his own id and hit the endpoint. It returned a 401. Digging through the JavaScript and replaying requests in Burp, he found a call carrying X-Tenant-Id: brand-name. He dropped that tenant id into his curl command and got another 401.
X-Tenant-Id is a custom header. Custom headers are simply headers the developers invented for their own use; the X- prefix is a long-standing convention for non-standard ones. This one tells the gateway which tenant's database to use. brand-name is a placeholder for the real value.
At that point the key and the tenant id looked like two separate dead ends. Then he realised they were two halves of the same lock: the API key did not need a tenant name, it needed a tenant id, and he now had one.
This is the central lesson of the whole story. Neither half was enough. The key proved identity but could not choose a database. The tenant id chose a database but proved nothing. Together they opened the door. In everyday terms: one person holds the key to the building, another knows which flat is yours, and neither can get in alone.
Exploitation
Step 1: combine the leaked token with the tenant id
curl -s https://api.acquisition.com/api/member?id=<my_id>&fields=given_name,email_addr \ -H "X-Tenant-Id: brand-name" \ -H "X-Api-Token: <LEAKED-TOKEN>"
Line by line:
curl -ssends the request quietly, as before.https://api.acquisition.com/api/memberis the member endpoint on the acquisition's API.id=<my_id>asks for the researcher's own member record.fields=given_name,email_addrasks for just the first name and email address.-H "X-Tenant-Id: brand-name"tells the gateway which tenant database to use.-H "X-Api-Token: <LEAKED-TOKEN>"presents the leaked key, this time under the header name the acquisition's own code uses.
The request sends the leaked token as X-Api-Token and the harvested tenant id as X-Tenant-Id. It returned his own data. On its own that is not a vulnerability, since it only exposed his own details. The interesting part was the fields=given_name,email_addr parameter: the endpoint let the caller name the columns it wanted back.
Why is that interesting? Because a normal, safe design would offer a fixed menu: "you may have the name and the email, nothing else". Here the caller writes the column names themselves. That means the caller's text has to be placed somewhere in the database instruction, and wherever user text is placed, the question is whether it is treated as data or as instructions.
Step 2: probe the fields parameter with a non-existent column
GET /api/member?id=<my_id>&fields=zzzX-Tenant-Id: brand-nameX-Api-Token: <LEAKED-TOKEN>
Line by line:
GETis the HTTP method, meaning "fetch this". It is what your browser uses when you open a page./api/memberis the endpoint.id=<my_id>is the researcher's own member id.fields=zzzasks for a column calledzzz, which does not exist. This is the deliberate probe: send something that cannot be valid and watch how the server complains.- The rest of the line,
X-Tenant-Id: brand-nameX-Api-Token: <LEAKED-TOKEN>, is the tenant id and token headers written into the same line as the URL. In the write-up they are shown this way rather than as separate-Hoptions.
The server responded with the error and, crucially, the query it had built:
{ "error": "column member.zzz does not exist", "query": "SELECT member.zzz FROM member WHERE member.id = <my_id>"}
Line by line:
errorsays the columnmember.zzzdoes not exist. Themember.part is a table name followed by a dot, the standard way to say "this column, in this table".queryis the actual database instruction the server ran. This is the gift: the server is showing its working.SELECT member.zzzmeans "return the column zzz from the member table".FROM membersays which table to read.WHERE member.id = <my_id>restricts the result to one row, the one whose id matches.
Two things stood out. The input zzz had gone straight into the SQL as a column name, untouched. And the server echoed back the exact query it built, so the injection point was visible:
SELECT member.<MY_INPUT> FROM member WHERE member.id = <my_id>
Line by line:
SELECTbegins a database query and is followed by the list of things to return.member.<MY_INPUT>is where the researcher's text lands, behind a fixedmember.prefix. The prefix is glued on by the application, not typed by the user.FROM memberis the table being read.WHERE member.id = <my_id>is the filter that picks one row.
SQL is the language used to talk to relational databases, which store data in tables of rows and columns. Column names are identifiers, not values, and prepared statements can only parameterise values. A prepared statement is the standard defence: the developer writes the query with blanks, and the database fills the blanks with data in a way that can never be reinterpreted as instructions. It works because the shape of the query is fixed before any data arrives. But you cannot put a column name in a blank, because the database needs to know the shape of the query in advance. A query that lets the caller pick columns by name almost always means the code is concatenating strings by hand with no escaping. That is what this was: the input was dropped into the SELECT list behind a fixed member. prefix.
A useful comparison: a prepared statement is like a form with boxes. Whatever you write in a box stays in the box. String concatenation is like letting a visitor write on the form itself, so they can add new questions, cross out existing ones, or write instructions in the margin.
Step 3: why the classic payloads failed
He reached for OR 1=1 and a quick subquery. Both failed instantly. Those payloads assume injection into a WHERE clause, where the attacker supplies a value that can be twisted into a condition:
SELECT * FROM member WHERE id = [INJECTION HERE] β OR 1=1 works here
Line by line:
SELECT *means "return every column".FROM memberis the table.WHERE id = [INJECTION HERE]is the filter, and the marker shows where attacker text would land.OR 1=1is the classic trick: if the filter becomesid = 0 OR 1=1, the second half is always true, so every row matches. It works because the attacker is supplying a value that can be turned into a condition.
His injection point was the column list right after SELECT, where the database expects an identifier, not a value:
SELECT member.[INJECTION HERE] FROM member WHERE id = <my_id> β OR 1=1 is meaningless here
Line by line:
SELECT member.[INJECTION HERE]shows the text landing where a column name belongs.FROM member WHERE id = <my_id>is the rest of the query, unchanged.OR 1=1is meaningless here because there is no condition to flip. The database is not asking "is this true?", it is asking "which column do you want?".
There is no condition to flip and no quote to escape. The app also silently prefixed whatever he sent with member., so a subquery such as (SELECT token FROM secrets LIMIT 1) became member.(SELECT..., which is garbage to the parser. A subquery is a query nested inside another query. LIMIT 1 means return at most one row. The parser is the part of the database that reads the query and checks it makes grammatical sense; member.( does not.
Rather than write the bug off as unexploitable, he asked what is actually valid right after SELECT member.. That reframing is the turning point. Instead of forcing a familiar attack into an unfamiliar place, he asked what the database would accept in that exact position.
Step 4: defeat the prefix by re-aliasing member
The member. prefix could not be deleted, so he changed what member pointed at. By rewriting the FROM clause and aliasing a different table back to the name member, member.<anything> resolves against that other table:
fields=token,role FROM secrets AS member
Line by line:
fields=is the parameter being abused.token,roleare the two columns he wants, from a table he is not supposed to read.FROM secretsstarts a newFROMclause naming a different table,secrets.AS membergives that table the nicknamemember. An alias is a temporary name used inside one query. So from now on,member.tokenmeans "the token column of the secrets table".
The server assembled:
SELECT member.token, member.roleFROM secrets AS member
Line by line:
SELECT member.token, member.roleis the application's own opening, with the researcher's text inserted.FROM secrets AS memberis the researcher's text continuing.- Notice
roleFROM: the application's text and the researcher's text have run together with no space. The database would normally reject that, which is why the next step matters.
The app's own trailing FROM ... WHERE ... is commented out, leaving:
SELECT member.token, member.role FROM secrets AS member
Line by line:
--starts a comment in SQL: everything after it on that line is ignored by the database.- The space and dash after it (
-- -) are a common way to make sure the comment is recognised even when the surrounding text is glued together. - With the application's trailing
FROM member WHERE ...commented out, the onlyFROMleft is the researcher'sFROM secrets AS member. - The result is a clean query that reads two columns from the
secretstable.
The prefix that had blocked him now pointed at a table he was never supposed to see, and the response was:
{ "rows": [["tok_demo_INVENTED_0000", "admin"]] }
Line by line:
rowsis the list of result rows.- The outer square brackets hold the list of rows; here there is one row.
- The inner square brackets hold that row's values in column order: first the token, then the role.
"tok_demo_INVENTED_0000"is the token value shown in the write-up, and"admin"is the role.
An auth token and a role came out of an endpoint that is only supposed to return a name and an email. An auth token is the credential a logged-in user carries; anyone holding it can act as that user. A role says what that user is allowed to do, and admin is the highest level.
Step 5: enumerate the schema
The same trick, aimed at the database catalogue instead of a guessed table name:
fields=table_name FROM information_schema.tables AS member
Line by line:
fields=table_nameasks for a column calledtable_name.FROM information_schema.tablespoints at a built-in catalogue.information_schemais a standard set of views that every relational database exposes about itself;tableslists every table in the database.AS memberagain gives that catalogue the nicknamemember, so the application'smember.prefix resolves against it.
It listed the tables. From there he could walk every table and every column and reach just about anything in the database, all through one fields parameter on an endpoint meant to return a first name. "Enumerate" means to list things one by one. "Schema" means the structure of the database: which tables exist and which columns each one has. Once you know the schema, you know where everything worth taking lives.
Root cause
The fields parameter was concatenated directly into the SELECT list, behind a fixed member. prefix, with no escaping. Escaping means treating special characters in user input as plain text rather than as instructions. Because column names are identifiers rather than values, prepared statements cannot parameterise them, so the usual defence did not apply here. The server also echoed the constructed query in its error response, which made the injection point and the query shape immediately visible. The X-Tenant-Id header meant the same injection point worked across every tenant on that backend, including the parent company and its other brands sharing the infrastructure.
In short, three separate weaknesses stacked up: user text was pasted into the query, the error message showed the query, and one shared backend served every tenant. Any one of them alone would be a problem. Together they turned a name-and-email lookup into a way to read the whole database.
Impact
The injection was not scoped to his account or to one company. Through the X-Tenant-Id header the same vulnerable fields parameter worked across every tenant on that backend, including the parent company and its other brands sharing the same infrastructure. He could walk every table and every column, including auth tokens and roles, from an endpoint that should only return a first name and an email address. One vulnerable parameter, multiplied across every customer the platform ran.
Why are auth tokens and roles so serious? Because a token lets you act as a user without knowing their password, and a role tells you how much that user can do. Reading both from a shared table means an attacker could potentially act as that user, including an administrative one. The researcher did not go further than confirming the flaw.
Once the injection was confirmed he stopped immediately, wrote up the full findings and sent the report directly to the CTO. Stopping at confirmation is the responsible approach: prove the bug exists, do not rummage through real customer data.
Fix
The team responded quickly and jumped on a call to walk through the methodology together. They patched it within a few days and confirmed the fix on retest. It came back as a Critical. The write-up does not describe the patch itself.
"Critical" is the top severity rating in most bug bounty programmes, meaning the issue could cause severe damage and should be fixed immediately. A retest means the researcher tried the same attack again after the fix and confirmed it no longer worked.
Variants to test
These are the same ideas generalised, so a beginner can look for similar bugs elsewhere. Each one lists what to send and what a positive result looks like.
- Any
fields,select,sortororderparameter that names columns. Send a column that cannot exist and look for a database error naming it, or for the query being echoed back. A positive result is an error such ascolumn member.zzz does not existor a response containing the assembledSELECT. - Identifier positions behind a fixed table prefix. Try
token,role FROM secrets AS memberstyle payloads where the app prependstable.to your input. A positive result is rows from a table you did not name in the original query. - Schema enumeration through the same parameter. Try
table_name FROM information_schema.tables AS member. A positive result is a list of table names. - Tenant-selecting headers such as
X-Tenant-Id. Harvest the value from the application's own requests and replay it against other hosts sharing the backend. A positive result is the same endpoint responding under a different tenant. - Leaked
NEXT_PUBLIC_blocks in client-side JavaScript. Check whether a token that returns 401 on one host returns a different error, such as a tenant lookup failure, on another. A positive result is an error that shows authentication already succeeded.
Glossary
- Alias: a temporary nickname given to a table inside one query, so it can be referred to by a shorter or different name.
- API (Application Programming Interface): the set of addresses and rules a website uses to ask its servers for data or actions.
- API gateway: a single front door in front of many internal services that routes each request to the right one.
- API key / API token: a string that acts like a membership card, proving a request is allowed.
- Auth token: a credential issued after login that lets the holder act as that user without re-entering a password.
- Blind SQL injection: SQL injection where the attacker does not see raw query results directly and must infer them from responses.
- Burp (Burp Suite): a tool that intercepts, inspects, edits and replays web requests between a browser and a server.
- Column: a named field in a database table, like a heading in a spreadsheet.
- Concatenation: joining strings end to end. In code, gluing user input into a query is what creates injection bugs.
- Critical: the highest severity rating, meaning the issue could cause severe damage and needs immediate fixing.
- CTO (Chief Technology Officer): the senior executive responsible for a company's technology.
- curl: a command-line tool for sending web requests.
- Custom header: a header invented by the developers for their own use, conventionally prefixed with
X-. - D2C (direct-to-consumer): a brand that sells straight to customers online rather than through shops.
- Endpoint: one specific address on an API that performs one job.
- Enumeration: listing things one by one, such as subdomains, endpoints or tables.
- Environment variables: settings passed into an application at startup.
- Escaping: treating special characters in user input as plain text rather than as instructions.
- Fields parameter: a parameter that lets the caller name which columns they want back.
- Front end: the part of a website that runs in the browser and draws the page.
- GET: the HTTP method meaning "fetch this", used when a browser opens a page.
- Header: extra information attached to a request or response, like a label on a parcel.
- HTTP status code: the server's short numeric answer, such as 200 (fine), 400 (bad request), 401 (not authenticated) or 403 (not allowed).
- Identifier: a name in a database, such as a table or column name, as opposed to a value stored in a row.
- information_schema: a standard built-in catalogue that a relational database exposes about its own tables and columns.
- JavaScript: the programming language that runs in the browser and makes pages interactive.
- JSON: a text format for structured data, using curly braces for objects and square brackets for lists.
- Next.js: a popular framework for building websites, which copies any
NEXT_PUBLIC_setting into the browser bundle. - Parameter: a named value attached to a request, such as the
fieldspart of a URL. - Parser: the part of a database that reads a query and checks it is grammatically valid.
- Payload: the text an attacker sends in the hope of changing how a query behaves.
- Prepared statement: a query written with blanks that are filled with data in a way that cannot be reinterpreted as instructions. It can parameterise values, not identifiers.
- Query: an instruction sent to a database, usually written in SQL.
- Recon (reconnaissance): the information-gathering phase before testing, such as finding subdomains and reading JavaScript.
- Relational database: a database that stores data in tables of rows and columns.
- Retest: trying the same attack again after a fix to confirm it no longer works.
- Role: a label that says what a user is allowed to do, such as
admin. - Rotated: replaced a credential with a new value, typically after a suspected leak.
- Row: one record in a database table.
- Schema: the structure of a database: which tables exist and which columns each has.
- SQL (Structured Query Language): the language used to talk to relational databases.
- SQL injection: tricking a database into running unintended instructions by slipping them into a place meant for data.
- Subdomain enumeration: finding all the smaller addresses under a company's main domain.
- Subquery: a query nested inside another query.
- Tenant: one customer organisation on a shared platform, whose data lives in its own database.
- Token: a string that acts like a temporary password; whoever holds it is treated as allowed.
- waybackurls: a tool that fetches old URLs archived by the Internet Archive, which can reveal forgotten features.
- WHERE clause: the part of a query that filters which rows are returned.