Guest checkout
needed a way
to see your order
without an account.
Order number.
Email address.
Both must match.
app.use(express.json());
app.post("/order", async (req, res) => {
const order = await orders.findOne({
number: req.body.number,
email: req.body.email,
});
...
});
The form sends two strings.
The attacker
does not use the form.
{
"number": { "$gt": "" },
"email": { "$ne": "" }
}
express.json
parses that body
into real objects.
The driver
passes them to MongoDB
as written.
And to MongoDB
an object with a dollar key
is not a value.
It is an operator.
Number greater than nothing.
Email not equal to nothing.
That matches every order
in the collection.
findOne
returns the first.
A name,
a delivery address,
what they bought.
Change the condition,
step through the range,
and the next order comes back.
And the next.
No quotes were broken.
No string was built.
Nobody concatenated anything.
That is why it gets past
people who know about
SQL injection.
The…