New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookie path not settable using $cookies service #1786

Closed
kgj opened this Issue Jan 10, 2013 · 35 comments

Comments

@kgj

kgj commented Jan 10, 2013

When using the $cookies service, there is no easy way to set the path of the cookie to match every path on the domain.

On line 3137 of angular.1.0.2.js the path of all cookies created is set as self.baseHref()
When trying to write the same cookie from different paths this results in additional cookies being created due to the different path.

With no facility implemented to pass in a path, the path needs to be hard coded in order to be changed.

alonbardavid added a commit to alonbardavid/angular.js that referenced this issue Apr 20, 2013

feat(ngCookies): support passing path/expires attributes to cookies
$cookieStore service had no way to set cookie attributes (such as expires).
The api for $cookieStore.put and $cookieStore.remove now has a third argument-
options,which allows setting cookie attributes, or deleting cookies under a
specific path.
- to change the path and/or expiration date of a cookie, you can pass an
  options object as the third argument to cookies(name,value).
  the options object can override Path and Expires when adding a value.
  You can pass either path, expires,none or both.
- the path option is checked to be a string and be partial to window.location
  otherwise, the default path is used. (warning is logged)
- the expires option is checked to be a Date and in the future,
  otherwise no expiration is set. (warning is logged)
- you can now delete a cookie on a specific path by calling
  cookie(name,undefined,{path:x})

The $cookie service remains unchanged since supporting cookie attributes
would mean serious backward comptability issues.
Foundations were put in place to make supporting $cookie easier.
GENERIC TEST CHANGE:
To support checking cookie path, all unit-tests now run on path "/karma/tests"
Documentation was updated for both $cookie and $cookieStore with examples.

closes	#1786, #1320
BREAKING CHANGE: As part of the change, deleting a cookie  now deletes
   cookies set in multiple paths (and duplicate cookies if exists).
   Previously only cookies set in the / path were deleted.
   Since it is not intutive, if this change breaks someones code, it is
   probably as an accidental side-effect.
   It is reasonable to assume that most people actually wanted to delete the
   cookie even if it wasn't set in the same path (since they can see it).
   So while this is a breaking change, it fixes bad behaviour.
   If needed, you can delete the cookie in a specific path using $cookieStore.
@mike-spainhower

This comment has been minimized.

Show comment
Hide comment

👍

@toovs

This comment has been minimized.

Show comment
Hide comment

toovs commented Aug 16, 2013

👍

@jaymes-bearden

This comment has been minimized.

Show comment
Hide comment
@jaymes-bearden

jaymes-bearden Oct 23, 2013

Did this ever get accepted?

Did this ever get accepted?

@odino

This comment has been minimized.

Show comment
Hide comment

odino commented Oct 29, 2013

👍

@hd-deman

This comment has been minimized.

Show comment
Hide comment

👍

@derfsubterfuge

This comment has been minimized.

Show comment
Hide comment

👍

@HNygard

This comment has been minimized.

Show comment
Hide comment
@HNygard

HNygard Mar 18, 2014

Contributor

👍

Contributor

HNygard commented Mar 18, 2014

👍

@andrezero

This comment has been minimized.

Show comment
Hide comment

👍

@greengerong

This comment has been minimized.

Show comment
Hide comment
@greengerong

greengerong Apr 2, 2014

We need this feature. +1

We need this feature. +1

@maxtillich

This comment has been minimized.

Show comment
Hide comment

+1

@petebacondarwin petebacondarwin self-assigned this Apr 9, 2014

@andyhorng

This comment has been minimized.

Show comment
Hide comment

+1

@paveleremin

This comment has been minimized.

Show comment
Hide comment

+1

@bdelaforest

This comment has been minimized.

Show comment
Hide comment

+1

@heretge

This comment has been minimized.

Show comment
Hide comment
@heretge

heretge May 16, 2014

Contributor

+1

Contributor

heretge commented May 16, 2014

+1

@WhyNotHugo

This comment has been minimized.

Show comment
Hide comment

👍

@krisivanov

This comment has been minimized.

Show comment
Hide comment

+1

@battlesnake

This comment has been minimized.

Show comment
Hide comment

+1

@bdelaforest

This comment has been minimized.

Show comment
Hide comment
@bdelaforest

bdelaforest Jun 16, 2014

In the meantime you can use https://github.com/ivpusic/angular-cookie.

example :
ipCookie('cookie_key', data, { path: '/' });

In the meantime you can use https://github.com/ivpusic/angular-cookie.

example :
ipCookie('cookie_key', data, { path: '/' });

@ansorensen

This comment has been minimized.

Show comment
Hide comment

+1

@h2non

This comment has been minimized.

Show comment
Hide comment
@h2non

h2non Jul 2, 2014

+1
I've finally used angular-cookie

h2non commented Jul 2, 2014

+1
I've finally used angular-cookie

@Meligy

This comment has been minimized.

Show comment
Hide comment

Meligy commented Jul 7, 2014

+1

@ajspera

This comment has been minimized.

Show comment
Hide comment
@ajspera

ajspera Aug 11, 2014

To anyone looking to keep all cookie paths the same everywhere, adding <base href="/"> to the head tag of your html will make all cookie paths "/" and accessible at any path.

ajspera commented Aug 11, 2014

To anyone looking to keep all cookie paths the same everywhere, adding <base href="/"> to the head tag of your html will make all cookie paths "/" and accessible at any path.

@chesleybrown

This comment has been minimized.

Show comment
Hide comment
@chesleybrown

chesleybrown Aug 17, 2014

Thank you @ajspera. Can confirm your solution works.

Thank you @ajspera. Can confirm your solution works.

