Skip to content

Access check runs after the write

Scan rule · RSC-SEC-064

  • Security
  • Severity: High
  • CWE-862
  • OWASP A01-2021

Compares the position of the auth call and the database write within the same function body and reports checks that happen after the write.

Why this matters

An access check only works if it can prevent the operation it is meant to protect. If it sits after the write call, the row is already in the database by the time the check runs — the abort then prevents at most the response, not the change.

The case typically arises after the fact: the function was open at first, an auth check was added later, and it landed wherever there was room — often right before the `return`, because that is where error handling lives. In review it reads as plausible, because the check is visibly there.

Check it yourself: in every function that writes, the first substantive step must be the identity check with an immediate bail-out. Nothing above it may modify data.

Scan tier

  • Source code from source maps
  • Repo access (deep scan)

How to fix it

Move the auth call and its bail-out to the top of the function, ahead of every write.

Scan your own app for free