Laravel seems to be adding an unused cookie with random name every refresh, filling up storage

I am running a Laravel project with Vue/Vite as front-end. Lately I have encountered an issue regarding cookie management, which I have attributed to some kind of misconfiguration after upgrading to Laravel 11 (from 10.3).

The problem

When reloading the page, 3 cookies are set: the laravel_session, the XSRF-TOKEN, and a third one with a random string as name. The first two work as intended, the third does not. If I reload the page, the first two cookies are overwritten, however the third is replaced with a fourth cookie with similar naming. Every reload this happens again (including during HMR from Vite), until eventually the cookie storage is full and reloading throws errors. On previous versions of my site this third cookie also exists, but it is always overwritten during reloads, so the cookie storage stays normal.

This problem exists on Laravel 10.10 and up, and does not exist on Laravel 10.9 or down. Previously I worked with 10.3 for a while, as does my live server currently, without this problem.

Setup

Laravel 11 (though this problem also seems to exist on Laravel 10.10 and up)

Guzzlehttp 7.8.1 (Same with v7.4.5 when running Laravel 10.10)

Laravel Sanctum 4.0 (Same with v3.2 when running Laravel 10.10)

Vite 5.3.1 & Vue 3.4.29

Running on Localhost

Relevant config:

.env

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>SESSION_SECURE_COOKIE=false
SESSION_DOMAIN=localhost
SANCTUM_STATEFUL_DOMAINS=localhost:8000,localhost:3000
</code>
<code>SESSION_SECURE_COOKIE=false SESSION_DOMAIN=localhost SANCTUM_STATEFUL_DOMAINS=localhost:8000,localhost:3000 </code>
SESSION_SECURE_COOKIE=false
SESSION_DOMAIN=localhost
SANCTUM_STATEFUL_DOMAINS=localhost:8000,localhost:3000

HttpKernel.php

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> protected $middlewareGroups = [
'web' => [
AppHttpMiddlewareEncryptCookies::class,
IlluminateCookieMiddlewareAddQueuedCookiesToResponse::class,
IlluminateSessionMiddlewareStartSession::class,
IlluminateViewMiddlewareShareErrorsFromSession::class,
AppHttpMiddlewareVerifyCsrfToken::class,
IlluminateRoutingMiddlewareSubstituteBindings::class,
],
'api' => [
LaravelSanctumHttpMiddlewareEnsureFrontendRequestsAreStateful::class,
'throttle:api',
IlluminateRoutingMiddlewareSubstituteBindings::class,
],
];
</code>
<code> protected $middlewareGroups = [ 'web' => [ AppHttpMiddlewareEncryptCookies::class, IlluminateCookieMiddlewareAddQueuedCookiesToResponse::class, IlluminateSessionMiddlewareStartSession::class, IlluminateViewMiddlewareShareErrorsFromSession::class, AppHttpMiddlewareVerifyCsrfToken::class, IlluminateRoutingMiddlewareSubstituteBindings::class, ], 'api' => [ LaravelSanctumHttpMiddlewareEnsureFrontendRequestsAreStateful::class, 'throttle:api', IlluminateRoutingMiddlewareSubstituteBindings::class, ], ]; </code>
    protected $middlewareGroups = [
    'web' => [
        AppHttpMiddlewareEncryptCookies::class,
        IlluminateCookieMiddlewareAddQueuedCookiesToResponse::class,
        IlluminateSessionMiddlewareStartSession::class,
        IlluminateViewMiddlewareShareErrorsFromSession::class,
        AppHttpMiddlewareVerifyCsrfToken::class,
        IlluminateRoutingMiddlewareSubstituteBindings::class,
    ],

    'api' => [
        LaravelSanctumHttpMiddlewareEnsureFrontendRequestsAreStateful::class,
        'throttle:api',
        IlluminateRoutingMiddlewareSubstituteBindings::class,
    ],
];

HttpMiddlewareVerifyCsrfToken.php

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>protected $except = [
'/api/logout',
'api/broadcasting/auth'
];
</code>
<code>protected $except = [ '/api/logout', 'api/broadcasting/auth' ]; </code>
protected $except = [
    '/api/logout',
    'api/broadcasting/auth'
];

The rest of the configuration is default or does not seem relevant from my searches. Keep in mind that this is the configuration for Laravel 10.10 and some changes might have to be made for the Laravel 11 upgrade.

What I’ve tried

I’ve searched around a lot to try and find the answers to this, read up on the documentation for Laravel, Laravel cookie management, Sanctum etc. I haven’t found anyone with this exact issues, but related issues mentioned the .env settings for session domains and sanctum stateful domains. From what I can tell the settings should be correct as I have them now. I’ve scoured the upgrade guides for Laravel, the changelogs for previous versions, the changes made between 10.9 and 10.10 and looked for any relevant information in these changes.

I have tried changing the ‘SANCTUM_STATEFUL_DOMAINS’ to ‘localhost’, which resolves the cookie problem, but prevents me from logging in, it just logs me straight back out. I also don’t think that’s the answer, just thought it relevant to mention. Most changes to ‘SESSION_DOMAIN’ prevents the site from setting any cookie correctly at all.

Edit: I have updated the live version of this site and it has the same problem (running Laravel 11, Vite 5, etc). In normal use it wouldn’t be an issue on production unless someone refreshes the page 20 times within 2 hours. This should rule out any settings related to localhost.

Any help would be appreciated, I’m still pretty new to development so there may be obvious things I’ve missed, and I’m happy to share more relevant info. Thanks in advance!

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật