angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

More powerful $cookies service

Open reichart opened this issue 14 years ago • 67 comments

I want to set a cookie on the root path / so it's available everywhere on the domain.

But the $cookies service only accepts name and value, and always sets the cookie path to the current page via self.baseHref().

Could the $cookies service be extended to provide access to additional cookie properties like path, expires, domain and secure?

I quite like the API of the jquery.cookie plugin: https://github.com/carhartl/jquery-cookie#usage. It keeps the common name=value use case simple and allows to set additional cookie properties via a third options object parameter.

I'm not very proficient in Javascript but I might try to implement something over the weekend.

reichart avatar May 11 '12 11:05 reichart

Working on this (first version, I'm not worried about providing jquery's "raw" option), just updating tests now.

branch is here: https://github.com/jzacsh/angular.js/compare/master...issue950_cookies

jzacsh avatar Aug 31 '12 18:08 jzacsh

Hey, sorry I forgot to update this thread. Switched teams and don't have the time do this. Someone should take this on :-)

jzacsh avatar Mar 09 '13 19:03 jzacsh

any updates on this?

eddiemonge avatar Jul 31 '13 21:07 eddiemonge

+1 for updates and a resolution

solidspark avatar Sep 11 '13 21:09 solidspark

+1 Not supporting secure cookies is a security issue and should be addressed ASAP.

wkonkel avatar Sep 24 '13 20:09 wkonkel

Just added a $200 bounty to this issue: https://www.bountysource.com/issues/68135-more-powerful-cookies-service

+1

rappo avatar Sep 25 '13 20:09 rappo

you could always use a different library like: https://github.com/grevory/angular-local-storage

eddiemonge avatar Sep 25 '13 20:09 eddiemonge

Would it not be possible to simply replace the existing code for cookie control with a third-party library like jQuery Cookie https://github.com/carhartl/jquery-cookie

This plugin provides support for custom expiry dates, domain names (set example.com from sub.example.com etc), path values, and secure cookies, thus:

$.cookie('cookiename', 'cookievalue', { expires: 7, path: '/', domain: 'example.com', secure: true });

lewisgoddard avatar Oct 06 '13 19:10 lewisgoddard

Although local-storage and jQuery both provide workarounds, this ticket is for fixing the core issue within AngularJS so workarounds aren't necessary.

wkonkel avatar Oct 07 '13 18:10 wkonkel

angular-cookies is no longer 'core'. its more of a Angular team supported plugin now.

eddiemonge avatar Oct 07 '13 18:10 eddiemonge

+1

Narretz avatar Dec 17 '13 16:12 Narretz

+1 - for reference this seems to work pretty well - https://github.com/ivpusic/angular-cookie - but I still think this should be part of the included Angular cookie plugin.

bwdolphin avatar Dec 17 '13 16:12 bwdolphin

+1

johannesjo avatar Dec 29 '13 00:12 johannesjo

+1 We were just bitten by this, with cookies being shared between different environments running on the same host but different ports.

The current implementation is dangerous IMO, as it makes it impossible to properly secure cookies you create. This is going to lead to Angular apps which are vulnerable to XSS attacks.

jonrimmer avatar Feb 12 '14 12:02 jonrimmer

+1 what is the current status?

lucianenache avatar Feb 12 '14 20:02 lucianenache

+1 I'd like to be able to set path, expiry and domain

kbanman avatar Feb 19 '14 00:02 kbanman

:+1:

HNygard avatar Mar 18 '14 09:03 HNygard

+1

jamiemccrindle avatar Apr 09 '14 09:04 jamiemccrindle

+1 any update?

I want to use $cookieStore to store data that can be read by javascript running on any of my products subdomains (lasvegas.x.com, losangeles.x.com)

mellodev avatar Apr 16 '14 23:04 mellodev

+1

tniswong avatar Apr 24 '14 03:04 tniswong