skip to Main Content

I have a Django coded backend server, with Apache to serve(Windows)

When I submit a form (click on form submit in html) for n times, it submits the data n times into db and server

i.e. When I gave “abc” as input in text field and click on submit buttom for 10 times, I could see that the db has 10 record with “abc” as data.

I tried installing mod_evasive to prevent DDOS attack (thought this is a version of the attack), still I couldn’t stop users from submitting only for one time.

Django

def test_func(request):
    if request.method == "POST":
        form = test_form(request.POST)
        if form.is_valid():
            form.save()
            redirect <to the same function>
    else:
        form = test_form()
    return render <html page with form>

httpd.conf

LoadModule evasive_module modules/mod_evasive.so

<IfModule mod_evasive.so>
  DOSEnabled          true
  DOSHashTableSize    3097
  DOSPageCount        2
  DOSSiteCount        1
  DOSPageInterval     1
  DOSSiteInterval     1
  DOSBlockingPeriod   10
</IfModule>

Please help me on how to achieve this

Thanks in Advance

2

Answers


  1. If you want to limit the number of requests that can be made by a client, you can use a third-party-library that provide you throttle function.

    Here, I have found a package that provides us request throttling.

    Login or Signup to reply.
  2. It sounds like you are trying to solve a couple distinct issues.

    1. Preventing DDOS attacks
    2. Preventing users from submitting duplicate forms

    Just because you are throttling the number of requests your form can take in a defined time frame doesn’t mean that you will stop duplicate forms from being submitted by a user while the number of requests submitted are still less than the allotted amount.

    That being said, you need a way to enforce uniqueness of form submissions to prevent duplicate forms. To do this, you should create custom validators for your form. If you do this, you will be able to not only validate that the form can be submitted but if it can’t you can return a message to your user letting them know that the form was already submitted.

    https://docs.djangoproject.com/en/3.0/ref/forms/validation/#validators

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search