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

Improve type checking in getContactPhone and use CRM_Utils_Request::r… #12687

Merged
merged 1 commit into from
Oct 25, 2018

Conversation

seamuslee001
Copy link
Contributor

…etrieve to get data from GET

Overview

This improves the type checking on the name key by making it use the type Alphanumeric rather than string. It also switches to use CRM_Utils_Request::retrieve rather than CRM_Utils_Array::value to get data from the $_GET variable

ping @eileenmcnaughton @monishdeb @colemanw

@civibot
Copy link

civibot bot commented Aug 19, 2018

(Standard links)

@eileenmcnaughton
Copy link
Contributor

eileenmcnaughton commented Aug 20, 2018

I tested with

http://dmaster.local/civicrm/ajax/checkphone?cid=96,97,95,148

http://dmaster.local/civicrm/ajax/checkphone?name=Jacobs, Elbert

& this didn't work. For the first url the following patch worked

:...skipping...
diff --git a/CRM/Contact/Page/AJAX.php b/CRM/Contact/Page/AJAX.php
index 8a4ffdf6e8..24ffa88ae2 100644
--- a/CRM/Contact/Page/AJAX.php
+++ b/CRM/Contact/Page/AJAX.php
@@ -472,7 +472,7 @@ LIMIT {$offset}, {$rowCount}
       $queryString = " ( cc.sort_name LIKE '%$name%' OR cp.phone LIKE '%$name%' ) ";
     }
     else {
-      $cid = CRM_Utils_Request::retrieve('cid', 'CommaSeparatedIntegers', NULL, FALSE, NULL, 'GET');
+      $cid = CRM_Utils_Request::retrieveValue('cid', 'CommaSeparatedIntegers', NULL, FALSE, 'GET');
       if ($cid) {
         $queryString = " cc.id IN ( $cid )";
       }
@@ -480,9 +480,8 @@ LIMIT {$offset}, {$rowCount}
 
     if ($queryString) {
       $result = array();
-      $offset = CRM_Utils_Request::retrieve('offset', 'Integer', NULL, FALSE, 0, 'GET');
-      $rowCount = CRM_Utils_Request::retrieve('rowcount', 'Integer', NULL, FALSE, 20, 'GET');
-
+      $offset = (int) CRM_Utils_Request::retrieveValue('offset', 'Integer', 0, FALSE, 'GET');
+      $rowCount = (int) CRM_Utils_Request::retrieveValue('rowcount', 'Integer', 20, FALSE, 'GET');
       // add acl clause here
       list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause('cc');
       if ($aclWhere) {

Note that the (int) is required because of the way 0 is handled in retrieve function

For the 'name' retrieval it's more complex. Valid name variables include more than just alphanumeric. In my test there was a comma and a space (it works off sort_name) but also consider O'Connor. We probably need to filter things out ? Do we need a new filter

@seamuslee001
Copy link
Contributor Author

@eileenmcnaughton possibly yes, i guess what i can do is for the moment send it back to string but yeh i think it would be good. Maybe we could allow for one space in the alphanumeric but hmmm its a difficult question

@eileenmcnaughton
Copy link
Contributor

@seamuslee001 specifically stripping < & > seems good

if ($name) {
$name = CRM_Utils_Type::escape($name, 'String');
$queryString = " ( cc.sort_name LIKE '%$name%' OR cp.phone LIKE '%$name%' ) ";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't think we should be concatenating string values from the url into a query. I think this line ought to be using %1 %2 etc placeholders and we should be feeding values into an array as the 2nd param to executeQuery.

@eileenmcnaughton
Copy link
Contributor

@seamuslee001 I took a look at this - there are a few instance where you use retrieveValue instead of the existing CRM_Utils_Array::value + escape. For commaSeparatedInteger & Integer I think the validate action is solid enough not to also require escaping.

However for the first one - ie. the one that is string - the validate doesn't do much now we've backed off your original 'Alphanumeric' - making the change @colemanw suggested would work - although the way the hook has been jammed in that function it arguably could mess with it. Alternatively CRM_Core_DAO::composeQuery could be used to do the interpolation.

@eileenmcnaughton
Copy link
Contributor

@seamuslee001 this needs an update by you per comments

@seamuslee001
Copy link
Contributor Author

@eileenmcnaughton updated now

@seamuslee001 seamuslee001 force-pushed the get_phone_improvement branch from d9a81f1 to 13a6395 Compare October 25, 2018 02:31
@eileenmcnaughton
Copy link
Contributor

Thanks @seamuslee001 this is good to merge IMHO

@eileenmcnaughton
Copy link
Contributor

@seamuslee001 oops I take it back - I'm getting a notice
screenshot 2018-10-25 17 06 19

…etrieve to get data from GET

Fix retrieving value from GET param as per review by Eileen

Replace inserted variables with placeholders as per standards
@seamuslee001 seamuslee001 force-pushed the get_phone_improvement branch from 13a6395 to 3ae9c7d Compare October 25, 2018 04:42
@seamuslee001
Copy link
Contributor Author

@eileenmcnaughton hopefully fixed that e-notice now

@eileenmcnaughton
Copy link
Contributor

@seamuslee001 yep seems good

@seamuslee001
Copy link
Contributor Author

Merging as per the tag

@seamuslee001 seamuslee001 merged commit bad2cae into civicrm:master Oct 25, 2018
@seamuslee001 seamuslee001 deleted the get_phone_improvement branch October 25, 2018 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants