Registry Mirror
Skip to content

Conversation

@lakhansamani

@lakhansamani lakhansamani commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The embedded OpenFGA server is built without WithListObjectsMaxResults / WithListUsersMaxResults, so OpenFGA v1.22.1's DefaultListObjectsMaxResults / DefaultListUsersMaxResults (both 1000) apply per call. That equals service.maxFgaListResults (1000).

A single (type, relation) pair with, say, 5,000 matches came back from the engine as exactly 1000. ListPermissions appended all 1000, never saw a 1001st, and returned truncated: false, so results were dropped with no signal to the caller.

Fix

internal/authorization/engine/openfga/openfga.go: configure the server with WithListObjectsMaxResults(maxListResults) and WithListUsersMaxResults(maxListResults), where maxListResults = 1001 (service cap + 1). The service-side cap is now the one that applies, so truncated is set correctly. Kept as a literal like maxBatchCheckSize, so the engine doesn't import service; a comment documents the coupling.

Delegated callers (second commit)

For an RFC 8693 delegated caller, ListPermissions enumerates the agent and the user separately and intersects the results. Each per-subject slice is capped by the engine before the intersection, and OpenFGA returns objects unordered, so two capped slices of large sets overlap far less than the true intersection. The folded result could fall under the cap and be reported as truncated: false while most reachable objects were dropped. This was already the case before this PR.

internal/service/list_permissions.go: mark the response truncated when any raw per-subject slice exceeds maxFgaListResults (meaning the engine hit its maxFgaListResults + 1 cap), before intersecting. Aggregation still stops at the service cap.

Tests

  • TestOpenFGAEngine_ListAboveServiceCap: 1,050 grants; ListObjects and ListUsers must each return 1001 (both returned 1000 before).
  • TestFGAListPermissionsTruncated: end-to-end list_permissions with 1,050 grants on one pair → 1000 permissions, truncated: true. Verified failing without the fix.
  • TestAgentIntersectionListPermissionsTruncated: delegated token; user grants on document:0..2999, agent on document:1000..3999 (true intersection 2000). truncated must be true. Failed 3/3 runs before the second commit.

go build ./..., go vet ./..., make test, make lint-go pass locally.

