Laravel TokenMismatchExpection when publishing inside iframe

I have a page working on http://some.example.com/myiframes/default.aspx. There is an iframe on this page. The iframe / source contains the base Laravel 5.2 application.

My url of the Laravel page, which is the source of the iframe, is https://laravel.example.com .

https://laravel.example.com has a form with a submit button. When use clicks it, he / she performs another route in the same domain, i.e. https://laravel.example.com/disply/survey

But every time I submit the form, I get the following exception

TokenMismatchException in VerifyCsrfToken.php line 67:

To make sure I understand, on the page, http://some.example.com/myiframes/default.aspxmy code looks something like this:

 

in my laravel application which is on https://laravel.example.com, here is my form

    <form method="POST" action="https://laravel.example.com/disply/survey" accept-charset="UTF-8" class="form">
<input name="_token" type="hidden" value="Dk6SN4WzO4brbvdnBO6JZ7e1lBGjmYz8GQJ1lYFo">
<input name="survey_id" type="hidden" value="10">
<input name="call_id" type="hidden" value="667">
<input name="pools" type="hidden">

<input name="alt_id_1" type="hidden" value="250">
<input name="alt_id_2" type="hidden" value="5">
<input name="alt_id_3" type="hidden">
<input name="alt_id_4" type="hidden">
<input name="alt_id_5" type="hidden">
<input name="alt_id_6" type="hidden">
<input name="alt_id_7" type="hidden">
<input name="alt_id_8" type="hidden">
<input name="alt_id_9" type="hidden">
<input name="alt_id_10" type="hidden">


<input name="alt_string_1" type="hidden">
<input name="alt_string_2" type="hidden">
<input name="alt_string_3" type="hidden">
<input name="alt_string_4" type="hidden">
<input name="alt_string_5" type="hidden">
<input name="alt_string_6" type="hidden">
<input name="alt_string_7" type="hidden">
<input name="alt_string_8" type="hidden">
<input name="alt_string_9" type="hidden">
<input name="alt_string_10" type="hidden">

<div class="text-center"> 
    <input class="btn btn-primary" type="submit" value="Start Survey">
</div>

</form>

iframe. , iframe.

VerifyCsrfToken, App\Http\Middleware, http://some.example.com $except, .

protected $except = [
    'http://some.example.com'
];

? ?

,

{!! Form::open([
                'url' => route('my.surveys.display'),
                'class' => 'form',
                'method' => 'post'
                ]) !!}
{!! Form::hidden('survey_id', $survey_id) !!}
{!! Form::hidden('call_id', $call_id) !!}
{!! Form::hidden('pools', $pools) !!}
{!! Form::hidden('call_type', $type) !!}


{!! Form::hidden('alt_id_1', $alt_id_1) !!}
{!! Form::hidden('alt_id_2', $alt_id_2) !!}
{!! Form::hidden('alt_id_3', $alt_id_3) !!}
{!! Form::hidden('alt_id_4', $alt_id_4) !!}
{!! Form::hidden('alt_id_5', $alt_id_5) !!}
{!! Form::hidden('alt_id_6', $alt_id_6) !!}
{!! Form::hidden('alt_id_7', $alt_id_7) !!}
{!! Form::hidden('alt_id_8', $alt_id_8) !!}
{!! Form::hidden('alt_id_9', $alt_id_9) !!}
{!! Form::hidden('alt_id_10', $alt_id_10) !!}


{!! Form::hidden('alt_string_1', $alt_string_1) !!}
{!! Form::hidden('alt_string_2', $alt_string_2) !!}
{!! Form::hidden('alt_string_3', $alt_string_3) !!}
{!! Form::hidden('alt_string_4', $alt_string_4) !!}
{!! Form::hidden('alt_string_5', $alt_string_5) !!}
{!! Form::hidden('alt_string_6', $alt_string_6) !!}
{!! Form::hidden('alt_string_7', $alt_string_7) !!}
{!! Form::hidden('alt_string_8', $alt_string_8) !!}
{!! Form::hidden('alt_string_9', $alt_string_9) !!}
{!! Form::hidden('alt_string_10', $alt_string_10) !!}

<div class="text-center"> 
    {!! Form::submit('Start Survey', ['class' => 'btn btn-primary', 'id' => 'start_survey']) !!}
</div>
+4
2

, , , Laravel , , .

- http://some.example.com POST https://laravel.example.com iframe. , , CSRF.

Laravel 5 TokenMismatchException iFrame. .

, , POST ing, .

+2

https://laravel.com/docs/master/routing#csrf-x-csrf-token

X-CSRF-

CSRF POST, Laravel VerifyCsrfToken X-CSRF-TOKEN. , meta:

, , , jQuery, . CSRF AJAX:

$. AjaxSetup ({       : {            "X-CSRF-TOKEN": $('meta [name= "csrf-token" ]'). Attr ('content')       } });

X-XSRF-

Laravel CSRF cookie XSRF-TOKEN. cookie X-XSRF-TOKEN. JavaScript, Angular, . , .

0

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


All Articles