Menu

Soft delete adds a trash page and a restore button. Do they get the same permission checks as the rest of your API?
📰

Soft delete adds a trash page and a restore button. Do they get the same permission checks as the rest of your API?

DEV Community: backend·Auth By Example·17 days ago
#N4z3UlbP
#devtobackend#devto#dev#restore#tenant
Reading 0:00
15s threshold

Most apps I've worked on move to soft delete at some point. A deleted_at column goes on the table, the default scope hides those rows, and a sprint later someone adds a Trash page with a restore button. That last step is where I keep finding authorization gaps.

The first one is the tenant filter. The normal read path goes through a scope that filters by tenant and hides deleted rows. The trash page needs the deleted rows, so someone reaches for Document.unscoped (or whatever your ORM calls it). In Rails, unscoped drops every default scope, so if the tenant filter lived in the same default_scope as deleted_at IS NULL , it's gone too. The trash list now shows deleted documents from every tenant, and nobody notices because in dev there's only one.

The second one is restore. It usually gets a role check like "editors can restore", which says nothing about whether this editor could ever see this document.…

Continue reading — create a free account

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