# 添加路径到Cookie

**URL:** https://meta.discourse.org/t/add-path-to-cookie/40218
**Category:** Development
**Created:** [2016年二月26日 09:42 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218 "2016-02-26T09:42:05Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![vikaskedia](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vikaskedia/32/73333_2.png) [@vikaskedia](https://meta.discourse.org/u/vikaskedia)
#### Post date: [2017年六月21日 15:35 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/21 "2017-06-21T15:35:12Z")

</div>

@sam I took your suggestion .. deleted all the cookies and I still hit the bug.

Please see the attached video:

https://www.youtube.com/embed/mmkTyxeX8nE?feature=oembed&wmode=opaque

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [2017年六月21日 18:48 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/22 "2017-06-21T18:48:38Z")

</div>

I can go back and forth between two sites at the same domain, different subfolders, and I don’t see anything out of the ordinary hitting the auth logs.

```plaintext
6 - seen token
5 - rotate
4 - seen token
3 - rotate
...

```

Those don’t happen very often.

---

<div class="post-metadata">

### Author: ![vikaskedia](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vikaskedia/32/73333_2.png) [@vikaskedia](https://meta.discourse.org/u/vikaskedia)
#### Post date: [2017年六月21日 18:54 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/23 "2017-06-21T18:54:08Z")

</div>

@neil I can give you access to my system remotely if it helps you debug.

I am able to replicate the bug in the video every time.

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [2017年六月21日 18:54 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/24 "2017-06-21T18:54:55Z")

</div>

I believe you, but subfolder debugging… ugh. Still working on it.

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [2017年六月21日 19:51 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/25 "2017-06-21T19:51:44Z")

</div>

So you deleted your cookies but still have the problem?

---

<div class="post-metadata">

### Author: ![vikaskedia](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vikaskedia/32/73333_2.png) [@vikaskedia](https://meta.discourse.org/u/vikaskedia)
#### Post date: [2017年六月21日 19:54 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/26 "2017-06-21T19:54:18Z")

</div>

> [@neil](#):
>
> So you deleted your cookies but still have the problem?

yes .. I wanted to make sure I did it .. so I also recorded it in the video

https://www.youtube.com/embed/mmkTyxeX8nE?feature=oembed&wmode=opaque

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [2017年六月21日 20:18 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/27 "2017-06-21T20:18:06Z")

</div>

Hmm, the problem definitely goes away for me when i’ve cleared cookies. Do yours look like this now?

![](https://global.discourse-cdn.com/meta/original/3X/7/6/76db43aae700fc744cd4440989223dce7702d177.png)

---

<div class="post-metadata">

### Author: ![vikaskedia](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vikaskedia/32/73333_2.png) [@vikaskedia](https://meta.discourse.org/u/vikaskedia)
#### Post date: [2017年六月21日 20:33 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/28 "2017-06-21T20:33:47Z")

</div>

Yes !!

 ![](https://global.discourse-cdn.com/meta/original/3X/4/6/465a44a54424fbebe5712eb5b64f57b449b32c86.png)

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [2017年六月21日 20:35 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/29 "2017-06-21T20:35:13Z")

</div>

I reverted the other fix, so you should undo that change since it’s worse behaviour than before. I don’t understand what you’re seeing, or how to fix what I’m seeing.

---

<div class="post-metadata">

### Author: ![vikaskedia](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vikaskedia/32/73333_2.png) [@vikaskedia](https://meta.discourse.org/u/vikaskedia)
#### Post date: [2017年六月21日 20:37 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/30 "2017-06-21T20:37:20Z")

</div>

> [@neil](#):
>
> I don’t understand what you’re seeing, or how to fix what I’m seeing.

maybe its time for big boss @sam to step in !!

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2017年六月21日 22:13 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/31 "2017-06-21T22:13:28Z")

</div>

We are deferring on this for now. Running two instances of Discourse on the same domain in different subfolders is not a supported config _at the moment_. We may circle back to this in a few months, though.

---

<div class="post-metadata">

### Author: ![vikaskedia](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vikaskedia/32/73333_2.png) [@vikaskedia](https://meta.discourse.org/u/vikaskedia)
#### Post date: [2017年六月21日 23:58 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/32 "2017-06-21T23:58:14Z")

</div>

> [@codinghorror](#):
>
> We are deferring on this for now. Running two instances of Discourse on the same domain in different subfolders is not a supported config at the moment. We may circle back to this in a few months, though.

makes sense .. being able to say 'No" creates a great product.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [2017年十一月23日 21:57 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/34 "2017-11-23T21:57:42Z")

</div>

We will give another go at this soon.

---

<div class="post-metadata">

### Author: ![vikaskedia](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vikaskedia/32/73333_2.png) [@vikaskedia](https://meta.discourse.org/u/vikaskedia)
#### Post date: [2018年三月29日 22:44 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/35 "2018-03-29T22:44:32Z")

</div>

Please close this issue. It works now. By setting the DISCOURSE\_TOKEN\_COOKIE env var.

Thanks @Falco @neil

Well done !!

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2018年三月29日 23:33 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/36 "2018-03-29T23:33:41Z")

</div>



---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [2018年六月26日 20:27 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/37 "2018-06-26T20:27:46Z")

</div>



---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [2018年六月26日 20:30 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/38 "2018-06-26T20:30:23Z")

</div>

As @vikaskedia mentioned earlier, there is a workaround. You can use a different cookie name for each subfolder by using `DISCOURSE_TOKEN_COOKIE` in your configuration.

However, there is still a bug here where cookies are not properly restricted to paths on subfolder installs, causing conflicts with their sessions. The only solution is to use a different cookie name for now.

A better fix from a security standpoint would be to restrict to the proper subfolder path per cookie.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2018年六月26日 20:57 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/39 "2018-06-26T20:57:56Z")

</div>

Can you scope how much work this would be, in terms of “T-shirt sizing”? Small, Medium, Large, XL, XXL?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2018年六月27日 07:25 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/40 "2018-06-27T07:25:54Z")

</div>

Somewhere between small and medium. It would log everyone off though when “fixed / changed”

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2018年六月27日 08:03 UTC](https://meta.discourse.org/t/add-path-to-cookie/40218/41 "2018-06-27T08:03:58Z")

</div>

Hmm that is fairly traumatic. Is there any way to fix it so it only logs people out on subfolder setups at least?

[上一頁](https://meta.discourse.org/t/add-path-to-cookie/40218.md?page=1)

[下一頁](https://meta.discourse.org/t/add-path-to-cookie/40218.md?page=3)
