[BUG] LibreNMS Web UI: base_url not taken into account

Hi.

I ran git bisect. It looks that the problem was introduced in this commit:

commit 32a7c50189b46058d53b8a1de6c2846a16f5e549
Author: Tony Murray [email protected]
Date: Tue Sep 11 07:51:35 2018 -0500

Use Laravel authentication (#8702)

* Use Laravel for authentication
Support legacy auth methods
Always create DB entry for users (segregate by auth method)

Port api auth to Laravel

restrict poller errors to devices the user has access to

Run checks on every page load.  But set a 5 minute (configurable) timer.
Only run some checks if the user is an admin

Move toastr down a few pixels so it isn't as annoying.

Fix menu not loaded on laravel pages when twofactor is enabled for the system, but disabled for the user.
Add two missing menu entries in the laravel menu

Rewrite 2FA code
Simplify some and verify code before applying

Get http-auth working
Handle legacy $_SESSION differently.  Allows Auth::once(), etc to work.

* Fix tests and mysqli extension check

* remove duplicate Toastr messages

* Fix new items

* Rename 266.sql to 267.sql

Regarding my setup:

  1. Front server (SERVER-NAME):

    server {
     listen          443 ssl;
     server_name     SERVER-NAME;
    
     root            /usr/share/empty;
    
     ssl_certificate         /etc/pki/tls/certs/SERVER-NAME.crt;
     ssl_certificate_key     /etc/pki/tls/private/SERVER-NAME.key;
     ssl_ciphers             PROFILE=SYSTEM;
     ssl_session_timeout     15m;
    
     proxy_bind              $remote_addr            transparent;
     proxy_set_header        Host                    $host:$server_port;
     proxy_set_header        X-Forwarded-For         $proxy_add_x_forwarded_for;
     proxy_set_header        X-Forwarded-Proto       $scheme;
     proxy_read_timeout      5m;
    
     location /librenms/ {
             proxy_pass              http://librenms/;
     }
    }
    
  2. Backend (libernms):

    <VirtualHost *:80>
     ServerName              librenms
     DocumentRoot            "/opt/librenms/html/"
    
     AllowEncodedSlashes     NoDecode
    
     <Directory "/opt/librenms/html/">
             Require         all granted
             AllowOverride   All
     </Directory>
    </VirtualHost>
    
  3. LibreNMS Configuration:

    (...)
    $config['base_url']     = 'hxxps://SERVER-NAME/librenms/';
    (...)
    

Problem:

  1. While hxxps://SERVER-NAME/librenms/ as not logged in user, the LibreNMS redirects to login page hxxps://SERVER-NAME/login instead of hxxps://SERVER-NAME/librenms/login (base_url is not taken under account).

  2. The LibreNMS login page can be accessed using hxxps://SERVER-NAME/librenms/login/, however the login form is posted to hxxps://SERVER-NAME/login (base_url is not taken under account).

  3. If I login on SERVER-NAME and access hxxp://librenms/, I am redirected to hxxp://librenms/login. If I log in, I see dashboard, and all links there are correctly prepended by base_url (hxxps://SERVER-NAME/librenms/).

I hope my description is clear enough. The example HTTP request & reply sniffed between SERVER-NAME and librenms is avaiable in one of my previous posts.

PS: I had to replace http by hxxp and https by hxxps.