Not covered (follow-ups)

  • No pagination upstream: OpenFGA v1.22.1 (latest) has no continuation token on ListObjects/ListUsers, and maintainers have said paging is not planned (openfga#2828). A truncated response is an arbitrary 1000 objects, not the first 1000.

  • Deadline truncation: DefaultListObjectsDeadline (3s) returns partial results with no error, so truncated can still be a false negative on slow queries.

  • _fga_list_users: its 1000 cap now actually applies, but the response has no truncated field, so callers can't detect truncation (needs a GraphQL + proto schema change).

The embedded OpenFGA server was built without WithListObjectsMaxResults /
WithListUsersMaxResults, so OpenFGA v1.22.1's defaults (1000) applied per
call. That equals service.maxFgaListResults, so a single (type, relation)
pair with more than 1000 matches came back as exactly 1000 and the service
never saw a 1001st result: list_permissions returned truncated=false while
silently dropping results.

Set both engine caps to maxListResults = 1001 (service cap + 1) so the
service-side cap is the one that bites and truncated is reported.

Regression tests: engine-level ListObjects/ListUsers above the cap, and an
integration test asserting list_permissions returns 1000 with
truncated=true for 1050 grants (fails without the fix).
For a delegated caller, list_permissions enumerates each subject
(agent and user) separately and intersects the results. Each
per-subject slice is capped by the engine before the intersection,
and OpenFGA returns objects unordered, so two capped slices of large
sets overlap far less than the true intersection. The folded result
could fall under the service cap and be reported as truncated=false
while most reachable objects were dropped.

Mark the response truncated when any raw per-subject slice exceeds
maxFgaListResults (i.e. the engine hit its maxFgaListResults+1 cap),
before intersecting. Aggregation still stops at the service cap.

Regression test: user grants on 3000 documents, agent on 3000 with a
2000-document overlap; truncated must be true (failed 3/3 before).
@lakhansamani
lakhansamani merged commit 0a05418 into main Nov 19, 2026
4 checks passed
@lakhansamani
lakhansamani deleted the fix/fga-list-engine-cap branch November 19, 2026 10:46
lakhansamani added a commit that referenced this pull request Nov 27, 2026
Black-box, against the real binary:
- GHSA-p7g3-2258-8wmp: org A's SCIM PATCH of a shared user's userName,
  emails, phoneNumbers (and a mixed PatchOp) is refused with 400/mutability
  and writes nothing; the reset cannot reach the attacker's mailbox;
  case-only and single-org changes still sync.
- #904: RS256/ES256 tokens carry a kid equal to the RFC 7638 thumbprint of
  a JWKS key that verifies them, including a pre-rotation token after a
  primary-to-secondary rotation; HS256 tokens have no kid.
- #913: client_id on access tokens and azp == aud on ID tokens from the
  authorization_code, refresh_token and client_credentials grants.
- #903: list_permissions with cap+1 grants returns cap results and
  truncated=true on GraphQL, REST and gRPC; under the cap, false.
lakhansamani added a commit that referenced this pull request Nov 27, 2026
* test(e2e): smoke coverage for 2.4.9 fixes

Black-box release smoke tests against the real binary for the 2.4.9 fixes:

- GHSA-rpv7-grw6-r2jv: a wrong-password login to an unverified account
  arms an MFA session that skip_mfa_setup, lock_mfa, totp/email OTP setup
  and webauthn registration options must all reject on GraphQL, REST and
  gRPC; the emailed OTP (read from an in-test SMTP sink) still completes
  login via verify_otp.
- #922: restart on the same DB with a role removed from --roles; login,
  validate_jwt_token on an old token and the refresh grant stop honouring it.
- #924/#932: a fake Redis that errors after the startup PING; revoke returns
  a masked internal error with an error_id on every surface, and that id is
  logged next to the original error.
- #927: admin users sort/filter return identical ordered results on
  GraphQL, REST and gRPC.

startServer gains a startServerWithLog variant that returns the log path.

* test(e2e): smoke coverage for 2.4.7 and 2.4.8 fixes

Black-box, against the real binary:
- GHSA-p7g3-2258-8wmp: org A's SCIM PATCH of a shared user's userName,
  emails, phoneNumbers (and a mixed PatchOp) is refused with 400/mutability
  and writes nothing; the reset cannot reach the attacker's mailbox;
  case-only and single-org changes still sync.
- #904: RS256/ES256 tokens carry a kid equal to the RFC 7638 thumbprint of
  a JWKS key that verifies them, including a pre-rotation token after a
  primary-to-secondary rotation; HS256 tokens have no kid.
- #913: client_id on access tokens and azp == aud on ID tokens from the
  authorization_code, refresh_token and client_credentials grants.
- #903: list_permissions with cap+1 grants returns cap results and
  truncated=true on GraphQL, REST and gRPC; under the cap, false.

* test(e2e): opt-in make smoke-db for SereneDB, SurrealDB and SQL Server

`make smoke-db DB=serenedb|surrealdb|sqlserver` starts the database in
Docker and runs TestReleaseSmokeDB against the real binary: signup, login,
session, refresh grant, admin users list, forgot_password and
resend_verify_email twice with the superseding link redeemed, and MFA
enrollment twice plus a concurrent burst. The repeated forgot_password
fails with INTERNAL on SQL Server without the 2.4.7 conflict-target fix.

Skipped unless SMOKE_DB_ARGS is set, so `make smoke` stays SQLite-only
and needs no Docker.

* test(e2e): build the smoke binary once; unique smoke-db run ids; review nits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant