Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 8, 2025

Empty string parameters in deleteUser(), deleteRole(), and related methods act as wildcards in removeFilteredPolicy, causing all policies to be deleted instead of filtering by the specified user/role. This results in destructive SQL queries like DELETE FROM casbin_rule WHERE ptype = 'p'.

Changes

  • Input validation: Added checks to reject empty/falsy parameters in:
    • deleteUser(), deleteRole(), deletePermission()
    • deleteRoleForUser(), deleteRolesForUser(), deletePermissionsForUser(), deletePermissionForUser()
  • Error messages: Throw descriptive errors (e.g., "user must not be empty") instead of silently deleting all data
  • Test coverage: Added tests verifying empty string, undefined, and null are rejected

Example

// Before: Silently deletes ALL policies
await enforcer.deleteUser('');

// After: Throws "user must not be empty"
await enforcer.deleteUser('');

The fix catches empty strings, undefined, and null at the API boundary before they reach the filtering logic.

Original prompt

This section details on the original issue you should resolve

<issue_title>enforcer.deleteUser() wiped out all data from casbin_rule table</issue_title>
<issue_description>Logged queries shows that following queries are executed when calling enforcer.deleteUser()

DELETE from casbin_rule WHERE ptype = 'p';
DELETE from casbin_rule WHERE ptype = 'g'; 
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@hsluoyz hsluoyz marked this pull request as ready for review December 8, 2025 12:03
Copilot AI changed the title [WIP] Fix enforcer.deleteUser() to prevent data loss Prevent wildcard deletion in deleteUser/deleteRole methods Dec 8, 2025
Copilot AI requested a review from hsluoyz December 8, 2025 12:23
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.

enforcer.deleteUser() wiped out all data from casbin_rule table

3 participants