@btford btford removed the gh: issue label Aug 20, 2014

@tenaciousRas

This comment has been minimized.

Show comment
Hide comment
@tenaciousRas

tenaciousRas Oct 14, 2014

Did the documentation get updated? The proposed solution seems like a workaround. It's been a while since I had to use base href on a website. The last time I did I'm pretty sure it was a legacy situation on the server side and we couldn't have used this workaround without piles of money and time to rebuild the backend. Isn't the bug/feature request a better solution overall than the one accepted to close this issue?

Did the documentation get updated? The proposed solution seems like a workaround. It's been a while since I had to use base href on a website. The last time I did I'm pretty sure it was a legacy situation on the server side and we couldn't have used this workaround without piles of money and time to rebuild the backend. Isn't the bug/feature request a better solution overall than the one accepted to close this issue?

@kleinerroemer

This comment has been minimized.

Show comment
Hide comment
@lynndylanhurley

This comment has been minimized.

Show comment
Hide comment
@toshipon

This comment has been minimized.

Show comment
Hide comment

toshipon commented Nov 7, 2014

👍

@vfiebig

This comment has been minimized.

Show comment
Hide comment

vfiebig commented Nov 7, 2014

+1

@selvakn

This comment has been minimized.

Show comment
Hide comment

selvakn commented Nov 17, 2014

👍

@web2wire

This comment has been minimized.

Show comment
Hide comment
@web2wire

web2wire Nov 25, 2014

+1

I have the opposite problem, I have a site at abc.xyz and I need cookies to be restricted to abc.xyz/a or abc.xyz/b etc so I need to be able to explicitly set the path of the cookies one level down from the base.

+1

I have the opposite problem, I have a site at abc.xyz and I need cookies to be restricted to abc.xyz/a or abc.xyz/b etc so I need to be able to explicitly set the path of the cookies one level down from the base.

@dallasvogels

This comment has been minimized.

Show comment
Hide comment

👍

@petebacondarwin petebacondarwin modified the milestones: 1.3.x, Backlog Dec 10, 2014

shahata added a commit to shahata/angular.js that referenced this issue Dec 19, 2014

shahata added a commit to shahata/angular.js that referenced this issue Dec 19, 2014

shahata added a commit to shahata/angular.js that referenced this issue Dec 19, 2014

shahata added a commit to shahata/angular.js that referenced this issue Jan 5, 2015

@FraGoTe

This comment has been minimized.

Show comment
Hide comment

FraGoTe commented Jan 28, 2015

👍

@afc163

This comment has been minimized.

Show comment
Hide comment

afc163 commented Feb 2, 2015

👍

@MikeElghali

This comment has been minimized.

Show comment
Hide comment

👍

@simonykq

This comment has been minimized.

Show comment
Hide comment

+1

shahata added a commit to shahata/angular.js that referenced this issue Feb 28, 2015

shahata added a commit to shahata/angular.js that referenced this issue Feb 28, 2015

shahata added a commit to shahata/angular.js that referenced this issue Feb 28, 2015

shahata added a commit to shahata/angular.js that referenced this issue Mar 1, 2015

shahata added a commit to shahata/angular.js that referenced this issue Mar 1, 2015

shahata added a commit to shahata/angular.js that referenced this issue Mar 2, 2015

feat($cookies): allow passing cookie options
The `put`, `putObject` and `remove` methods now take an options parameter
where you can provide additional options for the cookie value, such as `expires`,
`path`, `domain` and `secure`.

Closes #8324
Closes #3988
Closes #1786
Closes #950

shahata added a commit to shahata/angular.js that referenced this issue Mar 2, 2015

feat($cookies): allow passing cookie options
The `put`, `putObject` and `remove` methods now take an options parameter
where you can provide additional options for the cookie value, such as `expires`,
`path`, `domain` and `secure`.

Closes #8324
Closes #3988
Closes #1786
Closes #950

shahata added a commit to shahata/angular.js that referenced this issue Mar 2, 2015

feat($cookies): allow passing cookie options
The `put`, `putObject` and `remove` methods now take an options parameter
where you can provide additional options for the cookie value, such as `expires`,
`path`, `domain` and `secure`.

Closes #8324
Closes #3988
Closes #1786
Closes #950

shahata added a commit to shahata/angular.js that referenced this issue Mar 2, 2015

feat($cookies): allow passing cookie options
The `put`, `putObject` and `remove` methods now take an options parameter
where you can provide additional options for the cookie value, such as `expires`,
`path`, `domain` and `secure`.

Closes #8324
Closes #3988
Closes #1786
Closes #950

shahata added a commit to shahata/angular.js that referenced this issue Mar 2, 2015

feat($cookies): allow passing cookie options
The `put`, `putObject` and `remove` methods now take an options parameter
where you can provide additional options for the cookie value, such as `expires`,
`path`, `domain` and `secure`.

Closes #8324
Closes #3988
Closes #1786
Closes #950

@shahata shahata closed this in 92c366d Mar 2, 2015

hansmaad pushed a commit to hansmaad/angular.js that referenced this issue Mar 10, 2015

feat($cookies): allow passing cookie options
The `put`, `putObject` and `remove` methods now take an options parameter
where you can provide additional options for the cookie value, such as `expires`,
`path`, `domain` and `secure`.

Closes #8324
Closes #3988
Closes #1786
Closes #950

netman92 added a commit to netman92/angular.js that referenced this issue Aug 8, 2015

feat($cookies): allow passing cookie options
The `put`, `putObject` and `remove` methods now take an options parameter
where you can provide additional options for the cookie value, such as `expires`,
`path`, `domain` and `secure`.

Closes #8324
Closes #3988
Closes #1786
Closes #950
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment