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 d2de7c1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 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
5 changes: 3 additions & 2 deletions CRM/Mailing/Page/Open.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public function run() {
$queue_id = CRM_Utils_Request::retrieveValue('q', 'Positive', NULL, FALSE, 'GET');
}
if (!$queue_id) {
echo "Missing input parameters\n";
exit();
//echo "Missing input parameters\n";
//exit();
CRM_Utils_System::sendResponse(new \GuzzleHttp\Psr7\Response(400, [], ts("Missing input parameters") ) );
}

CRM_Mailing_Event_BAO_MailingEventOpened::open($queue_id);
Expand Down

0 comments on commit d2de7c1

Please sign in to comment.