Repository navigation
Closed
Description
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
- Path items via
$refskip enforcement (Sourcery, Copilot; high):_get_enforced_operations()scans the raw spec, so operations of path items defined via$refare not in the enforced set; Connexion resolves them later and their controllers run unwrapped. Decide per operation inAccessControlResolver, based on Connexion's resolved operation (effectivesecurity,x-foca-access-control), instead of pre-scanning the raw spec. enforce: truewithauth.required: falsefails open (Sourcery; high): enforcement is silently skipped (only an error is logged), while operations declaringsecuritystill validate tokens. Refuse to start with this configuration.- 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 likesecurity: [], i.e., do not enforce. - Callable resolvers break registration (Copilot, Sourcery; medium/high): Connexion accepts a callable as
resolver, butAccessControlResolvercalls.resolve()on it. Wrap callables inResolver(...). - Empty
subject_prefixreintroduces role-name collisions (Sourcery; high): withsubject_prefix: "", a useradminmatches theadminrole. Reject an empty prefix. subject_prefixoverlappinggroup:lets users collide with groups (Sourcery; medium): e.g.,subject_prefix: "group:". Reject prefixes overlapping with thegroup:namespace.
Findings to address in the docs
- 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>). - Interplay with
check_permissions(Sourcery; medium, two findings): the legacy decorator is a separate, header-based mechanism and does not use claims or prefixes; withenforce: true, both checks run. Document thatcheck_permissionsshould not be combined withenforce: true, and that claims and prefixes only apply to config-driven enforcement and the helpers.
Findings declined
- 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.
- 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
$refare enforced. - FOCA refuses to start with
enforce: trueandauth.required: false. - Operations whose security requirements include an empty alternative are not enforced.
- Callable resolvers work with enforcement enabled.
- Empty
subject_prefixand prefixes overlappinggroup: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).
Metadata
Metadata
Assignees
Labels
No labels
Activity
test: cover resolver instances with enforcement
fix: keep non-callable resolver objects as is