Add ip subnet whitelist for bypassing webui auth - #6779
Conversation
b4041ff to
32a342f
Compare
|
@evsh, @glassez , @Chocobo1, @sledgehammer999: would someone be able to review this PR, or at least comment on it? This is a highly requested feature and I know a lot of people would benefit from having it. |
Don't think so, care to point it out?
How so? having a simple/mindless password is better than none. |
I agree we could have an option for bypassing auth for users on LAN, for WAN, it's best to keep auth on. |
#924 A method of disabling webgui auth is even provided in the Compiling qBittorrent on Debian and Ubuntu guide. However, that method requires users to modify their login.html file. |
I don't get what you're trying to say. @Piccirello If I wasn't clear enough, I only support the idea of adding a checkbox stated: "Bypass authentication for users on LAN". |
But this checkbox exists, isn't it? |
No, the one exists is |
|
I agree that the "disable for LAN" option makes more sense from a security standpoint. I'll modify my changes and update when finished. |
|
I see that |
There was a problem hiding this comment.
There are many conditions here so it would be better to have two helper functions: isLoopbackAddress and isLANAddress.
There was a problem hiding this comment.
Shouldn't be OR in this place?
The LAN conditionals return true if the address isn't localhost OR if local auth is enabled. Therefore if an OR is used and a user connects with a LAN ip, the function would return true regardless of the LAN conditionals.
That being said, development is still underway, so don't start picking apart my changes just yet ;)
Once I'm finished I'll squash the changes and update this PR.
you'll need to handle 3 formats:
|
981b740 to
9ee2abf
Compare
|
Ok, all three scenarios are now handled by the LAN check. Commits are also squashed. What're your thoughts? |
There was a problem hiding this comment.
I would prefer const QHostAddress &clientAddress
There was a problem hiding this comment.
I would prefer const QHostAddress &clientAddress
There was a problem hiding this comment.
These 2 can move to src\base\utils\net if you want
There was a problem hiding this comment.
At least it shouldn't be member of AbstractWebApplication.
There was a problem hiding this comment.
please use:
if ()
else if ()
elseThere was a problem hiding this comment.
No. Don't do it!
It is considered "bad form" to use else after return.
There was a problem hiding this comment.
OK, but at least it should be
if ()
return ...
else if ()
return ...
return true;to save 1 comparison.
There was a problem hiding this comment.
You are again mistaken. It saves nothing.
There was a problem hiding this comment.
The second comparison will be executed only if the first returns false, because otherwise we will just return from the function.
There was a problem hiding this comment.
You are again mistaken. It saves nothing.
You're right. I my head was obsessed with something else.
There was a problem hiding this comment.
I know, the suggestion is for clarity.
There was a problem hiding this comment.
use isInSubnet(const QHostAddress &subnet, int netmask)?
i.e. isInSubnet(QLatin1String("10.0.0.0"), 8)
and below
There was a problem hiding this comment.
Why? They are equivalent.
There was a problem hiding this comment.
They are equivalent.
to save 1 function call in our code?
There was a problem hiding this comment.
isInSubnet(QLatin1String("10.0.0.0"), 8)
What's the purpose of using QLatin1String in this instance? It's not currently used for creating the ipv6 mapped 127.0.0.1 address.
There was a problem hiding this comment.
What's the purpose of using QLatin1String in this instance?
QHostAddress is constructed via QHostAddress(const QString &address) and then from http://doc.qt.io/qt-5/qlatin1string.html#details :
This is a bit longer to type, but it provides exactly the same benefits as the first version of the code, and is faster than converting the Latin-1 strings using QString::fromLatin1().
There was a problem hiding this comment.
clientAddress -> addr or some other name
there is no concept of "client" in these 2 helper functions
There was a problem hiding this comment.
Done.
I still see "clientAddress"...
There was a problem hiding this comment.
there are non-trivial computation in this func, maybe it make sense to add the following?
if (clientAddress.isInSubnet(QLatin1String("0.0.0.0"), 0)) {
// ipv4
}
else {
// ipv6
}UPDATE: example updated.
There was a problem hiding this comment.
we use implicit type conversion in our codebase, so I'll say there is no need for explicit QHostAddress() construction here.
There was a problem hiding this comment.
I can't compile without explicitly passing QHostAddress
base/utils/net.cpp:51:60: error: no matching function for call to ‘QHostAddress::isInSubnet(QLatin1String, int) const’
if (addr.isInSubnet(QLatin1String("0.0.0.0"), 0)) {
^
base/utils/net.cpp:51:60: note: candidates are:
In file included from /opt/qt55/include/QtNetwork/QHostAddress:1:0,
from base/utils/net.cpp:30:
/opt/qt55/include/QtNetwork/qhostaddress.h:116:10: note: bool QHostAddress::isInSubnet(const QHostAddress&, int) const
bool isInSubnet(const QHostAddress &subnet, int netmask) const;
^
/opt/qt55/include/QtNetwork/qhostaddress.h:116:10: note: no known conversion for argument 1 from ‘QLatin1String’ to ‘const QHostAddress&’
/opt/qt55/include/QtNetwork/qhostaddress.h:117:10: note: bool QHostAddress::isInSubnet(const QPair<QHostAddress, int>&) const
bool isInSubnet(const QPair<QHostAddress, int> &subnet) const;
^
/opt/qt55/include/QtNetwork/qhostaddress.h:117:10: note: candidate expects 1 argument, 2 provided
base/utils/net.cpp:62:9: warning: control reaches end of non-void function [-Wreturn-type]
}
^
|
my review is finished. |
There was a problem hiding this comment.
Please drop else branch and place return statement outside it.
There was a problem hiding this comment.
Done.
I still see "clientAddress"...
|
And one more question. Is bypass auth for lan but require it for localhost the expected behavior? |
d5b6bfd to
2b43372
Compare
|
@Piccirello, I've done it for you (rebased and squashed). You need to force update your local branch. |
You shouldn't use GitHub editor. When you need to resolve conflicts in your PR, you need to rebase your local branch on top of current qBittorrent master (manually resolving some conflicts if required) and then force push it on GitHub. |
2b43372 to
09d9436
Compare
|
Thanks @glassez. |
09d9436 to
04d2e53
Compare
@Piccirello, what the hell are you doing? Are you kidding me? |
Ok. You can forget about commits squashing since they are unrelated. But coding style issues are still be fixed. |
glassez
left a comment
There was a problem hiding this comment.
Fix coding style.
The rest is ok.
Care to point out the style issues? I re-pushed the repo because you squashed unrelated commits. |
There was a problem hiding this comment.
Inconsistent else block. Curly braces are required because of curly braces in if.
04d2e53 to
0de2f17
Compare
|
Great work @Piccirello |
|
@Piccirello, thank you! |
| QStringList authSubnetWhitelistStringList; | ||
| for (const Utils::Net::Subnet &subnet : pref->getWebUiAuthSubnetWhitelist()) | ||
| authSubnetWhitelistStringList << Utils::Net::subnetToString(subnet); | ||
| data["bypass_auth_subnet_whitelist"] = authSubnetWhitelistStringList.join("\n"); |
There was a problem hiding this comment.
Unfortunately I noticed it only now... Why have you chosen this out-of-context way to encode this list? We should send it as (json) list, isn't it? I'm sure this should be fixed soon.
|
Posting for posterity. If you wish to turn of authentication completely, say in the scenario where the web interface is protected by a separate TLS nginx/apache/trafik/haproxy reverse proxy you can add Insert obvious warning: dont do this if dont know what you are doing, authentication is there for a reason. |
Requested in #924.
Provides a more permanent solution than this wiki page while also allowing the web API auth to be disabled
This feature is useful when qBitttorrent is used behind a reverse proxy with its own authentication scheme, or when it's running on a local network.