The lab
here is how portswigger describes it
The product category filter for this lab is powered by a MongoDB NoSQL database. It is vulnerable to NoSQL injection. To solve the lab, perform a NoSQL injection attack that causes the application to display unreleased products.
the new pieces in this lab#
since this is our first NoSQL lab, a short introduction.
- a NoSQL database stores data without the rigid tables of a traditional SQL database. MongoDB is the most common one, it stores JSON-like documents and is queried with structured objects rather than SQL text.
- NoSQL injection is the NoSQL equivalent of SQL injection: the app builds a database query by inserting our input, and if it does so unsafely, we can change what the query does rather than just what it searches for. with MongoDB there are two flavours:
- operator injection, smuggling MongoDB query operators like
$ne,$gt,$whereinto a JSON request (we'll meet this in later labs). - syntax / JavaScript injection, when the app concatenates our input into a query string that is then evaluated, often as JavaScript (MongoDB can run JS in
$whereclauses and similar). that is this lab: ourcategoryvalue is dropped into a JS expression, so we can inject JavaScript operators.
- operator injection, smuggling MongoDB query operators like
- detection is the goal here, not full exploitation. we're learning the probes that reveal an injection point: break the syntax, then confirm we can steer the query's logic with boolean conditions.
the method: a
'causes a JS syntax error (input isn't sanitised), a balanced payload avoids the error (confirming server-side injection), and then boolean conditions, false, true, and always-true, let us control the result set, ending with a condition that returns everything, including unreleased products.
why the unsanitised input is injectable#
the flaw is that our category value is concatenated directly into a server-side expression that MongoDB evaluates, with our input treated as code, not just data. the query is built roughly as '<our input>', a quoted string inside a larger JavaScript condition. because the quote we supply isn't escaped, we can close that string and append our own JavaScript, boolean operators, extra conditions, anything the evaluator will run. the app can no longer tell our data apart from the query's own syntax. detecting this is a matter of poking the boundary: a lone quote unbalances the expression and errors; a balanced payload runs cleanly; and once we can inject &&/|| conditions, we own the filter's logic and can force it to return rows it would normally hide.
Step 1 - capture the filter request#
we access the lab and click a product category filter. in Proxy > HTTP history we right-click the category filter request and Send to Repeater.

Step 2 - break the syntax with a quote#
in Repeater we submit a single ' in the category parameter. this causes a JavaScript syntax error, which indicates our input isn't being filtered or sanitised, it is landing inside a JS expression.

Step 3 - confirm injection with a balanced payload#
we submit a valid JavaScript payload that balances the quotes:
Gifts'%2b'
(%2b is a URL-encoded +, so server-side this reads 'Gifts'+'', a harmless string concatenation.) this causes no syntax error, confirming a form of server-side injection is occurring, our input is being evaluated as code.

Step 4 - inject a false boolean condition#
we test whether we can change the response with boolean logic. we insert a condition that is always false (URL-encode the payload):
Gifts' && 0 && 'x
no products are retrieved.
why this payload works. the server builds its query by wrapping our input in quotes, roughly '<input>'. dropping our payload in makes the evaluated expression:
'Gifts' && 0 && 'x'
our leading ' closes the string the server opened ('Gifts'), our trailing 'x pairs with the server's closing quote to make a valid string 'x', so the whole thing stays syntactically valid. in between we've injected a JavaScript boolean chain. JavaScript's && returns the first falsy value (or the last value if all are truthy):
'Gifts'is a non-empty string → truthy0is → falsy so'Gifts' && 0short-circuits to0, and0 && 'x'is0. the condition evaluates to false, the filter matches nothing, and no products come back. this proves our injected logic actually controls the query, not just the search term.

Step 5 - inject a true boolean condition#
we insert an always-true condition instead:
Gifts' && 1 && 'x
now 'Gifts' && 1 && 'x' evaluates with 1 (truthy) in the middle, so the chain resolves to the last truthy value and the condition is true. products in the Gifts category are retrieved. the false-returns-nothing / true-returns-results contrast confirms boolean injection works.

Step 6 - force an always-true condition#
we submit a condition that always evaluates to true, regardless of the category:
Gifts'||1||'
here || returns the first truthy value: 'Gifts' || 1 || '' is true no matter what, so the filter matches every product, not just the Gifts category.

Step 7 - confirm unreleased products appear#
we verify the response now contains unreleased products, the always-true condition bypassed the category filter entirely and returned everything the database holds.

with this, the lab is solved!
