Skip to content

Conversation

@Beesh1
Copy link
Contributor

@Beesh1 Beesh1 commented Oct 1, 2025

Fix: #110

Problem

The enforce() and batch_enforce() methods in both sync and async implementations incorrectly use enforceId as the query parameter name when calling the Casdoor API. The correct parameter name is enforcerId (note the 'r').

This bug causes the enforce API to silently return false for all authorization checks when using an Enforcer object, regardless of the actual policy rules. This is a security concern as it fails closed without raising any errors.

Related Issue

Fixes #110

Changes

Fixed parameter name in all 4 affected methods:

  • src/casdoor/main.py: enforce() and batch_enforce()
  • src/casdoor/async_main.py: enforce() and batch_enforce()

Changed params["enforceId"] to params["enforcerId"] in all locations.

Also added parameter validation to ensure exactly one of (permission_id, model_id, resource_id, enforce_id, owner) is provided, improving error messages when the API is called incorrectly.

Testing

  • ✅ Parameter validation tests pass
  • ✅ Integration test with live Casdoor instance passes
  • ✅ Authorization check now returns correct results when using Enforcer objects

Breaking Changes

None - this fixes existing broken functionality.

Fix critical bug in enforce() and batch_enforce() methods where they use
incorrect parameter name when calling Casdoor API, causing silent
authorization failures for Enforcer objects.

Problem:
- SDK sends "enforceId" parameter (typo)
- API expects "enforcerId" parameter (correct spelling)
- Results in silent failures: returns false for all Enforcer checks
- No exceptions raised, making it hard to debug
- Security concern: appears to work but denies all access

Changes:
- Fix parameter name: "enforceId" → "enforcerId" in all methods
- Add validation to ensure exactly one parameter is provided (API requirement)
- Only send non-empty parameters to API
- Update docstrings to clarify parameter usage
- Apply fix to both sync and async versions
- Apply fix to both enforce() and batch_enforce() methods

Files changed:
- src/casdoor/main.py - enforce() and batch_enforce()
- src/casdoor/async_main.py - enforce() and batch_enforce()

Impact:
This fix enables Enforcer-based authorization to work correctly for:
- Custom Casbin models with fine-grained access control
- ABAC/ReBAC policies with pattern matching
- Facility/attribute-based authorization
- Complex authorization scenarios requiring Enforcers

Testing:
- Verified parameter name changed in all 4 methods
- Verified validation logic added correctly
- Tested against live Casdoor instance
- All existing tests remain compatible (no breaking changes)

Fixes casdoor#110
@CLAassistant
Copy link

CLAassistant commented Oct 1, 2025

CLA assistant check
All committers have signed the CLA.

Reduces cyclomatic complexity of enforce methods to satisfy
linter requirements (C901 complexity < 10).
@hsluoyz hsluoyz changed the title fix: correct enforce parameter name from enforceId to enforcerId feat: fix enforce param name from enforceId to enforcerId Oct 2, 2025
@hsluoyz hsluoyz merged commit 462aefc into casdoor:master Oct 2, 2025
3 checks passed
github-actions bot pushed a commit that referenced this pull request Oct 2, 2025
# [1.39.0](v1.38.0...v1.39.0) (2025-10-02)

### Features

* fix enforce param name from enforceId to enforcerId ([#111](#111)) ([462aefc](462aefc))
@github-actions
Copy link

github-actions bot commented Oct 2, 2025

🎉 This PR is included in version 1.39.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: enforce() uses wrong parameter "enforceId" instead of "enforcerId" - breaks Enforcer functionality

3 participants