·5 min read
ByGabriel CA·Kraftwire Software

Implementing Row-Level Scoping and Database Permissions in Xano

Illustration for Implementing Row-Level Scoping and Database Permissions in Xano

Row filters limit API results to data the user may see. Guard functions provide shared access checks before an endpoint runs its business logic.1, 2

Database RLS and application access control

Row level security, or RLS, limits access to rows rather than whole tables. A user's role or permissions determine which rows they can view or edit.3

The access rules sit in the database itself. The database applies them whenever data is accessed, regardless of which application makes the request.4

Native RLS stores access policies in the database schema. Those policies apply to queries from application code, raw SQL and reporting tools.5

The database refuses to return rows the user cannot access. A missing filter in application code therefore does not bypass those row rules.5

An AI agent generating SQL could access another client's data without explicit limits on its queries.1 Database RLS suits rules that keep each customer's rows separate. It is not a replacement for the whole permission system.5

Application logic better suits feature flags and multi-step approval flows. It also suits rules where admins may edit project details, but only owners may delete them.5

Tables for roles and API permissions

Build the role-based access control, or RBAC, model around four tables: Users, Teams, Roles and Team_Members. This structure keeps a person's identity separate from their access rights.2

A user is a person, while a team defines a boundary for resources. A role defines allowed actions. The Team_Members table links these records and holds the user's access rights.2

A Permissions table can store API endpoints and the users allowed to call them. A Permission Requests table tracks requests for specific access rights.6

For a parental-control model, add a managed_users list field to the user table. This field holds links to users that the current user can manage.6

The prebuilt populate_permissions API uses Xano's Metadata API to list workspace endpoints. It fills the Permissions table with endpoint IDs and HTTP verbs.6

Install and run populate_permissions to fill that table. Enable authentication in the settings of each endpoint that needs a permission check.6

Access checks in the API function stack

The first layer checks who the user is. The next layer checks whether they hold the required permissions. The data-scoping layer filters results to rows they may see.2

Create a reusable check_user_permission function with a user ID, required permission and optional team ID. It queries team_members to check the user's role. When a team is supplied, the filter includes that team and global roles with no team.2

Call reusable guard functions at the start of each endpoint, alongside Xano's built-in authentication. Each guard returns the user's permissions or throws an error. A failed check must stop execution immediately.2

A require_team_member guard checks team membership; require_team_admin checks for an admin or owner role. A require_global_admin guard checks global admin rights. A require_resource_access guard checks access to a specific resource.2

Place check_permission first in the API function stack. Pass the endpoint's api_id and the signed-in user's user_id. The function queries the Permissions table.6

Access may be explicitly granted, open to all users, or allowed for admins when the endpoint permits admin access. Returned data allows execution to continue; no data produces an Unauthorized error. The edit_permissions API grants access for a supplied api_id and user_id pair.6

Preventing IDOR with scoped queries

Insecure direct object reference, or IDOR, occurs when a supplied record ID bypasses ownership checks. A user can then retrieve a project belonging to someone else's team.2

Join the project to its team, then join that team to its membership records. Filter by both the requested project ID and the signed-in user's ID.2

This limits access to members of the team that owns the project. A guessed or intercepted project ID does not grant access on its own.2

Use UUIDs rather than sequential IDs where possible. Add resource-level permission checks for sensitive data.2

SimplyScan security scans and trust badges

SimplyScan's platform signals include Xano. Platform detection is not a permission test.

SimplyScan offers security scans for missing RLS, unprotected database tables, and auth, session and OAuth flaws. The offer includes an impact estimate for every fix. Every finding comes with a copy-and-paste fix prompt for an AI editor.7

SimplyScan offers a trust badge for scores of 80 or higher with no critical or high-severity findings. The badge can be embedded using an HTML or Markdown snippet. It links to a public page showing the verified score and scan date.8

Sources

  1. community.xano.com › is-a-xano-row-level-security-rls-feature-necessary-to-have-…
  2. xano.com › rbac-in-xano
  3. snowflake.com › row-level-security
  4. learn.microsoft.com › row-level-security
  5. mergify.com › application-vs-database-where-should-permissions-live
  6. xano.com › unlocking-user-permissions-xano
  7. simplyscan.io
  8. simplyscan.io › badge

Frequently asked questions

Guard functions run before business logic and check the user's required access rights. They return permissions or throw an error that stops execution. The check_permission function uses the endpoint ID and signed-in user's ID to check API access.
Join resources to team and membership records, then filter by the signed-in user's ID. A record ID alone must not grant access. UUIDs and resource-level checks are further safeguards for sensitive data.
SimplyScan's platform signals include Xano, but platform detection is not a permission test. Its security scan offer covers missing RLS, unprotected tables, and auth, session and OAuth flaws. Findings include AI fix prompts, with an impact estimate for every fix.

Is your app secure? Run a free security scan in 30 seconds · free account required.

Scan your app free →