Skip to content

Address review findings on access control #262

Closed

Description

@uniqueg

Why?

#259 (config-driven access control, #258) was merged before the automated reviews by Sourcery and Copilot were addressed. Several findings are real, including one that lets authenticated callers bypass policy checks. None of this has been released yet (last tag: v0.13.0), so it should be fixed before the next release.

Findings to fix

  1. Path items via $ref skip enforcement (Sourcery, Copilot; high): _get_enforced_operations() scans the raw spec, so operations of path items defined via $ref are not in the enforced set; Connexion resolves them later and their controllers run unwrapped. Decide per operation in AccessControlResolver, based on Connexion's resolved operation (effective security, x-foca-access-control), instead of pre-scanning the raw spec.
  2. enforce: true with auth.required: false fails open (Sourcery; high): enforcement is silently skipped (only an error is logged), while operations declaring security still validate tokens. Refuse to start with this configuration.
  3. Optional authentication (security: [{}]) returns 401 (Sourcery, Copilot; medium): an empty security requirement alternative allows anonymous access, but such operations are enforced and anonymous callers get 401. Treat them like security: [], i.e., do not enforce.
  4. Callable resolvers break registration (Copilot, Sourcery; medium/high): Connexion accepts a callable as resolver, but AccessControlResolver calls .resolve() on it. Wrap callables in Resolver(...).
  5. Empty subject_prefix reintroduces role-name collisions (Sourcery; high): with subject_prefix: "", a user admin matches the admin role. Reject an empty prefix.
  6. subject_prefix overlapping group: lets users collide with groups (Sourcery; medium): e.g., subject_prefix: "group:". Reject prefixes overlapping with the group: namespace.

Findings to address in the docs

  1. Existing unprefixed rules stop matching (Sourcery; high): not a regression (enforcement is new and opt-in, the permissions API was unprotected before), and a fallback would reintroduce collisions. Document that rules, including those for the permissions API, must use prefixed subjects (user:<id>).
  2. Interplay with check_permissions (Sourcery; medium, two findings): the legacy decorator is a separate, header-based mechanism and does not use claims or prefixes; with enforce: true, both checks run. Document that check_permissions should not be combined with enforce: true, and that claims and prefixes only apply to config-driven enforcement and the helpers.

Findings declined

  1. Concurrent identical grants can create duplicate rules (Sourcery; medium): harmless for enforcement, and revoking removes all copies; a real fix needs a unique index in the shared Casbin adapter, out of scope here.
  2. Resource lifecycle and role grants are not atomic (Sourcery; medium): transactional consistency between an app's resources and its grants is the app's design, not FOCA's.

Acceptance criteria

  • Operations of path items defined via $ref are enforced.
  • FOCA refuses to start with enforce: true and auth.required: false.
  • Operations whose security requirements include an empty alternative are not enforced.
  • Callable resolvers work with enforcement enabled.
  • Empty subject_prefix and prefixes overlapping group: are rejected at config validation.
  • Docs cover prefixed subjects in rules and the relation to check_permissions.
  • Regression tests for all fixes.

Drafted with AI assistance (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions