fix: support QBT_SID_<port> session cookie in network agent proxy#89
Open
lucasliet wants to merge 1 commit into
Open
fix: support QBT_SID_<port> session cookie in network agent proxy#89lucasliet wants to merge 1 commit into
lucasliet wants to merge 1 commit into
Conversation
qBittorrent 5.2.x returns 'Set-Cookie: QBT_SID_<port>=<token>' instead of
'SID=<token>'. The agent proxy extracted the token via /SID=([^;]+)/, which
yielded an empty string for the new cookie name, so the agent rejected
every request with {"error":"missing SID"}.
Replace the regex with extractQbtSessionToken, which selects the cookie
whose name contains SID and returns its value. Works for SID (legacy) and
QBT_SID_<port> (5.2.x). Adds unit tests covering both formats, multi-cookie
strings, values containing '=', and invalid inputs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Network Agent proxy fails against qBittorrent 5.2.x. Every agent request is rejected with:
{"error":"missing SID"}Root cause
qBittorrent 5.2.x changed the session cookie name from
SIDtoQBT_SID_<port>(e.g.QBT_SID_8081):But
src/server/routes/proxy.tsextracts the token assuming the cookie is named exactlySID:For
QBT_SID_8081=<token>this yields'', so the agent receivesX-QBT-SID:(empty) and repliesmissing SID.The login/cookie flow in
src/server/utils/qbt.tsis correct — only the token extraction before calling the agent is wrong.Fix
Replace the regex with a helper that selects the cookie whose name contains
SIDand returns its value:Compatibility
The agent only needs the session value (sent as
X-QBT-SID), not the cookie name, so accepting any*SID*-named cookie is correct. Verified against:SID=abc(legacy, < 5.2)abcQBT_SID_8081=abc(5.2.x)abcQBT_SID_443=abcabcQBT_SID_12345=abcabctheme=dark(no SID)''(rejected)theme=dark; SID=abc(multi-cookie)abcincludes('SID')) on purpose: qBittorrent always emits uppercaseSID, and case-insensitive matching would false-positive on names likeresident.indexOf('=')+sliceinstead ofsplit('=', 2)so values containing=(e.g. base64 padding) are preserved.Testing
Added
__tests__/server/proxy.test.ts(16 cases). Full suite passes (356/356),tsc --noEmitandeslintclean.Verified with qBittorrent v5.2.2 returning
Set-Cookie: QBT_SID_8081=<token>.