digitalpoint
Well-known member
Have an event listener that fires when the app is loaded so you can refresh CSRF token and/or fetch counters (for conversations and alerts).
class Login extends XFCP_Login
{
public function assertValidCsrfToken($token = null, $validityPeriod = null)
{
if (\XF::options()->cfPageCachingSeconds && \XF::app()->router()->routeToController(\XF::app()->request()->getRoutePath())->getAction() === 'keep-alive')
{
return;
}
parent::assertValidCsrfToken($token, $validityPeriod);
}
}
XF.config.csrf
property. I believe that has the time the csrf token is good from, so you could infer when it expires. If it's within the validity period, do a simple JavaScript call to get a valid CSRF token to use. And as a bonus, that same call automatically updates the counters:XF.KeepAlive.refresh();
location.reload();
login/keep-alive
route is POST only, and never writes data, it's only used to fetch a CSRF token via the POST request. So simply removing the requirement to have a CSRF token in order to get a CSRF token doesn't seem terrible to me. Then you just add an event listener for statechange
and fire XF.KeepAlive.refresh();
when the state is changed to active
. Then you aren't doing different things depending on when the csrf token was generated and dealing with trying to reload a page that was the result of a POST.XF.KeepAlive.refresh()
does not update the counters.$.ajax()
call rather than XF.ajax()
. The latter of which fires some additional events.if (data.visitor)
{
XF.updateVisitorCounts(data.visitor, true);
}
document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "visible") {
XF.keepAlive.refresh();
}
});
display-mode: standalone
check).XF.KeepAlive.refresh()
handle an expired token already?I don't think so... when I was dealing with it in my Cloudflare addon for guest page caching, it really just makes a request to whatever is set inThe aforementioned CSRF issue I haven't actually experienced since my phone stopped being whacky. Doesn'tXF.KeepAlive.refresh()
handle an expired token already?
XF.config.url.keepAlive
, which is login/keep-alive
. There is a bypass within the checkCsrfIfNeeded
method, but if you go digging, the actionKeepAlive
method calls the assertValidCsrfToken
method if there is an existing csrf cookie (like an old or expired one maybe).Sec-Fetch-Site
HTTP header as an alternative to CSRF. Could still fallback to CSRF token if the Sec-Fetch-Site header doesn't exist (old browsers). Sec-Fetch-Site wasn't practical before because Safari didn't support it, but Safari added support in 16.4 (at this point the only browser that doesn't support it is IE... which isn't even a browser anymore). Might not be a bad time to explore using Sec-Fetch-Site within the CSRF checking code (with the existing cookie/CSRF token system as the fallback if it's not there).Actually I don’t know if this is a separate issue.Is this issue related to the fact that when the app is open, and there is a new notification coming in, when clicking on i, it opens the app but nothing happens (it doesn’t redirect to the notified message/PM/whatever) since it doesn’t refresh the page?
Is there a way to trigger a page refresh automatically every time the app is loaded? There is a page refresh anyway in between pages, when navigating the app, so maybe triggering a "hard" page refresh every time somebody is clicking on a notification/loading the app could solve this for now?Actually I don’t know if this is a separate issue.
We use essential cookies to make this site work, and optional cookies to enhance your experience.