Descrizione
Authorization Bypass Through User-Controlled Key (CWE-639) in the cart and wishlist repositories of MarcosCamara01 Ecommerce Template allows any authenticated user to delete and modify the cart and wishlist rows of any other user, because cartRepository.delete(), cartRepository.updateQuantityInternal() and wishlistRepository.delete() in src/lib/db/drizzle/repositories/ match rows by primary key alone, with no predicate on the owning user, and the per user authorization for those three operations rests on PostgreSQL row level security. The migrations run ALTER TABLE ... ENABLE ROW LEVEL SECURITY and create policies comparing app.current_user_id() with user_id, but never ALTER TABLE ... FORCE ROW LEVEL SECURITY, and PostgreSQL does not apply policies to the role that owns a table. The template uses one DATABASE_URL both to run the migrations, which create the tables, and for the application at runtime, so the application connects as the owner of the tables and the policies do not apply to it. cart_items.id and wishlist.id are sequential bigserial values, so the identifiers of rows belonging to other users can be enumerated, and the update path returns the modified row, which carries the identifier of the user it belongs to. This results in the destruction and modification of cart and wishlist contents belonging to other accounts of the installation.
Tipo di vulnerabilità
CWE-639
Aggiramento dell’autorizzazione tramite una chiave controllata dall’utente (IDOR)
Il controllo delle autorizzazioni non impedisce a un utente di accedere ai dati o ai record di un altro semplicemente cambiando l’identificativo che li richiama.
Impatto sui sistemi
| Ambito | Impatto |
| Controllo degli accessi |
Aggirare i meccanismi di protezione È possibile aggirare i controlli di accesso su dati o funzioni specifici di un utente. |
| Controllo degli accessi |
Ottenere privilegi o assumere un’altra identità È possibile un’escalation orizzontale dei privilegi: un utente può vedere o modificare le informazioni di un altro. |
| Controllo degli accessi |
Ottenere privilegi o assumere un’altra identità È possibile un’escalation verticale dei privilegi se la chiave controllata dall’utente è in realtà un indicatore del ruolo di amministratore: l’attaccante ottiene così l’accesso amministrativo. |
Come si previene
Architettura e progettazione
Per ogni accesso ai dati, verifica che l’utente abbia i privilegi necessari per accedere al record richiesto.
Architettura e progettazione · Sviluppo
Assicurati che la chiave usata per cercare il record di un utente non possa essere controllata dall’esterno, o che ogni manomissione venga rilevata.
Architettura e progettazione
Usa la cifratura per rendere più difficile indovinare altri valori validi della chiave, oppure associa alla chiave una firma digitale, così che il server possa verificare che non sia stata manomessa.
Tutte le 3.543 CVE di tipo CWE-639, con andamento e prevenzione