ColdFusion 10 CFCookie not honoring domain attribute

只愿长相守 提交于 2019-12-04 11:38:38

Thanks to Henry I took a look at using cfheaders again by having a closer look at the headers sent by CF10 when using <cfset this.SetClientCookies = true>. CF10 omitted the domain value in the header sent to the browser so I copied the header CF10 sent and put it in a cfheader:

<cfheader name="Set-Cookie"  value="CFID=#session.CFID#; Expires=#GetHttpTimeString(DateAdd("yyyy", 40, Now()))#; Path=/">
<cfheader name="Set-Cookie"  value="CFToken=#session.CFToken#; Expires=#GetHttpTimeString(DateAdd("yyyy", 40, Now()))#; Path=/">

Lo' and behold the browser received the cookie without the domain value having a leading period. I also managed to expire those cookies with the following code:

<cfheader name="Set-Cookie"  value="CFID=#session.CFID#; Expires=#GetHttpTimeString(Now()-1)#; Path=/">
<cfheader name="Set-Cookie"  value="CFToken=#session.CFToken#; Expires=#GetHttpTimeString(Now()-1)#; Path=/">
<cfset StructClear(session)>
<cflocation url="/" addtoken="no">

The only quirk it seems that while testing out that block of code using a url variable in Chrome, Chrome would send out a HTTP request when simply typing ?ResetSen in the address bar causing a second request when I hit enter. This would lead to oddities such as skipping a CFID (7249 -> 7251) or just sending out both sets of cookies (expire: indefinite and expires: now).

Nevermind, the real issue seems to be the expiry time not elapsing (two requests in the same second), I changed that portion to #GetHttpTimeString(Now()-1)# which is one day in the past and that seems to holding up.

Originally this:

<cfheader name="Set-Cookie"  value="CFID=#session.CFID#; Domain=test01.domain.net;Expires=Sat, 04-Jul-2043 13:24:38 GMT; Path=/">
<cfheader name="Set-Cookie"  value="CFToken=#session.CFToken#; Expires=Sat, 04-Jul-2043 13:24:38 GMT; Path=/">

Sent this:

Set-Cookie: CFID=7191; Domain=test01.domain.net; Expires=Sat, 04-Jul-2043 13:24:38 GMT; Path=/
Set-Cookie: CFToken=33b984d7a56f6356-0B97F3CF-3048-3344-AABF2B698F4B8B02; Domain=test01.domain.net; Expires=Sat, 04-Jul-2043 13:24:38 GMT; Path=/

Which the browser receives as .test01.domain.net which is what I wanted to avoid.

Henry

Yes, this does seem like <cfcookie> is doing too much by stripping any domain value to .domain.tld. See: why doesn't cfcookie allow setting domain= to a subdomain for CFID/CFTOKEN?

I'm not sure why, but the workaround would be using <cfheader>

In order to modify session cookies in your code you should add the following in your Application.cfc pseudo-constructor:

<cfset this.sessioncookie.disableupdate = false>

This can also be controlled at the server level under the 'Memory variables' section in the CF administrator.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!