Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Secure Cookie on `http://localhost`

I'm trying to set a secure cookie on http://localhost:3000:

Set-Cookie: loggedUser=brillout; Max-Age=315360000; Path=/; HttpOnly; Secure

But Chrome complains:

This Set-Cookie was blocked because it had the "Secure" attribute but was not received over a secure connection.

Yet, according to MDN, it should work:

A cookie with the Secure attribute is sent to the server only with an encrypted request over the HTTPS protocol, never with unsecured HTTP (except on localhost)

Is it possible to set Secure while being http://localhost? Developing on https://localhost instead of http://localhost is not an option.

like image 521
brillout Avatar asked Apr 09 '26 12:04

brillout


1 Answers

At the time of writing, the Chrome browser stands at Version 100.0.4896.75, the browser is not giving an error or warning. I can easily set cookie from my localhost with attributes given by you. But If you are still getting errors, you could easily install the SSL certificate on your localhost (read this blog) and it will resolve your problem.

Hope this helped you!

like image 87
Prabhsharan Sandhu Avatar answered Apr 12 '26 22:04

Prabhsharan Sandhu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!