Skip to content

Commit

Permalink
respond with 400 not 500 errors if wrong params on CiviMail url endpo…
Browse files Browse the repository at this point in the history
…ints
  • Loading branch information
ufundo committed May 16, 2023
1 parent 70c2b33 commit 57ae254
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions CRM/Mailing/Form/Optout.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ public function preProcess() {
$this->_hash = $hash = CRM_Utils_Request::retrieve('h', 'String', $this);

if (!$job_id || !$queue_id || !$hash) {
throw new CRM_Core_Exception(ts("Missing input parameters"));
//throw new CRM_Core_Exception(ts("Missing input parameters"));
CRM_Utils_System::sendResponse(new \GuzzleHttp\Psr7\Response(400, [], ts("Invalid request: missing parameters") ) );
}

// verify that the three numbers above match
$q = CRM_Mailing_Event_BAO_MailingEventQueue::verify($job_id, $queue_id, $hash);
if (!$q) {
throw new CRM_Core_Exception(ts("There was an error in your request"));
//throw new CRM_Core_Exception(ts("There was an error in your request"));
CRM_Utils_System::sendResponse(new \GuzzleHttp\Psr7\Response(400, [], ts("Invalid request: bad parameters") ) );
}

list($displayName, $email) = CRM_Mailing_Event_BAO_MailingEventQueue::getContactInfo($queue_id);
Expand Down
6 changes: 4 additions & 2 deletions CRM/Mailing/Form/Unsubscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ public function preProcess() {
$isConfirm = CRM_Utils_Request::retrieveValue('confirm', 'Boolean', FALSE, FALSE, 'GET');

if (!$job_id || !$queue_id || !$hash) {
throw new CRM_Core_Exception(ts('Missing Parameters'));
//throw new CRM_Core_Exception(ts('Missing Parameters'));
CRM_Utils_System::sendResponse(new \GuzzleHttp\Psr7\Response(400, [], ts("Invalid request: missing parameters")) );
}

// verify that the three numbers above match
$q = CRM_Mailing_Event_BAO_MailingEventQueue::verify($job_id, $queue_id, $hash);
if (!$q) {
throw new CRM_Core_Exception(ts("There was an error in your request"));
//throw new CRM_Core_Exception(ts("There was an error in your request"));
CRM_Utils_System::sendResponse(new \GuzzleHttp\Psr7\Response(400, [], ts("Invalid request: bad parameters")) );
}

list($displayName, $email) = CRM_Mailing_Event_BAO_MailingEventQueue::getContactInfo($queue_id);
Expand Down

0 comments on commit 57ae254

Please sign in to comment.