Level 2 · 2A Permissions and roles · Lesson 2 of 2
Anything in the browser can be changed
Anything that comes from the browser can be written by the person using it: hidden buttons, data in the address, form fields, local storage. Hiding a "Delete users" button protects nothing, because the attacker sends the request directly, without going through the button.
The most common flaw: the number snooper
If the address says /pedido/1042 (pedido means order) and the server doesn't check whose order that is, someone changes the number to 1043 and sees another person's. It's called IDOR (insecure direct object reference) and it's one of the most frequent flaws.
A different flaw is deciding permissions with data the browser sends, like ?es_admin=false ("is admin = false"): changing it to true is the first thing an attacker tries. That's not an IDOR: it's called privilege escalation, because the person gives themselves more permissions than they have.
What a good guard does
Every time a request arrives, the server always follows the same order: it identifies who you are from your session, checks what role and permissions you have, confirms that the requested data is yours or that you have permission over it, and only then performs the action or returns the data. Skipping a step opens a hole.
Going deeper
IDOR in code
// BAD: returns whatever order the address asks for, no matter whose it is
app.get("/pedido/:id", async (pedido) => {
return await buscarPedido(pedido.params.id);
});
// GOOD: returns it only if it belongs to the person asking
app.get("/pedido/:id", async (pedido) => {
const p = await buscarPedido(pedido.params.id);
if (!p || p.usuarioId !== pedido.usuario.id) return noEncontrado();
return p;
});- In the bad version, changing the number in the address shows other people's orders.
- In the good one, the server compares the order's owner (usuarioId) with the person who is logged in.
- Return "not found" (noEncontrado) both when it doesn't exist and when it belongs to someone else: that way you don't confirm to anyone which numbers exist.
Review questions
A website hides the "Delete users" button from people who aren't administrators, but the server doesn't check anything. Is it safe?
Answer: No: anyone can send the request without using the button. Hiding something on the screen isn't protecting it. The server has to do the check on every request.
In the address /factura/1042 (factura means invoice) you change the number to 1043 and see another person's invoice. What flaw is this?
Answer: An IDOR: the server doesn't check whose data it is. The server must check that the requested data belongs to the person asking, not trust the number in the address.
Where should permissions always be checked?
Answer: On the server. Whatever runs in the browser can be changed by the person using it. The server is the only place you can trust.