Tim Badolato
06/17/2025, 2:19 AMCFID and CFTOKEN as custom HTTP headers (e.g., Authorization: CFID xxxxx) with each request, and have Lucee bind to the appropriate session.
However:
• Passing session cookies cross-site triggers CORS restrictions.
• Including session IDs in URLs is insecure and messy.
Is there any supported way in Lucee to restore or bind a session using CFID and CFTOKEN from headers rather than cookies or query params?
If not natively supported, is there a way to hook into restore a session in onRequestStart using the CFID/CFTOKEN?
I did figure out how to retrieve the session data from Redis but if I loop over the values and add it to the current session, I'm basically duplicating the data to a new session on every load.
Any help is appreciated. ThanksBill Nourse
06/17/2025, 3:38 AMrodyon
06/17/2025, 10:49 AMTim Badolato
06/17/2025, 2:20 PMErin Brewer
06/17/2025, 2:32 PMTim Badolato
06/17/2025, 2:59 PMTim Badolato
06/17/2025, 3:04 PM# Handle CFID and CFTOKEN headers
@hasHeaders {
header cfid *
header cftoken *
}
handle @hasHeaders {
rewrite * {path}?{query}&cfid={header.cfid}&cftoken={header.cftoken}
}
reverse_proxy <http://cfml:8080>
Works great for now, but would be great if Lucee had a better way of doing this or allowed us more control over the current session.Erin Brewer
06/17/2025, 3:27 PMTim Badolato
06/17/2025, 3:36 PMBill Nourse
06/17/2025, 5:42 PMrodyon
06/17/2025, 6:22 PMjcberquist
06/17/2025, 8:05 PMcookie.cfid in the psuedo-constructor of Application.cfc and it should take effect - e.g.:
component {
try {
cookie.cfid = getHTTPRequestData().headers.cfid;
cookie.cftoken = 0;
} catch(any e) {
// do something?
}
this.name = '.....';
this.sessionmanagement = true;
}
Since cookies are passed in the Cookie HTTP header, I am guessing your issue is that you don't want that specific header to be used? You could also use Caddy to move your custom headers into the Cookie header when proxying to Lucee, I would think.Tim Badolato
06/18/2025, 12:51 AMrodyon
06/18/2025, 1:51 PMjcberquist
06/18/2025, 5:01 PMBK BK
06/18/2025, 10:38 PMvariables scope. That is a weird scope for session variables.
(2) Session-scoped locks are missing.
(3) I doubt whether cfid is actually a key of the struct getHTTPRequestData().headers.BK BK
06/19/2025, 8:39 AMcfid, cftoken and sessionid as headers. In that case, is it then an idea to do the following (with any necessary changes) in onRequestStart ?
<!--- Copy the session-key values from the headers --->
<cfset var tempSession = structnew()>
<cfset tempSession.cfid = cfid_from_header>
<cfset tempSession.cftoken = cftoken_from_header>
<cfset tempSession.sessionid = sessionid_from_header>
<!--- Clear any existing session --->
<cflock scope="session" type="exclusive" timeout=60>
<cfset structclear(session)>
</cflock>
<!--- Restore the session-key values. --->
<cflock scope="session" type="exclusive" timeout=60>
<cfset session.cfid = tempSession.cfid>
<cfset session.cftoken = tempSession.cftoken>
<cfset session.sessionid = tempSession.sessionid>
</cflock>