Laravel Türkiye Discord Kanalı Forumda kod paylaşılırken dikkat edilmesi gerekenler!Birlikte proje geliştirmek ister misiniz?
Selam Üstadlar,

Cok acil yardımlarınızı bekliyorum.

"Odeme" diye bir rotam mevcut ;
Route::match(['get','post'],'odeme', [PaymentController::class,'odeme'])->name('odeme');

Nestpay ile 3d ödeme aldıktan sonra nestpayın callback urlsinden gelen datayı karşılıyorum. başarılı ise
return redirect()->route('odeme'); ile yonlendiriyorum. Ancak buradan yonlendirdiğimde Odeme içine giriyor. Fakat Logout'a düşüyor.

VerifyCsrfToken $expect'e callback urllerini koydum.

protected $except = [
        'item/fail',
        'item/success'
    ];
return redirect()->route('odeme');
``` 
Ayrıca yonlendirdiğim odeme rotasınıda VerifyCsrfToken da koydum . Bu sefer "Odeme" içinde Auth::id() alanları null geliyor. Haliyle patlıyor.
Yardımlarınızı bekliyorum. Şimdiden Teşekkürler.
  • Unutmadan bu değişiklikleri yaptıktan sonra config önbelleği ve önbelleği temizlemeyin.

Kullanıcı logout oluyor ise cookie samesite parametresi eksik olabilir.

    Leon Selam Leon,
    config/session daki same_site => 'lax' durumda bura ile oynadım ama sorun düzelmedi.

    • Leon

        Seviye 31
      • Düzenlendi

      @echo75 ben none olması gerekiyor diye biliyorum ama same_site => ‘none’

        Leon none yapınca Login olamıyorum 🙂

        Cookieleri temizleyip tekrar login olmayı dene

        Benim sıkıntım şu. POST ile ödeme aldığım sayfa eft ile aldığımda sıkıntı olmuyor. Çünkü kendi form csrf sini kullanıyorum.
        Ancak Kredi Kartı ile (nestpay formu) aldığımda callbackurl den Doğrudan ödeme sayfasına yönlendirdiğim için token hatasına düşüyorum.Çok araştırdım. Söyle bir link de buldum.
        http://www.koraysadiklar.com.tr/laravel-iyzico-sanal-pos-entegrasyonu
        bu link üzerinden de gittim bir türlü sonuc alamadım

        Kredi kartı bilgilerini aldık post ettik bankaya sonra müşteri ödemeyi yaptı bize callback ile bilgi dönüyor şu kadar çekmek istedi onayladım sende tamamsan çekeyim. Tamam dedikten sonra sana başarılı cevabı gelirse istediğin sayfaya redirect edebilirsin müşteriyi. Csrf except edebilirsin sana gelen callbackurl için

          Leon Csrf expect ediyorum . Beni logout ediyor.. Tekrar giriş yaptığımda ödeme sonuc sayfasına düşüyor.Kaçırdığım bir yer var bulamıyorum. Expect ettim datalarda bankadan gelen success ve fail yaptım olmadı. Ayrıyetten Odeme yaptığım controllerdaki rotayı da expect ekledim. Değişen bir sonuc olmadı.

          Logout olmasının tek nedeni cookie sorunu. Browserdan baktığınızda same site none görmeniz lazım.

            Leon config/session.php içindeki same_site none çevirdim.Tarayıcı cache sildim .Bu sefer login olurken 419 'a düşüyorum.

            • Leon bunu yanıtladı.

              echo75 Aşağıdaki gibi test ettiğimde sorunsuz login çalışıyor.

              .env dosyanda yoksa aşağıdaki satırları ekle.
              SESSION_DOMAIN=siteninadresi.com // başına www varsa .siteninadresi.com
              SESSION_SECURE_COOKIE=true // sitede veya test ortamda ssl yok ise false

              config/session.php

              <?php
              
              use Illuminate\Support\Str;
              
              return [
              
                  /*
                  |--------------------------------------------------------------------------
                  | Default Session Driver
                  |--------------------------------------------------------------------------
                  |
                  | This option controls the default session "driver" that will be used on
                  | requests. By default, we will use the lightweight native driver but
                  | you may specify any of the other wonderful drivers provided here.
                  |
                  | Supported: "file", "cookie", "database", "apc",
                  |            "memcached", "redis", "dynamodb", "array"
                  |
                  */
              
                  'driver' => env('SESSION_DRIVER', 'file'),
              
                  /*
                  |--------------------------------------------------------------------------
                  | Session Lifetime
                  |--------------------------------------------------------------------------
                  |
                  | Here you may specify the number of minutes that you wish the session
                  | to be allowed to remain idle before it expires. If you want them
                  | to immediately expire on the browser closing, set that option.
                  |
                  */
              
                  'lifetime' => env('SESSION_LIFETIME', 120),
              
                  'expire_on_close' => false,
              
                  /*
                  |--------------------------------------------------------------------------
                  | Session Encryption
                  |--------------------------------------------------------------------------
                  |
                  | This option allows you to easily specify that all of your session data
                  | should be encrypted before it is stored. All encryption will be run
                  | automatically by Laravel and you can use the Session like normal.
                  |
                  */
              
                  'encrypt' => false,
              
                  /*
                  |--------------------------------------------------------------------------
                  | Session File Location
                  |--------------------------------------------------------------------------
                  |
                  | When using the native session driver, we need a location where session
                  | files may be stored. A default has been set for you but a different
                  | location may be specified. This is only needed for file sessions.
                  |
                  */
              
                  'files' => storage_path('framework/sessions'),
              
                  /*
                  |--------------------------------------------------------------------------
                  | Session Database Connection
                  |--------------------------------------------------------------------------
                  |
                  | When using the "database" or "redis" session drivers, you may specify a
                  | connection that should be used to manage these sessions. This should
                  | correspond to a connection in your database configuration options.
                  |
                  */
              
                  'connection' => env('SESSION_CONNECTION', null),
              
                  /*
                  |--------------------------------------------------------------------------
                  | Session Database Table
                  |--------------------------------------------------------------------------
                  |
                  | When using the "database" session driver, you may specify the table we
                  | should use to manage the sessions. Of course, a sensible default is
                  | provided for you; however, you are free to change this as needed.
                  |
                  */
              
                  'table' => 'sessions',
              
                  /*
                  |--------------------------------------------------------------------------
                  | Session Cache Store
                  |--------------------------------------------------------------------------
                  |
                  | While using one of the framework's cache driven session backends you may
                  | list a cache store that should be used for these sessions. This value
                  | must match with one of the application's configured cache "stores".
                  |
                  | Affects: "apc", "dynamodb", "memcached", "redis"
                  |
                  */
              
                  'store' => env('SESSION_STORE', null),
              
                  /*
                  |--------------------------------------------------------------------------
                  | Session Sweeping Lottery
                  |--------------------------------------------------------------------------
                  |
                  | Some session drivers must manually sweep their storage location to get
                  | rid of old sessions from storage. Here are the chances that it will
                  | happen on a given request. By default, the odds are 2 out of 100.
                  |
                  */
              
                  'lottery' => [2, 100],
              
                  /*
                  |--------------------------------------------------------------------------
                  | Session Cookie Name
                  |--------------------------------------------------------------------------
                  |
                  | Here you may change the name of the cookie used to identify a session
                  | instance by ID. The name specified here will get used every time a
                  | new session cookie is created by the framework for every driver.
                  |
                  */
              
                  'cookie' => env(
                      'SESSION_COOKIE',
                      Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
                  ),
              
                  /*
                  |--------------------------------------------------------------------------
                  | Session Cookie Path
                  |--------------------------------------------------------------------------
                  |
                  | The session cookie path determines the path for which the cookie will
                  | be regarded as available. Typically, this will be the root path of
                  | your application but you are free to change this when necessary.
                  |
                  */
              
                  'path' => '/',
              
                  /*
                  |--------------------------------------------------------------------------
                  | Session Cookie Domain
                  |--------------------------------------------------------------------------
                  |
                  | Here you may change the domain of the cookie used to identify a session
                  | in your application. This will determine which domains the cookie is
                  | available to in your application. A sensible default has been set.
                  |
                  */
              
                  'domain' => env('SESSION_DOMAIN', null),
              
                  /*
                  |--------------------------------------------------------------------------
                  | HTTPS Only Cookies
                  |--------------------------------------------------------------------------
                  |
                  | By setting this option to true, session cookies will only be sent back
                  | to the server if the browser has a HTTPS connection. This will keep
                  | the cookie from being sent to you if it can not be done securely.
                  |
                  */
              
                  'secure' => env('SESSION_SECURE_COOKIE'),
              
                  /*
                  |--------------------------------------------------------------------------
                  | HTTP Access Only
                  |--------------------------------------------------------------------------
                  |
                  | Setting this value to true will prevent JavaScript from accessing the
                  | value of the cookie and the cookie will only be accessible through
                  | the HTTP protocol. You are free to modify this option if needed.
                  |
                  */
              
                  'http_only' => true,
              
                  /*
                  |--------------------------------------------------------------------------
                  | Same-Site Cookies
                  |--------------------------------------------------------------------------
                  |
                  | This option determines how your cookies behave when cross-site requests
                  | take place, and can be used to mitigate CSRF attacks. By default, we
                  | will set this value to "lax" since this is a secure default value.
                  |
                  | Supported: "lax", "strict", "none", null
                  |
                  */
              
                  'same_site' => 'none',
              
              ];

                Unutmadan bu değişiklikleri yaptıktan sonra config önbelleği ve önbelleği temizlemeyin.

                  Sevgili Leon sorunum çözüldü. Çok teşekkür ederim.
                  Bu yapılandırma güvenlik açısından bir sorun teşkil eder mi ?

                  • Leon bunu yanıtladı.

                    echo75 Sitede https yoksa zaten güvenlik sorunu var demektir. SESSION_SECURE_COOKIE=true şeklinde olduğunda güvenlik sorunu yok demektir. sadece https olarak çalışır.

                    http_only => false olursa güvenlik açığı var. JS ile cookieler okunabilir. XSS

                    http_only => true olursa güvenlik var. Cookieler için XSS açığına maruz kalmazsınız.

                    Özetle httponly true; SameSite=None; secure; ise sorun yok.

                      Leon Harika bilgiler verdin. Çok teşekkür ederim.

                      Leon Bu 'same_site' kısmının none bırakılması bir güvenlik zaafı oluşturur mu?

                      • Leon

                          Seviye 31
                        • Düzenlendi

                        @BoraN7

                        Gönderilen istekler kısmında CSRF tokenimiz devreye giriyor.

                        Birde tabi olmazsa olmaz http_only seçeneğimiz var, buda cookiemizi koruyor JS ile okunmuyor XSS engelliyoruz.

                        SameSite=Strict
                        Diğer domainlerden istek kabul etmiyor.

                        SameSite=Lax
                        Diğer domainlerden sadece GET istek kabul ediyor. POST DELETE PUT v.b. kabul etmiyor.

                        SameSite=none
                        Gel anam babam döner 9.99₺ yiyen cennete gidiyor 🙂
                        Bu kısımda callback url'mizde CSRF kapattığımız için banka ile aramızdaki hash kontrolümüzü yapıyoruz.

                        Leon Özetle httponly true; SameSite=None; secure; ise sorun yok.

                          Leon 'same_site' olayını özelikle sordum çünkü @coder2 baska bir konuda su sekilde belirtmiş;

                          coder2 Taylor Otwell same_site değerinin lax olarak tutulmasını tavsiye ediyor.

                          İyzico dan gelen callback url i app/Http/Middleware/VerifyCsrfToken.php içerisinde protected $except kısmına ekleyerek csrf korumasından muaf tutabilirsiniz. (İyzico entegrasyonu daha önce yapmadım ama bu şekilde sorun olduğuna göre muhtemelen callback url e post methoduyla geliyor)

                          3 ay sonra

                          Login işlemlerinde sıkıntı yaşıyorum. İşlem başarılı ama session da tutmuyor.