Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop bots from using .submit() to bypass my 'required' fields?

I have a form which is producing a lot of spam. I have made all inputs required and have attached a captcha. This has not had any affect.

I assume the bots are using form.submit() as for some reason this bypasses all my required fields AND also bypasses my onsubmit="check(e)"

I cannot seem to grab this event .submit() by any means. Does anyone know how to catch this event and make sure it is cancelled. I want the only way to submit the form is through clicking the submit button.

$("#myForm").submit(function(event) {
    console.log("Handler for .submit() called.");

    if (CaptchaInput.value == "") {
        event.preventDefault();
    }
});

My code that was supposed to catch a .submit() call and prevent the form submission. This function is never triggered.

<form target="hidden_iframe" 
onsubmit="if (CaptchaInput.value == '') { why += '- Please Enter CAPTCHA Code.\n'; alert(why); return false; };return checkform(this)" id="myForm">
like image 945
tjway Avatar asked Sep 05 '19 08:09

tjway


People also ask

Why do bots fill out forms?

At other times, these bots are made to create fake leads on the behalf of the fraudster using them. Why would someone use form-filling bots on your ad campaigns? The primary reason is usually money. By generating a ton of bad or fake leads, a fraudster can claim credit and collect a big paycheck for minimal effort.

What steps do you take to block spam and bot accounts?

You can use a tool called Akismet to filter the spam comment, and it can be implemented using their API service. Time-analysis of forms: When it comes to forms, there are only a few fields that need to filled up during signup. Filling up these forms requires some time when a human does. While bots require no time.

Do bots run JavaScript?

These days, it's easy for attackers to create bots that can execute JavaScript (JS).


1 Answers

You cannot. I can submit your form without a browser, or with JavaScript disabled. Anyone can just send an HTTP POST request to your server, without going through any client-side process you may introduce.

The solution to your problem is to also verify on the server, and don't rely on the client side validation to have completed successfully (or indeed, even to have been run at all).

Treat client-side validation as a convenience to your users, they see the error immediately without having to retype and resubmit the entire form.

like image 144
Madara's Ghost Avatar answered Oct 14 '22 06:10

Madara's Ghost