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

dev/financial#50 - Fix contributions and participants getting overwritten #14244

Merged

Conversation

pfigel
Copy link
Contributor

@pfigel pfigel commented May 14, 2019

Overview

This fixes an issue where contributions or participants may be overwritten when users open an existing contribution or participant after opening the creation form (but before actually submitting it).

Before

An existing contribution or participant is overwritten if it's been opened after the creation form was loaded.

After

A new contribution or participant is recorded.

Technical Details

The form passes a reference to itself when calling CRM_Utils_Request::retrieve, which eventually leads to the ID being loaded from $_SESSION (via CRM_Core_Controller::get()).

Some forms bypass this behaviour by not loading the ID for CRM_Core_Action::ADD (or only for CRM_Core_Action::UPDATE), but I could not find any issues with this approach (i.e. not passing $this).

https://lab.civicrm.org/dev/financial/issues/50

@civibot
Copy link

civibot bot commented May 14, 2019

(Standard links)

@civibot civibot bot added the master label May 14, 2019
@pfigel pfigel changed the title [WIP] dev/financial#50 - Fix contributions getting overwritten dev/financial#50 - Fix contributions and participants getting overwritten May 14, 2019
@pfigel pfigel force-pushed the fix-contribution-overwrite branch from 53a88ab to de49856 Compare May 14, 2019 14:36
@pradpnayak
Copy link
Contributor

I get fatal error when trying to save contribution opened in new tab
After

@pfigel
Copy link
Contributor Author

pfigel commented May 15, 2019

@pradpnayak Thanks, nice catch! Digging a bit deeper, it seems that unlike the AJAX form, this one does not pass the contribution ID as a GET/POST parameter, thus triggering the fallback to session. Naturally, that also means the standalone edit form suffers from the same problem - if you open more than one, values from the form submission will be applied to the one you opened last.

I'll check if I can make the standalone form behave like the AJAX form.

@pfigel
Copy link
Contributor Author

pfigel commented May 15, 2019

Jenkins test this please

@pfigel
Copy link
Contributor Author

pfigel commented May 15, 2019

8b92924 seems to have addressed the issue @pradpnayak found.

The approach used here (passing the record ID explicitly):

  • Is what most web frameworks would use (in some variation)
  • Is not used by Civi consistently, but is used in many places, e.g. in the AJAX form for contributions

With that in mind, there's some remaining uncertainty on whether this would break in unexpected places, and test coverage is not great for forms, to say the least. I wasn't able to uncover further issues during r-run, FWIW.

@eileenmcnaughton
Copy link
Contributor

@mattwire @colemanw @seamuslee001 @xurizaemon this looks promising & addresses an ongoing annoyance - can anyone see any reason for caution here?

@mattwire
Copy link
Contributor

I've not tested but the principal here is good. I've come up against issues when writing custom stuff and the ID of what you're trying to work with can sometimes be nearly impossible to retrieve! If the ID changes the form would be reloaded so I can't see any issues with this.

@pfigel
Copy link
Contributor Author

pfigel commented May 29, 2019

Jenkins test this please

@eileenmcnaughton
Copy link
Contributor

test this please

@eileenmcnaughton eileenmcnaughton added the merge ready PR will be merged after a few days if there are no objections label Jun 5, 2019
@eileenmcnaughton
Copy link
Contributor

@pfigel just sitting with @colemanw now & discussing this & this seems to make sense but there could be security implications - ie could someone alter id in firebug & access a contribution that they would otherwise be blocked from by the financial acl check - ie

    if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()
      && $this->_action & CRM_Core_Action::UPDATE
      && CRM_Utils_Array::value('financial_type_id', $this->_values)
    ) {
      $financialTypeID = CRM_Contribute_PseudoConstant::financialType($this->_values['financial_type_id']);
      CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($this->_id, 'edit');
      if (!CRM_Core_Permission::check('edit contributions of type ' . $financialTypeID)) {
        CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
      }
    }

pfigel added 3 commits June 13, 2019 23:25
This fixes an issue where contributions may be overwritten when users
open an existing contribution after opening the "Record Contribution"
form (but before actually submitting it).
@pfigel
Copy link
Contributor Author

pfigel commented Jun 13, 2019

@eileenmcnaughton @colemanw so I tried to reproduce this and I think the check in CRM_Contribute_Form_Contribution::buildQuickForm still works as intended. I tried the following:

  • Opening the "View" link of a contribution I shouldn't have access to: no access
  • Opening the "Edit" link of a contribution I shouldn't have access to: no access
  • Opening the "Edit" link of a contribution I have access to and then changing the "id" input value to a contribution I shouldn't have access to: no access

On the bright side, this got me to do some testing with deleting contributions, and that seems to have regressed with this change. I'll continue tomorrow.

This fixes an issue where the hidden "id" element wasn't added
because the CRM_Core_Action::DELETE handler has an early return.
@pfigel pfigel force-pushed the fix-contribution-overwrite branch from 8b92924 to 5774b54 Compare June 14, 2019 18:28
@pfigel
Copy link
Contributor Author

pfigel commented Jun 14, 2019

@eileenmcnaughton @colemanw issue with deletes was resolved. If someone could double-check my findings for financial ACLs (haven't really used them before), I think this would be ready.

@JoeMurray
Copy link
Contributor

@monishdeb please review.

@eileenmcnaughton
Copy link
Contributor

I also had a go at circumventing the acl by going into the edit screen of a contribution I had access to & setting cj('#id').val(15) in firefox and that seemed to be ignored in post processing

@xurizaemon opening the hacking floor to you :-) , also @monishdeb will you have a chance to try? @pradpnayak

Note the test config is a bit weird - you need to enable financial acls on the contribution settings screen and then the limited user needs to have edit contributions + edit contributions of a particular financial type in the drupal screen

@eileenmcnaughton
Copy link
Contributor

In absence of further input (I've tried a few places) I'm going to merge this in time for the rc

@eileenmcnaughton eileenmcnaughton merged commit 8d0350d into civicrm:master Jul 1, 2019
@eileenmcnaughton
Copy link
Contributor

@pfigel ok I've found a regression from this - it's pretty kooky https://lab.civicrm.org/dev/report/issues/16 - question is should we revert this out of 5.16 rc & bring back into master to give us more time given the crazy ugliness of it

@eileenmcnaughton
Copy link
Contributor

& a PR for the regression - #14732 (but I'm running scared now)

@JKingsnorth
Copy link
Contributor

Hiah, I'm just trying to follow along the trail with this - it looks like the participant element of this has NOT been fixed yet then? Is there an open issue/PR for this bit of it?

@eileenmcnaughton
Copy link
Contributor

@JKingsnorth you are right - we found a regression on the participant side & backed it out - I'd say it's a fixable but probably requires a bit of retrofitting sanity onto the code to get past the are which regressed

@JKingsnorth
Copy link
Contributor

Created a follow up issue on gitlab for the event registration part then: https://lab.civicrm.org/dev/core/issues/1164

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
master merge ready PR will be merged after a few days if there are no objections
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants