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.
This commit is contained in:
Sipke Schoorstra
2016-01-17 16:26:17 +01:00
parent f47ce2a5f0
commit 5f0e690874

View File

@@ -82,20 +82,23 @@ namespace Orchard.AntiSpam.Drivers {
ReCaptchaPartResponseModel responseModel = _jsonConverter.Deserialize<ReCaptchaPartResponseModel>(result); ReCaptchaPartResponseModel responseModel = _jsonConverter.Deserialize<ReCaptchaPartResponseModel>(result);
if (!responseModel.Success) { if (!responseModel.Success) {
for (int i = 0; i < responseModel.ErrorCodes.Length; i++) { foreach (var errorCode in responseModel.ErrorCodes) {
if (responseModel.ErrorCodes[i] == "missing-input-response") { if(errorCode == "missing-input-response") {
_notifier.Error(T("The Captcha field is required")); updater.AddModelError("", T("Please prove that you are not a bot."));
_notifier.Error(T("Please prove that you are not a bot."));
} }
else { else {
_notifier.Error(T("There was an error with the Captcha please try again")); Logger.Information("An error occurred while submitting a reCaptcha: " + errorCode);
Logger.Information("Error occurred while submitting a reCaptcha: " + responseModel.ErrorCodes[i]); updater.AddModelError("", T("An error occurred while submitting a reCaptcha."));
_notifier.Error(T("An error occurred while submitting a reCaptcha."));
} }
} }
} }
} }
catch (Exception e) { catch (Exception e) {
Logger.Error(e, "An unexcepted error occurred while submitting a reCaptcha"); 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")); 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); return Editor(part, shapeHelper);