Skip to content

Commit

Permalink
Fixed embedded form validation issues with CR/LF. Thanks to jmason03 …
Browse files Browse the repository at this point in the history
…on the forums for catching this.
  • Loading branch information
timbuckingham committed Feb 24, 2015
1 parent 2173888 commit c9ca655
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 11 additions & 1 deletion core/admin/ajax/auto-modules/embeddable-form/process.php
Expand Up @@ -15,8 +15,18 @@
};
$hash_recurse($_POST);

// Clean out carriage return and line feed characters since JS and PHP seem to disagree on their presence
$cleaned_string = "";
for ($i = 0; $i < strlen($complete_string); $i++) {
$char = substr($complete_string,$i,1);
$code = ord($char);
if ($code != 10 && $code != 13) {
$cleaned_string .= $char;
}
}

// Stop Robots - See if it matches the passed hash and that _bigtree_email wasn't filled out
if ($_POST["_bigtree_hashcash"] != md5($complete_string) || $_POST["_bigtree_email"]) {
if ($_POST["_bigtree_hashcash"] != md5($cleaned_string) || $_POST["_bigtree_email"]) {
$_SESSION["bigtree_admin"]["post_hash_failed"] = true;
BigTree::redirect($_SERVER["HTTP_REFERER"]);
}
Expand Down
14 changes: 12 additions & 2 deletions core/admin/js/main.js
Expand Up @@ -2354,7 +2354,7 @@ var BigTreeFormValidator = Class.extend({
});

// If this is an embedded form, we want to generate a hash of everything
complete_submission = "";
var complete_submission = "";
if ($("#bigtree_hashcash_field").length) {
this.form.find("input,select,textarea").not("#bigtree_hashcash_field").each(function() {
if ($(this).is("textarea") && $(this).css("display") == "none") {
Expand All @@ -2373,7 +2373,17 @@ var BigTreeFormValidator = Class.extend({
}
}
});
$("#bigtree_hashcash_field").val(md5(complete_submission));

// Remove carriage return and line feed since PHP and JS disagree on their presence
var cleaned_submission = "";
for (i = 0; i < complete_submission.length; i++) {
var code = complete_submission.charCodeAt(i);
if (code != 10 && code != 13) {
cleaned_submission += complete_submission[i];
}
}

$("#bigtree_hashcash_field").val(md5(cleaned_submission));
}

if (this.form.find(".form_error").length) {
Expand Down

0 comments on commit c9ca655

Please sign in to comment.