Menu

Your Order Lookup Passed the Email Straight to MongoDB and Someone Sent an Object Instead
📰

Your Order Lookup Passed the Email Straight to MongoDB and Someone Sent an Object Instead

DEV Community: mongodb·Serguey Asael Shinder·6 days ago
#4sbL9KtY
#devtomongodb#devto#dev#order#email
Long article (306 words) — no AI summary yet.
Reading 0:00
15s threshold

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…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.