Skip to content

Commit

Permalink
Add hook for invalidating checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire committed Jul 28, 2021
1 parent af65ee6 commit 48886a8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CRM/Contact/BAO/Contact/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ public static function generateChecksum($entityId, $ts = NULL, $live = NULL, $ha
* @throws \CRM_Core_Exception
*/
public static function validChecksum($contactID, $inputCheck) {
// Allow a hook to invalidate checksums
$invalid = FALSE;
CRM_Utils_Hook::invalidateChecksum($contactID, $inputCheck, $invalid);
if ($invalid) {
return FALSE;
}

$input = CRM_Utils_System::explode('_', $inputCheck, 3);

Expand Down
19 changes: 19 additions & 0 deletions CRM/Utils/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2835,4 +2835,23 @@ public static function alterApiRoutePermissions(&$permissions, $entity, $action)
);
}

/**
* Allows an extension to override the checksum validation.
* For example you may want to invalidate checksums that were sent out/forwarded by mistake. You could also
* intercept and redirect to a different page in this case - eg. to say "sorry, you tried to use a compromised
* checksum".
*
* @param int $contactID
* @param string $checksum
* @param bool $invalid
* Leave this at FALSE to allow the core code to perform validation. Set to TRUE to invalidate
*/
public static function invalidateChecksum($contactID, $checksum, &$invalid) {
return self::singleton()->invoke(
['contactID', 'checksum', 'invalid'],
$contactID, $checksum, $isValid, self::$_nullObject, self::$_nullObject,
self::$_nullObject, 'civicrm_invalidateChecksum'
);
}

}

0 comments on commit 48886a8

Please sign in to comment.