Compare PostgreSQL API and Direct Role Risk with Safegres
Dan Lynch
Once you declare the API boundary, A2 (grants on a table with RLS off) stays visible on internal tables but doesn't lower the headline API grade. RLS off alone doesn't trigger A2; qualifying grants must exist.
Compare three audits
Use the workspace and exposure config from the previous lesson. Save this as no-exposure.json for the first run:
json{ "extends": "safegres:recommended", "source": { "pgpm": "." }, "excludeSchemas": ["pgpm_migrate"] }
bashpnpm exec safegres audit --config no-exposure.json --verbose pnpm exec safegres audit --verbose pnpm exec safegres audit --report-only --verbose \ --exposure-schemas app_public,app_private
No grants changed. The A+ describes only the declared API; the role still has SQL access to the private table.
The default score weighs exposed fail-open findings by severity and exposed table count. Fail-closed findings (such as RLS with no policies) don't deduct by default, but still need review. Compare grades only across like scopes.
Grade another access path
Replace the exposure assignment in safegres.config.js with two independently graded boundaries without changing the primary scope:
javascriptmodule.exports.exposure = { schemas: ['app_public'], roles: ['authenticated'], planes: [ { name: 'direct:authenticated', kind: 'role', roles: ['authenticated'] }, { name: 'internal', kind: 'schema', schemas: ['app_private'] }, ], };
bashpnpm exec safegres audit --verbose --plane 'direct:*'
Both extra planes score C in the lab. The role plane includes inherited and PUBLIC grants; it doesn't grade superusers or BYPASSRLS roles. The schema plane grades the internal schema. Gate a required plane with failOn.planes.
Scorecards filter findings by criteria such as rule, schema, or role. The built-in raw card ignores exposure; it isn't a direct-role grade. Headlines, planes, and cards aren't averaged.
Review indirect access, too
An exposed view, callable SECURITY DEFINER routine, or trigger can reach a private schema. Check grants (including function EXECUTE to PUBLIC) and test allowed and denied requests as real app roles. Use public.read only for intentionally public data.

