Authorization Enforced Only in Browser Code (Open Row-Level Policies)

Illustrative example. ACME Financial is an invented company and every detail below is made up. The layout is the one our reports use.

Finding 4.1
Authorization Enforced Only in Browser Code (Open Row-Level Policies)
C1
Severity
Critical
CVSS 3.1 score
7.5High
Risk rating
Likelihood:  High
Impact:  Critical
CVSS vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
Classification
CWE-602 Client-Side Enforcement of Server-Side Security
CWE-862 Missing Authorization
A01:2021 Broken Access Control
Description
The customer portal reads its data directly from a hosted database through a generated REST interface, using a public key that ships in the JavaScript bundle. That design is safe only when the database's row-level policies restrict each customer to their own rows. Where a policy allows every row, the filter applied in the browser is the only restriction, and anyone can remove it by calling the interface directly.
Affected assets
Customer portal repository: db/migrations/0007, 0009, 0011 and 0012 (tables accounts, transactions, statements, payees)
The CVSS score rates the technical characteristics of the flaw. The severity rating also accounts for likelihood and business impact: the key needed is delivered to every visitor's browser, and the tables hold customers' banking information.

Impact

The policies allowed every row to be read, so the data of every customer was available to anyone holding the portal’s public key, which is delivered to each visitor’s browser. No account or password was required. The four tables affected hold account holders’ names, account numbers, balances, transactions, statements and saved payees.

The same policy was repeated in four migrations, which indicates a pattern in how tables are added rather than a single oversight. A table added in the same way would carry the same flaw. Within an attack chain, this finding supports large-scale collection of customer data with no prior access. Strafe assesses the likelihood as high and the impact as critical.

Technical details

Strafe reviewed the customer portal’s repository at the commit ACME Financial supplied. The accounts screen loads its data with a query that filters on the signed-in customer’s identifier. The filter is applied in the browser:

// src/features/accounts/useAccounts.ts
const { data, error } = await db
  .from("accounts")
  .select("holder, account_number, available_balance")
  .eq("customer_id", session.user.id);
The accounts query in the customer portal's source code, with the line that filters by the signed-in customer's identifier marked
Figure 1 - The ownership filter, applied in the browser Open full size

The migration that creates the table enables row-level security and then adds a policy that allows any caller to read every row, including a caller with no session:

-- db/migrations/0007_accounts.sql
alter table accounts enable row level security;

create policy "accounts are readable"
  on accounts for select
  to anon, authenticated
  using (true);
The database migration for the accounts table, with the select policy marked: it applies to the anon and authenticated roles and its condition is true
Figure 2 - The policy allows every row Open full size

The same policy text appeared in the migrations for three further tables: transactions, statements and payees. In each case the matching screen filtered by customer in the browser, as the accounts screen did.

To confirm the finding, Strafe sent one request to the staging interface with the public key from the bundle and no customer session. The response contained rows belonging to more than one customer:

GET /rest/v1/accounts?select=holder,account_number&limit=2 HTTP/2
Host: api-staging.acme-financial.example
apikey: [public key from the client bundle]

HTTP/2 200 OK
Content-Type: application/json

[{"holder":"Customer A (test account)","account_number":"0000100481"},
 {"holder":"Customer B (test account)","account_number":"0000100482"}]
A terminal request to the accounts table with the public key and no session, answered with the rows of two different customers
Figure 3 - Two customers' rows returned to a caller with no session Open full size

The request was limited to two rows from the staging database, which held test accounts only.

Remediation

  1. Replace each open policy with one that compares the row’s customer to the caller’s identity, and remove the anon role from it. For the accounts table: using (customer_id = auth.uid()), granted to authenticated only.
  2. Apply the same change to transactions, statements and payees, then review every table for a policy whose condition is true.
  3. Add a test to the build pipeline that queries each table with the public key and no session, and as one customer for another customer’s rows. The build fails if either query returns a row.
  4. Keep the filter in the browser for display only. It is not an access control.

Rotating or hiding the public key would not correct the flaw. The key is public by design; the policies are the control.

remediation.md
## C1 - Authorization enforced only in browser code

**Where:** db/migrations/0007, 0009, 0011, 0012 (policies on accounts,
transactions, statements, payees)
**Severity:** Critical (CVSS 7.5) · Likelihood High · Impact Critical

### What "fixed" means
- A query with the public key and no session returns no rows from
  any of the four tables.
- A signed-in customer receives only rows whose customer_id is
  their own, whatever filter the request carries.
- The comparison is in the database policy, not in client code.

### What does not count
- A filter in the browser or in a client-side helper.
- Rotating, shortening or obscuring the public key.

### Where else this pattern may exist
Every table created by a migration, and the storage bucket that
holds statement files. Search the migrations for "using (true)".

After the fix

StatusResolved

ACME Financial replaced the four policies. Strafe reviewed the new migration and repeated the request. The interface returned an empty list to a caller with no session, and a signed-in test customer received only their own rows.

The same terminal request with the public key and no session, now answered with an empty list
Figure 4 - The same request after the fix Open full size

References

  • OWASP Top 10, A01:2021 Broken Access Control
  • CWE-602: Client-Side Enforcement of Server-Side Security
  • PostgreSQL documentation, Row Security Policies