We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9102 ☆ A M B ☆
    • 318 Posts
    This is a re-post of an idea I posted on topliners.eloqua.com - but since I just saw some spam posts in the Revo forum, I thought I'd post it here as well and get your feedback and ideas. Maybe some version of this technique could be incorporated into Discuss at the post form level, so that even if a bot manages to create an account, it will have difficulty actually posting.

    However, I'm not sure this technique would have stopped the bot that was posting in the Revo forum, since it apparently somehow got past the "keep things human" test in the account creation form. This method is basically the same, with a bit of JS added to avoid bothering the user with the question if they have JS turned on - that may not matter on an account creation form, but on any sort of lead gen form you want to lower the barriers to entry as much as possible.

    I've been struggling with form spam recently, and found a solution that I like and thought would be worth posting about. I tried the "honeypot" technique described in this post: http://topliners.eloqua.com/community/do_it/blog/2013/04/19/experiencing-automated-form-spam-submissions-try-the-honeypot-method-to-counter-it, but I found that some of the bots attacking my forms were sophisticated enough to detect that the honeypot field is hidden, even if I used CSS or JavaScript to hide the field. So I tried a modified version of this technique which seems to be working well.

    Step 1: create a "honeypot" field

    • Create a new text field in your form (not a hidden field, we'll hide it with JS later).
    • The field label should be a question with an answer that would be obvious to any human, such as "what color is the sky?" If you're not confident that it's obvious enough, you can put something in the field instructions that says "just say blue." This is necessary so that the form will work with JavaScript disabled.
    • Set up your form processing steps to run conditionally only if the value of this field is "blue" or whatever the correct answer is. With FormIt, this could be done by using "contains" and "maxlength" validators.

    Step 2: hide the field using JavaScript

    • Don't use CSS to hide the field, because you want it to be visible if JavaScript is disabled so that the submitter can correctly answer the question.
    • Use JavaScript to set the "display" property of the field (or preferably, one of its parent elements) to "none." See sample jQuery code below.

    Step 3: populate the hidden field using a JavaScript event

    • The idea here is to use JavaScript to fill in the correct answer to the hidden field when the user takes an action that any human would have to take in order to fill out the form.
    • I settled on using the "focus" event on all form elements because even if the user is using their browser to auto-fill the fields, they will still have to place focus on some form element in order to submit the form.
    • If you use some other event, make sure that it's an event that any human user must trigger in order to submit the form, but not one that is automatically triggered when the page loads (such as window load) because some bots may be smart enough to execute it.

    Example Code (uses jQuery)

     
    <script type="text/javascript">  
    $(document).ready(function(){  
        $('#formElement7').hide();  
        $('input').focus(function(){  
            $('input[name="sky"]').val('blue');  
        });  
    });  
    </script>  
    

    Where formElement7 is the id of the honeypot field's parent div, sky is the name of the honeypot field, and blue is... well, the color of the sky. Obviously replace these values as needed for your form.

    So far this is working well for me - I'll post updates if I find that there are problems or if I want to recommend modifications to the technique.
      • 26027
      • 145 Posts
      Hi 'freejung'. I had been using a 'hidden field must be blank' HoneyPot for some time now ... and quite successfully. Unfortunately I've recently encountered one or more bots who could recognize CSS "display: none" hiding and react by avoiding the field. I thought I could beat it by changing the CSS to 'off-screen placement' and that's failing me as well.

      I'd like to ask you two questions:

      1. It's 8 months now (or more) since you implemented your Javscript routine. How's that been working for you?

      2. I've seen CAPTCHA pretty universally criticized for ease-of-use and other reasons, and I wonder what the web development community thinks of a simple question and answer as a way to force "humanization" on the form. Is that considered 'bush' or unprofessional or is it generally accepted?

      Thanks for any assistance. These bots have gotten the best of me for now.

      ... Sam, in Philly
        • 3749
        • 24,544 Posts
        @samg - Another easy way of hiding your honeypot field is to use CSS to give it an absolute position off the screen, and/or make its width 1 pixel, and/or make its color the same as the background color so it will be invisible though not technically hidden.

        @freejung - Really interesting idea. smiley
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 26027
          • 145 Posts
          BobRay, I already tried moving the Honey Pot off screen. I really banked on that working but the pesky bot saw through it anyway. The CSS I used was {
          position: absolute;
          top: -999999em;
          left: auto;
          width: 1px;
          height: 1px;
          overflow:hidden;
          }

          Yuk!!
            • 3749
            • 24,544 Posts
            They keep getting smarter. They can now decode a lot of CAPTCHA images wink

            I'm using SPForm at Bob's Guides with no CAPTCHA and haven't received a single spam email in over a year, but then maybe the site's not popular enough for them to want to crack it. I can't remember which anti-spam options I have turned on.

            I read that some spammers are hiring kids in the third world to fill out the forms by hand -- not sure if it's true.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 26027
              • 145 Posts
              Quote from: BobRay at Feb 17, 2014, 04:48 PM
              They keep getting smarter. They can now decode a lot of CAPTCHA images wink

              I'm using SPForm at Bob's Guides with no CAPTCHA and haven't received a single spam email in over a year, but then maybe the site's not popular enough for them to want to crack it. I can't remember which anti-spam options I have turned on.

              I read that some spammers are hiring kids in the third world to fill out the forms by hand -- not sure if it's true.
              I would like to think I'm the victim of 3rd world children. At least I would know my Honey Pot still works with spam bots. ;>)
                • 9102 ☆ A M B ☆
                • 318 Posts
                I'm still using the same technique and so far (knock wood) it's working great. I expect the bots will get wise sooner or later but I also think we could add a couple of further tricks to make this continue working once they get the basic version figured out.

                I haven't been able to find a way to hide the field so that the bots won't find it. That's why I started doing it this way.

                As for the question of testing for humanity by asking a question, I don't know what others think of it but I don't like it any better than captcha. That's why I set it up so that you only have to answer the question if you have JS disabled. That's a pretty small minority. For most people this method is seamless.
                  • 9102 ☆ A M B ☆
                  • 318 Posts
                  Oh - and I don't think there's anything to be done about the problem of crowdsourcing (using cheap third-world labor to perform tasks only a human can do). Make sure that submitting forms cannot possibly result in the submitter inserting a followed link on your site - then you're wasting their time, so presumably they'll get discouraged eventually and go away.
                    • 26027
                    • 145 Posts
                    freejung, I've been lucky so far (only a few days) by changing the name of the Honey Pot field and having it hidden by CSS 'offscreen' not "display: none". However, I don't hold out much hope of long term success using this method unless, perhaps, I can find a way to change all the field names automatically somehow.

                    This quandary got me thinking about your technique some more and I believe I like it. I've had very good success on my non-MODx web sites using JS to foil the bots.

                    I may use your technique but I don't like asking the user a simple question. I think I'll assume that everyone uses JS these days. I'll use my normal Honey Pot field and leave it blank. Then I'll use javascript unconditionally to enter some value into the field. I'll continue to have eForm validate the submission but instead of doing the normal Honey Pot check for field not empty, I'll check for the presence of the value I entered. This technique should be foolproof for as long as form bots avoid using javascript.

                    You don't need to respond to this post unless you see a problem with it.

                    Thanks ... Sam
                      • 40045
                      • 534 Posts
                      I also use the honeypot method on almost all of my sites but I don't hide the input field via type="hidden" or css "display: none;" but the container (in my case a div) that holds the input field, so if the bots check the only the input field itself, it seems like a normal field to them (hopefully)...I have quite good success with that, just occasional spams on one site so far, don't know how they get trough there though (maybe 3rd world children, don't know), but its not too bad, maybe once a week...