AI pentesting guides / By tech stack

Stack guide: Hasura

Hasura security testing

Hasura security testing checks the permission rules Hasura generates your API from: Hasura turns a Postgres schema into a GraphQL API automatically, and what each role can query or mutate is decided by row and column permissions configured per table, plus the admin secret that bypasses all of them.

That makes Hasura closer to Supabase than to a hand-written GraphQL server. There are few resolvers to audit; there is a permission matrix to verify, and it grows with every table.

Admin secret and console

  • Without an admin secret configured, every request runs as admin. Production deployments must set one.
  • The admin secret sent from a frontend, or baked into a mobile app, gives full read, write and metadata access.
  • The console enabled in production, and dev mode returning detailed internal errors, expose more than necessary.
  • Metadata and schema APIs (for example run_sql) are admin-only, so they should be unreachable without the secret.

Roles, rows and columns

Hasura derives the role and user ID from JWT claims or a webhook. Row permissions such as {user_id: {_eq: X-Hasura-User-Id}} restrict rows; column permissions restrict fields. Common mistakes: an anonymous or unauthorised role with select on tables containing private data, a user role allowed to read every column including email or internal flags, insert permissions without column presets so clients can set owner_id, and relationship traversal that reaches a table with looser rules.

Trust boundaries

  • Session variables like X-Hasura-Role are only trusted from the JWT or auth webhook, unless the admin secret is also sent. Test that a client header cannot switch roles.
  • Actions and remote schemas forward requests to your services; those services must authorise independently.
  • Event triggers call webhooks with data that should be validated as untrusted.
  • Without an allow-list or query limits, expensive aggregate queries are open to any role that can select.
With Pentest-Swarm

Testing Hasura with Pentest-Swarm

Pentest-Swarm tests the Hasura GraphQL endpoint over HTTP using the graphql-audit playbook. It never needs your admin secret, and for a realistic test it should not have it.

  • Run graphql-audit against the /v1/graphql endpoint on staging with scope set to that host.
  • Test as anonymous first, then pass a user JWT with --auth, then a second user's, to compare what each role can reach.
  • Look for role switching by sending X-Hasura-Role headers without the admin secret.
  • Findings it proves include the exact query and response, which maps back to a specific table permission.

Where it falls short

A black-box test only sees what the roles it is given can reach, so tables only exposed to a role you did not provide credentials for go untested. Export Hasura metadata and review the permission matrix directly, and keep it under version control so changes are reviewed.

Questions

Is Hasura secure by default?

It is secure once an admin secret and an auth mode are configured and permissions are written. Without an admin secret it runs fully open, which is suitable only for local development.

Can a client set X-Hasura-User-Id itself?

Not if Hasura is configured correctly: session variables come from the verified JWT or webhook. Sending them alongside the admin secret is the exception, which is why that secret must stay server-side.

Should I disable introspection on Hasura?

You can disable it per role. It reduces exposure, but permissions remain the real control.