# Log access restricted to audit/compliance roles only

- **Pattern:** `ab-001385` (`finserv-audit-trail.balance-reconciliation.access-control`)
- **Severity:** high
- **Lifecycle:** active
- **Last modified:** 2026-04-18
- **Canonical URL:** https://auditbuffet.com/patterns/ab-001385
- **License:** CC-BY-4.0 — attribute to AuditBuffet Pattern Catalog (https://auditbuffet.com/patterns/ab-001385)

## Why it matters

Audit logs that any authenticated user can query are a surveillance and privacy failure — they expose the financial activity of every customer to every employee who has a database login. PCI-DSS v4.0 Req-10.3.1 limits read access to audit log files to those with a job-related need — precisely the scope of this control. NIST 800-53 AU-9 requires that audit information is protected from unauthorized access, modification, and deletion. OWASP A01:2021 (Broken Access Control) covers this class directly — granting SELECT on `transaction_logs` to `app_role` without a compliance restriction means any developer querying the database has full visibility into the financial movements of all customers. CWE-285 (Improper Authorization) is the vulnerability. A disgruntled employee or compromised app credential can exfiltrate the complete transaction history of any user with a single query.

## Severity rationale

High because unrestricted read access to audit logs exposes the complete financial history of all users to any compromised or malicious credential that holds the application's standard database role.

## Remediation

Revoke SELECT from general roles and grant it only to a designated compliance role in `db/migrations/`:

```sql
REVOKE SELECT ON transaction_logs FROM app_role;
CREATE ROLE compliance_role;
GRANT SELECT ON transaction_logs TO compliance_role;

-- Row-level: users can only see their own rows
ALTER TABLE transaction_logs ENABLE ROW LEVEL SECURITY;
CREATE POLICY user_self_read ON transaction_logs
  FOR SELECT TO app_role
  USING (user_id = current_setting('app.current_user_id')::uuid);
```

In `src/middleware/` or your route handlers, enforce the compliance role check before any audit log query:

```ts
app.get('/api/audit-logs', authenticate, requireRole('compliance'), async (req, res) => {
  const logs = await db('transaction_logs').where({ user_id: req.query.userId });
  res.json(logs);
});
```

## Detection

**The detection method for this pattern is part of AuditBuffet Pro.**

The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the [Financial Audit Trail Audit](https://auditbuffet.com/audits/finserv-audit-trail). The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.

## External references

- cwe CWE-285
- owasp A01
- nist AU-9
- pci-dss Req 10.3.1
- external FINRA-Rule-4511 — https://www.finra.org/rules-guidance/rulebook/finra-rules/4511

Taxons: access-control, regulatory-conformance

HTML version: https://auditbuffet.com/patterns/ab-001385
