|
22 | 22 | */
|
23 | 23 | class Mage_Contacts_IndexController extends Mage_Core_Controller_Front_Action
|
24 | 24 | {
|
| 25 | + /** |
| 26 | + * Use CSRF validation flag from contacts config |
| 27 | + */ |
| 28 | + public const XML_CSRF_USE_FLAG_CONFIG_PATH = 'contacts/security/enable_form_key'; |
25 | 29 | public const XML_PATH_ENABLED = 'contacts/contacts/enabled';
|
26 | 30 | public const XML_PATH_EMAIL_SENDER = 'contacts/email/sender_email_identity';
|
27 | 31 | public const XML_PATH_EMAIL_RECIPIENT = 'contacts/email/recipient_email';
|
@@ -61,6 +65,10 @@ public function postAction()
|
61 | 65 | /** @var Mage_Core_Model_Translate $translate */
|
62 | 66 | $translate->setTranslateInline(false);
|
63 | 67 | try {
|
| 68 | + if (!$this->_validateFormKey()) { |
| 69 | + Mage::throwException($this->__('Invalid Form Key. Please submit your request again.')); |
| 70 | + } |
| 71 | + |
64 | 72 | $postObject = new Varien_Object();
|
65 | 73 | $postObject->setData($post);
|
66 | 74 |
|
@@ -112,16 +120,26 @@ public function postAction()
|
112 | 120 |
|
113 | 121 | $translate->setTranslateInline(true);
|
114 | 122 | Mage::getSingleton('customer/session')->addSuccess($this->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
|
115 |
| - } catch (Mage_Core_Exception $e) { |
| 123 | + } catch (Mage_Core_Exception $exception) { |
116 | 124 | $translate->setTranslateInline(true);
|
117 |
| - Mage::logException($e); |
118 |
| - Mage::getSingleton('customer/session')->addError($e->getMessage()); |
119 |
| - } catch (Exception $e) { |
120 |
| - Mage::logException($e); |
| 125 | + Mage::logException($exception); |
| 126 | + Mage::getSingleton('customer/session')->addError($exception->getMessage()); |
| 127 | + } catch (Throwable $throwable) { |
| 128 | + Mage::logException($throwable); |
121 | 129 | Mage::getSingleton('customer/session')->addError($this->__('Unable to submit your request. Please, try again later'));
|
122 | 130 | }
|
123 | 131 | }
|
124 | 132 |
|
125 | 133 | $this->_redirect('*/*/');
|
126 | 134 | }
|
| 135 | + |
| 136 | + /** |
| 137 | + * Check if form key validation is enabled in contacts config. |
| 138 | + * |
| 139 | + * @return bool |
| 140 | + */ |
| 141 | + protected function _isFormKeyEnabled() |
| 142 | + { |
| 143 | + return Mage::getStoreConfigFlag(self::XML_CSRF_USE_FLAG_CONFIG_PATH); |
| 144 | + } |
127 | 145 | }
|
0 commit comments