Replies: 3 comments 2 replies
|
There is no flag you are missing. On 3.17.0 the Why the timeouts do not do it
local remember_flags
if remember then
local max_age = self.remember_rolling_timeout
...
remember_flags = fmt("; Expires=%s; Max-Age=%d", expires, max_age)
endThat is the whole of it. The attributes only ever appear on the "remember me" cookie, which is a separate cookie with its own name and its own timeouts. The ordinary session cookie is a session cookie by design and never carries an expiry. Why you cannot turn it onThe plugin's Same for That is APISIX 3.17.0 with This gap is known, incidentally. Issue #13177 asked for the lua-resty-session 4.x options and listed "remember/persistent session settings" among the ones missing from the schema. The fix, PR #13178, merged on 2026-06-10, is what gave you the flat What works todayRewrite the header on the way out. This is tested on 3.17.0 and produces exactly what you want: "serverless-post-function": {
"phase": "header_filter",
"functions": ["return function(conf, ctx)\n local ck = ngx.header[\"Set-Cookie\"]\n if not ck then return end\n local max_age = 2592000\n local function fix(c)\n if c:find(\"^session=\") and not c:lower():find(\"max%-age\") then\n return c .. \"; Max-Age=\" .. max_age .. \"; Expires=\" .. ngx.cookie_time(ngx.time() + max_age)\n end\n return c\n end\n if type(ck) == \"table\" then\n local out = {}\n for i, c in ipairs(ck) do out[i] = fix(c) end\n ngx.header[\"Set-Cookie\"] = out\n else\n ngx.header[\"Set-Cookie\"] = fix(ck)\n end\nend"]
}Result on the same route: Three things to keep in mind. Match the |
|
This is an intentional design choice in Session cookies are always valid only for the duration of the browser session and are cleared when the browser is closed; their concept is similar to a short-term Currently, neither APISIX’s OpenID Connect nor Manually modifying the session cookie's expiration time is neither supported nor recommended. We do not endorse this informal method, and you must resolve any unexpected issues on your own. APISIX acts as the Service Provider (SP) in the authentication process. It can use a short-term cookie mechanism exclusively, refreshing the cookie with every request. Once the short-term cookie expires, the user is redirected directly to the Identity Provider (IDP). We expect the IDP to provide a session persistence mechanism with a longer validity period. For example, sessions on Google OAuth rarely expire with regular use. The IDP can silently complete authentication and code generation, then redirect back to APISIX, which will also silently handle token exchange and reverse proxying. One example is the Keycloak Admin Console, which does exactly that. |
|
Thanks for the clarification, @bzp2010 @jmrplens A quick follow-up on Is this recommended? Since access tokens expire in 10 minutes while the gateway session lasts 30 days, does APISIX track the access token's expiry and trigger a refresh under the hood? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
We are encountering an issue in which session cookies generated by APISIX are sent without explicit
Max-AgeorExpiresattributes in theSet-Cookieheader. As a result, client browsers treat them strictly as session-scoped cookies.While modern client browsers with session restore retain these cookies across restarts, browsers running on certain remote Windows Server environments purge them immediately upon closure, forcing users to re-authenticate on every restart.
I'm using
apisix:3.17.0and OIDC Plugin - https://apisix.apache.org/docs/apisix/plugins/openid-connect/Current Configuration
We configured the session timeout settings expecting persistent cookies to be written, but the cookies are still generated without an expiration timestamp:
Expected Behavior
The
Set-Cookieheader should include a Max-Age or Expires attribute reflecting the configured duration so that the browser treats the cookie as persistent across sessions.Actual Behavior
The
Set-Cookieheader omits the expiration attributes, causing the cookie to be discarded whenever the browser process terminates in strict/remote environments.Questions
All reactions