After working with Cloudflare AI for two days to ensure my set up is secure - it has decided the only way to stop a Security Warning is to rewrite code! here’s what it initially told me:
Found the bug! The issue is a port mismatch. Look at this check:
elsif ($referer_site eq $http_host &&
-
(!$referer_port || !$http_port || $referer_port == $http_port)) {*
The Referer header says https://#####.com/ (port 443), but Webmin thinks it’s running on port 10000. So $referer_port (443) != $http_port (10000) → trust fails.
Also, referer=0 in Perl is falsy, so the $gconfig{‘referer’} check doesn’t skip. The simplest fix — patch the code to always trust:
# Add $trust = 1 before the check
sudo sed -i ‘/^if (!$trust) {/i \ $trust = 1; # Force trust - behind Cloudflare tunnel’ /usr/share/webmin/web-lib-funcs.pl
sudo systemctl restart webmin"
ME: Isn’t that a security risk?
AI: You’re right — disabling it entirely is a security risk. A better approach is to patch only the port comparison, since the real issue is that Cloudflare uses port 443 but Webmin sees port 10000. The hostname check still protects you:
```
# Undo the previous change first
sudo sed -i ‘/# Force trust - behind Cloudflare tunnel/d’ /usr/share/webmin/web-lib-funcs.pl
# Patch only the port check - keep hostname verification but ignore port mismatch
sudo sed -i ‘s/(!$referer_port || !$http_port || $referer_port == $http_port)/1/’ /usr/share/webmin/web-lib-funcs.pl
# Restart Webmin
sudo systemctl restart webmin
```
This changes:
```
# Before: requires both hostname AND port to match
*elsif ($referer_site eq $http_host && *
-
(!$referer_port || !$http_port || $referer_port == $http_port)) {*
# After: only requires hostname to match (port always passes)
elsif ($referer_site eq $http_host && 1) {
```
The hostname check (#####.com) still protects against cross-site requests from other domains — only the port mismatch is bypassed, which is expected behind a reverse proxy/tunnel."
I’m not happy with this - what we are trying to do is get Webmin to recognise my login while dealing with Cloudflare’s apparent inability to deal with port 10000.
How have others dealt with Webmin (NOT Virtualmin) and Cloudflare? This is a very old ( but regularly updated) install of Webmin from way back when it could be installed by itself. Sadly there is no way to upgrade it to Virtualmin without the possibility of screwing up my server
