CSRF attack detected when sending data using ajax

I am trying to submit a form using jquery in symfony 1.4, but the detected CSRF attack error appears every time. This is the code I use to submit form data:

$.ajax({
      type: 'post',
      cache: false,
      url: $('#assign-form form').attr('action'),
      data: (
        'activity[id]=' + $('#activity_id').val() +
        '&activity[_csrf_token]=' + $('#activity__csrf_token').val() +
        '&activity[assigned_to_user_id]=' + $('#activity_assigned_to_user_id').val() +
        '&activity[assigned_to_group_id]=' + $('#activity_assigned_to_group_id').val()
      )
});

Am I missing something?

Thanks Radu.

+3
source share
5 answers

One thing you need to pay attention to is whether the Form object that checks the input is the same class as the one that generated the token. By default, the class is used to generate the CSRF token.

, , , html, , , , , .

, .

, , ? .log() .

Um... , , , , "". JSON?

+1

, cookie - , cookie , (, iehttpheaders, wireshark, tamperdata)?

settings.yml?

.

0

.

CSRF ( ), Form /lib/form/...:

public function configure ()

  $this->disableLocalCSRFProtection();

, CSRF , , , / .

0

cookie ajax-? , , , HTTP- (, ) XMLHttpRequest, CSRF.

0

$ ('# activity__csrf_token'). Shaft()

Did you mean double underscore in this id element?

0
source

Source: https://habr.com/ru/post/1731617/


All Articles