jducoeur: (Default)
[personal profile] jducoeur
A brief Nota Bene for users of Play Framework, mostly in case anyone else hits this silly problem and winds up in the same boat I've been in.

Querki has, until now, been entirely based on transient session cookies -- your session expires when you close the browser. That works okay on the desktop, since many of us *never* close our browsers, but turns out to suck on mobile: both Mobile Chrome and Mobile Safari seem to lose their transient cookies kind of at whim. (There's probably a definition of when somewhere, but I haven't found it yet.) Problem is, the Play Framework that Querki is built on has no documented way to set up a *non*-transient session. This has had me tearing my hair out for a year now.

Turns out that the answer, as usual, is to look at the source code. (Yay for open source.) It turns out that there is an as-far-as-I-can-tell-undocumented "session.maxAge" configuration variable, which sets the max-age setting on the session cookies, which is exactly what you want in the real world. There are also config variables for the other major aspects of the session cookie.

So as far as I can tell, to manage your session cookies, you want to use this config structure:
session {
  maxAge : nnnn  # Number of milliseconds for a session to live; if not specified, session is transient
  secure : true/false  # Whether to require HTTPS for a valid session cookie, default false
  httpOnly : true  # Whether to prevent JavaScript from accessing the session cookie, default true
  domain : xxxx  # The domain to use for the session cookie?  Not sure
}
I'll be trying this out on Querki later today; hopefully it'll fix the problem.

(no subject)

Date: 2015-05-07 02:07 pm (UTC)
From: [identity profile] goldsquare.livejournal.com
Interesting.

Android programs tend to have Activities - not quite the same as a thread, but if you haven't studied Android, think "thread with stuff" and you can figure it out.

Android starts and restarts activities through a very complex lifecycle - with the Activity having many states, and many locally implemented calls for each state transition.

This is the diagram, with appropriate calls:


Note the comment at the left hand edge, about processes that need memory... and also note that screen rotation also causes the Activity to restart.

Activities can preserve their data objects between restarts, but it takes coding and effort. I wonder (I do not know) if these browsers are not saving transient cookies during the restart process. I'm sure they are doing so during the Pause flow, but I haven't checked.

But it is ALSO the case that, should memory start to run low, Android will call methods that prune memory in the application. It might be the case that the applications are throwing away transient cookies at that time. (The cost of not lowering your memory usage when you receive that method call, can be literally "fatal", so apps tend to take it seriously.)

Android is weird.

(no subject)

Date: 2015-05-07 02:54 pm (UTC)
From: [identity profile] goldsquare.livejournal.com
I'm sufficiently paranoid that I run Desktop Chrome in incognito mode much of the time - which makes permanent cookies into transient cookies. :-)

(And when truly paranoid, I run in Firefox with all cookie-setting off, and allow cookies on an individual basis.)

I think you would benefit from reading section 4 of RFC 6265, which describes how session cookies are defined.

Back when I was doing more web-programming than I am now, I always deliberately set cookie expiration dates, rather than trust the 10 billion browsers out there as to their default policies.

I also coded to defend against cookies being rejected - I hate how web sites redirect to a new page when cookies can't be set. If I reconfigure my cookie policy to permit that site to set cookies, I also had to go back and forth for each cookie, many times.

You should also bear in mind that your cookies' expiration dates might be overridden anyway. I often force "permanent cookies" to expire at the end of each session, or tab, depending. If the user agent maintains the data, the server-programmer has to defend against intransigent (or crappy) user agents.

This is your quality engineering friend, speaking. :-) Boy, have I effed over some web sites by hacking on their cookies... :-)

(no subject)

Date: 2015-05-08 03:01 pm (UTC)
laurion: (Default)
From: [personal profile] laurion
To save memory and power, mobile browsers 'expire' old pages and then reload them when you go back to the browser tab. And then try to pretend that the page was loaded the whole time. A necessary evil of the hardware limitations. Very likely that each OS and/or browser has its own parameters for when to do this, but yeah, totally hoses the transient cookies.

Profile

jducoeur: (Default)
jducoeur

June 2025

S M T W T F S
12 34567
891011121314
15161718192021
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags