Audit PostGraphile API Exposure with Safegres

Dan Lynch

Dan Lynch

lesson header image

This lesson is optional. Safegres is not a PostGraphile plugin: it doesn't read graphile.config.* or discover which schemas your pgServices serve. From the workspace root, save this as postgraphile.audit.json. For your app, use the schemas and roles your PostGraphile service uses:

json
{
	"extends": "safegres:recommended",
	"source": { "pgpm": "." },
	"excludeSchemas": ["pgpm_migrate"],
	"exposure": {
		"schemas": ["app_public"],
		"roles": ["authenticated"],
		"adapters": ["postgraphile"]
	}
}
bash
pnpm exec safegres audit --config postgraphile.audit.json --verbose

The adapter uses catalog @behavior smart tags and relation paths, not external smart-tag files. Compare its results with your generated GraphQL schema and test real requests under the API's roles. Audit each database service separately. An absent GraphQL field doesn't revoke SQL access: L6 can flag an API role's grant on a relation GraphQL can't address.

Use safegres:graphile only for the graphile-starter layout. It infers app_public, includes app_hidden for indirect reach, and adds an internal plane for app_private when present. Check its role assumptions. Explicit schemas add to inferred schemas; they don't remove them.

Other stacks have their own presets and adapters: Constructive, PostgREST, Supabase, and Hasura. For a custom boundary, declare it explicitly or supply an ExposureAdapter in a JS or TypeScript config. JSON can name built-ins but doesn't discover adapter packages. Safegres has no generic plugin loader.

Stop the lab with docker stop safegres-lab when you're done.