Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Add permission metadata to contact is_deleted field" #22203

Merged
merged 1 commit into from Dec 9, 2021

Conversation

colemanw
Copy link
Member

@colemanw colemanw commented Dec 2, 2021

Overview

Fixes https://lab.civicrm.org/dev/core/-/issues/2507 by reverting the commit from #17721.

Technical Details

This reverts commit d2ff128.

ACLs for accessing deleted contacts are already enforced in the query, so this field was being hidden for UI purposes not ACL purposes.
It had the unfortunate side-effect of crashing any API call using is_deleted in the WHERE clause for non-permissioned users.
It would be nice to hide it from SearchKit for non-permissioned users, but not mission-critical, and it's far more critical for us to prevent the crashes documented in https://lab.civicrm.org/dev/core/-/issues/2507.

This reverts commit d2ff128.
ACLs for accessing deleted contacts are already enforced in the query,
so this field was being hidden for UI purposes not ACL purposes.
It had the unfortunate side-effect of crashing any API call using
`is_deleted` in the WHERE clause for non-permissioned users.
@civibot
Copy link

civibot bot commented Dec 2, 2021

(Standard links)

@civibot civibot bot added the master label Dec 2, 2021
@totten
Copy link
Member

totten commented Dec 2, 2021

@jmcclelland Are you able to review this?

@jmcclelland
Copy link
Contributor

@totten - yes, I can review. Can you confirm what commands I need to run after applying the fix? I tried:

cd xml && php GenCode.php schema/Schema.xml
cv flush

But my tests are still failing in the same way as before the fix. I wonder if I'm missing a step? Or if the fix is not working?

@totten
Copy link
Member

totten commented Dec 2, 2021

@jmcclelland @colemanw Those steps sound more than sufficient to me... (Since DAOs are committed to git, I would expect a simple git checkout or git cherry-pick to be enough; but cv flush seems prudent too. )

@colemanw
Copy link
Member Author

colemanw commented Dec 2, 2021

Yea the cache flush is critical because APIv4 metadata is stored in the cache.

@totten
Copy link
Member

totten commented Dec 3, 2021

So then cv flush should've been enough, right? There's still some unidentified issue with why the patch didn't work?

@jmcclelland
Copy link
Contributor

Yes - I'm still working on it. I'm somewhat befuddled by the mixture of permissions needed to make it fail in the first place. I plan to have either a report or a semi-intelligent question later today.

@jmcclelland
Copy link
Contributor

@totten and @colemanw - I figured out my befuddlement. There is a difference in behavior between 5.39 lts and master.

WIth 5.39 lts granting or restricting the 'access deleted contacts' permission controls whether or not the error is triggered.

In master, as long as the user has 'access CiviCRM backend and API' permission, the error will not be triggered. But if the user doesn't have that permission, then the error will be triggered (regardless of whether or not they have 'access deleted contacts').

After applying the patch, I'm not seeing any difference. I'm not sure what's going on but will work on a test to try to demonstrate the behavior (or uncover something dumb I may be doing).

@jmcclelland
Copy link
Contributor

Hi all,

I've finally finished the review and it's surprisingly messy for what seems like such a simple change.

r-eplain: issue: See below. Wah, the explanation is no longer true - maybe it could be updated with a preface "In previous versions" and a final sentence "Also, this change makes querying on is_deleted consitent regardless of whether you have access to deleted contacts or not.
r-user: this change will alter behavior for some users - I'm not sure if anyone is counting on the old behavior (which I think is broken), but it does change things.
r-doc pass
r-run I tested both via the UI using both search results and phone bank results to test the generation of the overlay profile. In addition, I tested with a php script containing an APIv4 called to get a Contact and running cv --user=<user> php:script /path/to/script and substituting the admin user and a user without access to deleted contacts to compare the results.
r-tech: pass
r-maint: pass
r-test: fail (but I don't think it's related)

There is some subtle change to the Api4 in master compared with version 5.39 making the original issue less urgent. Now, as long as you have "access CiviCRM" permissions, you won't get the error when you call Api4 with is_deleted, even if you do not have permission to access deleted contacts.

However, I still think this change is an important improvement.

Consider this scenario:

  1. You do not have access to deleted contacts
  2. There is one contact in the database that has is_deleted set to 1.
  3. Your run an Api4 query with a where clause specifying is_deleted = 1 (with the intention of getting deleted contacts)
  4. You pop off the first record

Before the change: You get the first record in the database that is not deleted (unexpected). That's because the is_deleted where clause seems to be silently ignored, while your restriction against seeing deleted contacts is still enforced.

After the change: You get no results (expected)

And lastly, I was a bit surprised that I could access the phone bank without "access CiviCRM" permissions simply by knowing the right URL, but I don't think this is a security concern since:

  1. Access to the page is controlled by the "interview campaign contacts" permission
  2. It's often granted to volunteers, so is conceivably considered more of a front end page then a back end page

@colemanw colemanw changed the base branch from master to 5.45 December 8, 2021 00:07
@civibot civibot bot added 5.45 and removed master labels Dec 8, 2021
@colemanw
Copy link
Member Author

colemanw commented Dec 8, 2021

Thanks for the review @jmcclelland - based on your review this ought to get merged, and IMO should be merged into 5.45 so people stop getting tripped up by the unexpected behavior.

@colemanw colemanw added the merge ready PR will be merged after a few days if there are no objections label Dec 8, 2021
@colemanw colemanw merged commit 29ccf10 into civicrm:5.45 Dec 9, 2021
@colemanw colemanw deleted the revertContactDeletePermission branch December 9, 2021 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.45 merge ready PR will be merged after a few days if there are no objections
Projects
None yet
3 participants