From 5f0e69087409840a2013038d2f2ca5c42540418e Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Sun, 17 Jan 2016 16:26:17 +0100 Subject: [PATCH] Fixed reCaptcha driver. This fixes an issue where the reCaptcha driver would not add a model validation error in case captcha-validation failed, enabling bots to circumvent the validation altogether. --- .../Drivers/ReCaptchaPartDriver.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.AntiSpam/Drivers/ReCaptchaPartDriver.cs b/src/Orchard.Web/Modules/Orchard.AntiSpam/Drivers/ReCaptchaPartDriver.cs index 20c99c861..fbf2db7e7 100644 --- a/src/Orchard.Web/Modules/Orchard.AntiSpam/Drivers/ReCaptchaPartDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.AntiSpam/Drivers/ReCaptchaPartDriver.cs @@ -82,20 +82,23 @@ namespace Orchard.AntiSpam.Drivers { ReCaptchaPartResponseModel responseModel = _jsonConverter.Deserialize(result); if (!responseModel.Success) { - for (int i = 0; i < responseModel.ErrorCodes.Length; i++) { - if (responseModel.ErrorCodes[i] == "missing-input-response") { - _notifier.Error(T("The Captcha field is required")); + foreach (var errorCode in responseModel.ErrorCodes) { + if(errorCode == "missing-input-response") { + updater.AddModelError("", T("Please prove that you are not a bot.")); + _notifier.Error(T("Please prove that you are not a bot.")); } else { - _notifier.Error(T("There was an error with the Captcha please try again")); - Logger.Information("Error occurred while submitting a reCaptcha: " + responseModel.ErrorCodes[i]); + Logger.Information("An error occurred while submitting a reCaptcha: " + errorCode); + updater.AddModelError("", T("An error occurred while submitting a reCaptcha.")); + _notifier.Error(T("An error occurred while submitting a reCaptcha.")); } } } } catch (Exception e) { - Logger.Error(e, "An unexcepted error occurred while submitting a reCaptcha"); - updater.AddModelError("Parts_ReCaptcha_Fields", T("There was an error while validating the Captcha image")); + Logger.Error(e, "An unexcepted error occurred while submitting a reCaptcha."); + updater.AddModelError("", T("There was an error while validating the Captcha.")); + _notifier.Error(T("There was an error while validating the Captcha.")); } return Editor(part, shapeHelper);