Skip to content

Conversation

rioradio
Copy link

@rioradio rioradio commented Oct 6, 2025

Closes #20993

WebUI: add session cookie expiration date based on session timeout

@Chocobo1
Copy link
Member

Chocobo1 commented Oct 6, 2025

What about this comment? #20993 (comment)

@rioradio
Copy link
Author

rioradio commented Oct 6, 2025

My pull request allows me to stay logged in to the qBittorrent WebUI without the browser restoring my session.
This is how it should be.
For example, if I visit the WebUI once a week and the session timeout is set to 7,776,000 seconds (90 days), and I don't want to login every time.

cookie.setHttpOnly(true);
cookie.setSecure(m_isSecureCookieEnabled && isOriginTrustworthy()); // [rfc6265] 4.1.2.5. The Secure Attribute
cookie.setPath(u"/"_s);
cookie.setExpirationDate(QDateTime::currentDateTime().addSecs(m_sessionTimeout));
Copy link
Member

@Chocobo1 Chocobo1 Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. In your PR, the cookie is always going to expire when the time is up.
However, we want the cookie to not expire as long as the user is still using the webapi/webui.

I would suggest something like this:

Suggested change
cookie.setExpirationDate(QDateTime::currentDateTime().addSecs(m_sessionTimeout));
cookie.setExpirationDate(QDateTime::fromSecsSinceEpoch(std::numeric_limits<qint64>::max()));

AFAIK, Chrome and Firefox clamps max time to about 1 year. But Safari will only clamp to 7 days.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have WebUI Session Timeout in seconds in m_sessionTimeout. Why do you want to use a different value?

Copy link
Member

@Chocobo1 Chocobo1 Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_sessionTimeout is a value for session timeout (as long as user keep using it, it won't time out). It is not a time limit for expiring a cookie. You don't need to insist using it for cookie expiration date.
You should look around and see how m_sessionTimeout is actually used.

@rioradio
Copy link
Author

rioradio commented Oct 6, 2025

However, we want the cookie to not expire as long as the user is still using the webapi/webui.

Maybe it would be better to replace the cookie with a new session expiration date each time the user accesses the WebUI?

@Chocobo1
Copy link
Member

Chocobo1 commented Oct 6, 2025

Maybe it would be better to replace the cookie with a new session expiration date each time the user accesses the WebUI?

Yes, that is the basic idea. Chrome also suggests it: https://developer.chrome.com/blog/cookie-max-age-expires#extending_cookie_expiration
It seems in order to achieve this goal it will require a bit more code refactor. I suppose I could handle it unless you beats me to it.

@rioradio
Copy link
Author

rioradio commented Oct 6, 2025

Something like this?

rioradio@0fd54b0

@xavier2k6 xavier2k6 added the WebUI WebUI-related issues/changes label Oct 6, 2025
@Chocobo1
Copy link
Member

Something like this?
rioradio@0fd54b0

Close. I'm thinking something like #23392.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WebUI WebUI-related issues/changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebUI login doesn't persist. cookie expiration is never set and defaults to "session".

3 participants