Skip to content

fix: copy sets before sorting in SetEquals, SetEqualsInt and Set2DEquals - #1753

Open
lenamonj wants to merge 1 commit into
apache:masterfrom
lenamonj:fix-set-equals-mutation
Open

fix: copy sets before sorting in SetEquals, SetEqualsInt and Set2DEquals#1753
lenamonj wants to merge 1 commit into
apache:masterfrom
lenamonj:fix-set-equals-mutation

Conversation

@lenamonj

@lenamonj lenamonj commented Sep 1, 2026

Copy link
Copy Markdown

Fixes #1752.

SetEquals, SetEqualsInt and Set2DEquals sorted their arguments in place. Because GetPermissionsForUser returns the model's live policy rows, using Set2DEquals on its result reordered each stored rule's fields (p, zoe, data1, read became data1, read, zoe) and flipped subsequent Enforce calls from allow to deny. Full reproduction and output are in the issue.

This change sorts copies instead: the outer slices in all three helpers, and in Set2DEquals the inner rows as well, since reordering a row's fields is the mutation that corrupts a policy rule. Comparison semantics are unchanged.

TestSetComparisonsDoNotModifyArguments covers all three helpers and fails on master before this change. go test -count=1 ./... is green with it applied.

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.

SetEquals/SetEqualsInt/Set2DEquals sort their arguments in place; comparing live policy rows corrupts the model and flips Enforce results

1 participant