Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

995
Views
Embedded Laravel App In Iframe, Give 302 Error On Login

I'm trying to use the Laravel app in some other domain within iframe.

I had written a FrameMiddleware in which I have allowed that domain in the header

 public function handle(Request $request, Closure $next)
    {
        $response = $next($request);
        $response->header('Content-Security-Policy', 'frame-ancestors http://localhost');
        return $response;
    }

and by using the above middleware cors origin error removed.

As my Laravel app needs authentication from the iframe. and it's using form submission, not API. Then it starts to give a
419 error. I resolved by adding a login route in VerifyCsrfToken Middleware $except array for excluding csrf error.

then I check network and the post request for login give 302 error

laravel within iframe give 302 error for post request

I tested the authentication method and authenticated user object is returning with Dashboard page redirect and then 302 error code shown.

Moreover, I had set same_site => null in config/session.php but still not working.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

As @apokryfos said, I need to set the cookie to be secure and set SameSite=None.

Goto : config/session.php

set: 'same_site' => 'none' and 'secure' => env('SESSION_SECURE_COOKIE', true) OR by setting SESSION_SECURE_COOKIE = true in .env file.

and don't forget to create FrameMiddleware as you can follow-my-question-thread and white_labeled the domain i.e http://localhost in which you are embedding iframe.

Note: you can verify cookies are secured or not along with SameSite=Null by using browser dev-tools as shown in the below image:

cookies secured and SameSite=Null Verification

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!