Skip to content

A free open source IT asset/license management system

Fixed #19942 - allow opt-in for REMOTE_LOGIN header-name for docker

snipeb17cab1c2ef4
diff --git a/docker/startup.sh b/docker/startup.sh
index 0f7d506fb9..111973dfbd 100644
--- a/docker/startup.sh
+++ b/docker/startup.sh
@@ -137,6 +137,44 @@ fi
# and the VirtualHost conf so Apache's module-side bind and the vhost match.
# sed with --follow-symlinks because a2ensite symlinks 001-default-ssl.conf
# from sites-available into sites-enabled.
+# Trusted forwarded-header promotion for REMOTE_LOGIN. Snipe-IT rejects
+# HTTP_-prefixed server variable names in login_remote_user_header_name
+# (commit a5927ca21e, hr9m-63rg) because PHP populates $_SERVER[HTTP_*]
+# directly from inbound request headers, which lets any client spoof the
+# auth header and get logged in as any active user. Setups that
+# terminate SSO at an upstream proxy (oauth2-proxy, Traefik ForwardAuth,
+# Keycloak gatekeeper) have a legitimate trusted header on the inbound
+# request, but the admin can't make Snipe-IT read it directly without
+# reopening that attack surface. The right place to promote the trusted
+# header to a non-HTTP_* server variable is Apache, so Snipe-IT reads
+# REMOTE_USER (the default) and the defensive guard stays intact.
+#
+# Set REMOTE_LOGIN_FORWARDED_HEADER to the inbound header name your
+# upstream sets (e.g. X-Forwarded-Email, X-Forwarded-User). Only do this
+# when the upstream STRIPS any client-supplied value of that header
+# BEFORE setting its own. Otherwise this reopens the exact pre-auth
+# login spoofing surface the guard closed. Issue #19942.
+if [ -v "REMOTE_LOGIN_FORWARDED_HEADER" ] && [ -n "$REMOTE_LOGIN_FORWARDED_HEADER" ]
+then
+ echo "Promoting trusted inbound header '${REMOTE_LOGIN_FORWARDED_HEADER}' to REMOTE_USER for REMOTE_LOGIN"
+ cat > /etc/apache2/conf-available/remote-login-forwarded.conf <<EOF
+# Generated by startup.sh from REMOTE_LOGIN_FORWARDED_HEADER="${REMOTE_LOGIN_FORWARDED_HEADER}".
+# Promotes the inbound ${REMOTE_LOGIN_FORWARDED_HEADER} header to the
+# REMOTE_USER server variable so Snipe-IT's REMOTE_LOGIN sees a
+# non-HTTP_* value and its defensive guard accepts it. Set your
+# Snipe-IT REMOTE_LOGIN header-name back to REMOTE_USER (the default)
+# after enabling this.
+SetEnvIfNoCase ${REMOTE_LOGIN_FORWARDED_HEADER} "^(.+)\$" REMOTE_USER=\$1
+EOF
+ a2enconf remote-login-forwarded
+else
+ # Admin un-set the var on a container restart. Drop the previous
+ # generated conf so we don't keep promoting a header the admin no
+ # longer wants trusted.
+ rm -f /etc/apache2/conf-available/remote-login-forwarded.conf
+ a2disconf remote-login-forwarded 2>/dev/null || true
+fi
+
if [ -v "APACHE_HTTP_PORT" ] && [ "$APACHE_HTTP_PORT" != "80" ]
then
echo "Changing Apache HTTP port to ${APACHE_HTTP_PORT}"