← All articlesWeb security

How to Validate Document State Transitions on the Server

If a document must be reviewed before approval, the server must enforce that sequence. Hiding a button in the interface does not replace checking the current state when an API request arrives. We will use an entirely fictional workflow with our own synthetic documents to define a transition table, specify handler behavior, and verify the outcome by reading the stored state. The goal is to confirm that the required step cannot be skipped in this particular workflow.

Where the Trust Boundary Lies

A REST API can represent a business process as a sequence of endpoints: document creation, review, and approval. Authentication and authorization at each endpoint may not, by themselves, detect a violation of that sequence. A user may have permission to approve documents while a particular document has yet to complete the required step.

The interface helps users follow the workflow, but the server must not treat an available button as proof that the preceding step was completed. A request expresses the desired action; the server decides whether the transition is allowed based on the current stored state. In our example, user permissions are treated as a separately implemented prerequisite and checked on every request.

A Transition Table for One Entity

Consider a fictional approval workflow for a training application. All documents and their contents are synthetic, and the API belongs to the team performing the checks. A document has three states: ‘draft’, ‘reviewed’, and ‘approved’. Creation sets the initial state to ‘draft’; after that, this training model allows only two transitions. The following entries form its table: current state, target state, and decision.

In particular, the ‘draft → approved’ transition is prohibited. Returning to an earlier step and transitioning to the same state again are also unsupported here. These are the chosen rules for this fictional example: teams must explicitly define their own transition tables for their documents instead of automatically adopting these restrictions.

  • Draft → reviewed: allow the review step.
  • Reviewed → approved: allow approval.
  • Any other pair of states: reject the transition in this training model.

What the Server Handler Should Do

Before changing the state, the handler reads the document’s current stored state, determines the target state for the requested action, and checks that pair against the table. For an allowed pair, it performs the corresponding transition. For a pair absent from the table, it rejects the request with a clear error, such as: ‘Approval unavailable: the document must be reviewed first.’

Apply this check to every request that performs a workflow step. A check in the handler for the required step does not establish that the approval handler enforces the sequence. In our example, approval must be allowed only from the ‘reviewed’ state. When a request is rejected, the expected behavior is to preserve the document’s previous state; verify this separately by reading the result.

Positive Control: Complete the Entire Workflow

The following are original proposed defensive tests, not an official OWASP procedure. Run them sequentially, only in your own test API and with synthetic documents. For the positive control, create a document named ‘Training-A’ and read it in a separate request: its initial stored state should be ‘draft’.

Perform the document review required by the workflow, then read its state again. The acceptance criterion for this step is ‘reviewed’. After requesting approval, perform another read: the expected state is now ‘approved’. A successful HTTP response is insufficient: it does not, by itself, prove that the intended change was saved.

Negative Test: Skip the Required Review

Create a separate synthetic document named ‘Training-B’ and confirm its ‘draft’ state by reading it. Using the same test-user permissions established beforehand, request approval while skipping the required review. Expect the server to reject the request with a clear explanation that the transition is not allowed.

After the rejection, read the document separately. The test passes only when both outcomes are observed: the server rejected the transition, and the stored state remained ‘draft’. An error response alone does not confirm that the state was preserved. Then perform the required review and approval on the same document, reading its state after each step. Expect ‘reviewed’ followed by ‘approved’: the rejection must not prevent completion of the intended workflow.

Fix Priorities and Completion Criteria

First, document the allowed state pairs for a single entity. Then verify that every handler for its workflow steps checks the current stored state against this table before making a change. If approval from draft succeeds, the fix must address the server’s transition decision. Changes to button visibility do not provide the required validation.

After the fix, repeat the positive scenario, the attempt to skip a step, and the return to the normal workflow. This task is complete when allowed transitions save the expected states, the prohibited transition returns a clear error and leaves the document in draft, and the subsequent correct sequence ends in approval.

What This Check Confirms

The result applies to the selected table and the sequential scenarios performed. It does not establish the correctness of all business processes or behavior under concurrent changes. This example also does not cover access to other users’ objects, payments, webhooks, GraphQL fields, HTTP methods and Content-Type, CSRF, JWT, or session lifecycles. Permission checks remain a separate prerequisite.

If you would like to examine a similar workflow in your product, you can start with a free website or web-product audit from CheckMyApp. A practical starting point for discussion is the transition table for a specific document and the observed results of checking its stored state.

Sources and documentation

  1. REST Security Cheat Sheet
  2. Authorization Cheat Sheet
CheckMyApp

Check your application’s security.

Enter your web application address and email. Get a free preliminary report and choose the depth of analysis.

Check for free