← Tips

OWASPA06Insecure Design

Two People Posted. One Post Vanished.

When your whole app lives in one database row, two people saving at the same time overwrite each other. No error, no bug in the code, and it gets worse the more people use your app.

Watch on YouTube

The mistake

Two people have my demo app open. Maria on the left, Dev on the right. Both loaded the same board.

Maria posts. Her app takes its copy of the whole board, adds her post, and saves it. Then Dev posts. But Dev's copy is from before Maria posted. His app adds his post to his old copy and saves the whole thing.

Refresh both windows. Dev's post is there. Maria's is gone.

No error, no bug

Nothing in the code is broken. That's just what happens when two people rewrite the same box at the same time. The last one saved wins. And the more people use your app, the more often it happens, so it gets worse as you succeed.

The fix

The two-window test

  • Open your app in two browser windows, signed in as two different accounts.
  • Load the same page in both.
  • Post from the first window. Then post from the second, without refreshing it.
  • Refresh both. Are both posts there?

If one is missing, your app is probably saving everything as one big object. The fix is to give each post its own row, so posting adds one row and touches nothing else. The full walkthrough is in the video: One Bad Save Deleted My Entire App

The app in this tip is my own demo, built with fake data and intentionally insecure.