ngx-cookie-service: Cookie not being set in Chrome versions > 80 with ngx-cookie-service 2.4.0

Expected Behavior

Using ngx-cookie-service 2.4.0, when a cookie is being set with key, value, Chrome browser should set the cookies in all browsers. this.cookieService.set(‘runOffline’, ‘true’);

Actual Behavior

No cookie is being set in the chrome browsers with version > 80(the latest version).

Reason

For some reason there are other libraries that are creating cookies and the cookies found in document.cookie does not start with a space. So setting a cookie in this condition does not actually set the cookie.

Steps to Reproduce the Problem

Just download the latest version of chrome and set the cookie

Specifications

  • Version: 2.4.0
  • Browser: Chrome Version 80.0.3987.132
  • OS: Ubuntu 18.04

Steps to Reproduce the Problem

Set the cookie the traditional way by leaving a space initially eg.

document.cookie = " runOffline=true; " + document.cookie

Notice the space in the beginning for some reason works well.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 6
  • Comments: 35 (12 by maintainers)

Most upvoted comments

Version 3.0 still doesn’t work

macOS, Chrome Version 80.0.3987.132 (Official Build) (64-bit)

temporary fix: pass all arguments when setting a new cookie. this.cookieService.set(‘name’, ‘John’, null, null, null, null, null);

@stevermeister yes it should fix it.

But in the case where a cookie is set with the samesite = none (via the cookieService.set method) the secure flag always has to be set. So I don’t know if ngx-cookie-service should override the secure flag if mode is none

Doing this will result with a reject from the browser :

this._cookieService.set(
cookieName,
cookieValue,
expirationDate,
'/',
someData,
false, <- secure flag
'None' <- sameSite property
);

Doing this will work

this._cookieService.set(
cookieName,
cookieValue,
expirationDate,
'/',
someData,
true, <- secure flag
'None' <- sameSite property
);

Doing this will work

this._cookieService.set(
cookieName,
cookieValue,
expirationDate,
'/',
someData,
true, <- secure flag
'Strict' <- sameSite property
);

It is not working for me also, Somebody has the solution? Unable to set cookies in chrome > 80.

worked for me after upgrading version to 3.0.1, Thanks 😃

None of those actually works. Chrome 80 unable to set cookie.

@stevermeister I made a repo where you can see the warning : https://github.com/Yohandah/ngx-cookie-bug-secure

  • Clone
  • npm i
  • npm run start
  • access localhost:4200 with Chrome (I’m using v80.0.3987.132 64bits)
  • open console
  • see the warning in the console, and in the application tab the cookie setted without secure (if you don’t : press f5)

@Yohandah could you please check version 3.0.0?