Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a token for CSRF protection, not referer. #17598

Open
omeryagmurlu opened this issue Aug 23, 2022 · 6 comments
Open

Use a token for CSRF protection, not referer. #17598

omeryagmurlu opened this issue Aug 23, 2022 · 6 comments
Labels
Feature request WebAPI WebAPI-related issues/changes

Comments

@omeryagmurlu
Copy link

omeryagmurlu commented Aug 23, 2022

Suggestion

Currently qBittorrent checks referer to make sure no CSRF occurs. This is fine for most cases, but completely disallows using qBittorrent behind an HTTP proxy like nginx in a secure (regarding CSRF) manner. You either have to drop the referer to bypass qbt’s csrf protection, or disable it in qbt preferences altogether, which is bad, in order to proxy qbt.

Transmission uses tokens for csrf protection with the header X-Transmission-Session-Id:

2.3.1 CSRF protection

Most Transmission RPC servers require a X-Transmission-Session-Id header to be sent with requests, to prevent CSRF attacks.

When your request has the wrong id -- such as when you send your first request, or when the server expires the CSRF token -- the Transmission RPC server will return an HTTP 409 error with the right X-Transmission-Session-Id in its own headers.

So, the correct way to handle a 409 response is to update your X-Transmission-Session-Id and to resend the previous request

from https://github.com/transmission/transmission/blob/9bf2918ad09ee6c89e105adfb865d9130f987bed/docs/rpc-spec.md#231-csrf-protection

By passing this header through the proxy, one can use Transmission behind a proxy with working CSRF protection. I would like to see qBittorrent switch to token based csrf protection too.

See also this question from stackoverflow: https://stackoverflow.com/questions/1413930/is-checking-the-referrer-enough-to-protect-against-a-csrf-attack

Use case

Security is important

Extra info/examples/attachments

No response

@sledgehammer999 sledgehammer999 added the WebAPI WebAPI-related issues/changes label Aug 23, 2022
@Chocobo1
Copy link
Member

Chocobo1 commented Aug 24, 2022

There is a Server domains: text input box in Options. Doesn't it help?

This is fine for most cases, but completely disallows using qBittorrent behind an HTTP proxy like nginx in a secure (regarding CSRF) manner.

Not true, as long as you provide X-Forwarded-Host & X-Forwarded-For correctly it should work fine, see: https://github.com/qbittorrent/qBittorrent/wiki/NGINX-Reverse-Proxy-for-Web-UI

@omeryagmurlu
Copy link
Author

That only works as long as you directly enter the url and navigate to it directly. If you want to use a dashboard or something similar, it fails and shows unauthorized.

@Chocobo1
Copy link
Member

That only works as long as you directly enter the url and navigate to it directly. If you want to use a dashboard or something similar, it fails and shows unauthorized.

Yes that is intended. Embedding built-in webUI into other pages is specifically not supported use case, and you should disable related webui protections if you want to go that way.

@omeryagmurlu
Copy link
Author

omeryagmurlu commented Aug 24, 2022 via email

@KonRay
Copy link

KonRay commented Dec 7, 2023

+1. Remote Torrent Adder didn't work for me until I disabled CSRF protection.

@coanghel
Copy link

Just chiming in that I see the same issue: directly accessing the WebUI reverse proxy at qbittorrent.my.domain works fine, but if I try to hit a link with the same embedded in a dashboard it trips the CSRF. That definitely feels unintended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature request WebAPI WebAPI-related issues/changes
Projects
None yet
Development

No branches or pull requests

5 participants