Skip to content

A free open source IT asset/license management system

Allow for overriding of specific apache limits

Thomas Misilo09c7fec84980
diff --git a/.env.docker b/.env.docker
index 7e7e278aa0..0528fdd517 100644
--- a/.env.docker
+++ b/.env.docker
@@ -117,6 +117,13 @@ BACKUP_ENV=true
#PHP_UPLOAD_MAX_FILESIZE=10
#PHP_MEMORY_LIMIT=10
+# --------------------------------------------
+# OPTIONAL: CHANGE APACHE REQUEST HEADER LIMITS (UNCOMMENT WHEN NEEDING TO BE CHANGED)
+# Defaults: 8190 / 8190 / 100
+# --------------------------------------------
+#APACHE_LIMIT_REQUEST_FIELD_SIZE=8190
+#APACHE_LIMIT_REQUEST_LINE=8190
+#APACHE_LIMIT_REQUEST_FIELDS=100
# --------------------------------------------
# OPTIONAL: SESSION SETTINGS
diff --git a/Dockerfile b/Dockerfile
index b4c4e8a357..be96e1865a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -75,6 +75,10 @@ COPY . /var/www/html
RUN a2enmod rewrite
+# Apache Limits Defaults
+COPY docker/apache-limits.conf /etc/apache2/conf-available/limits.conf
+RUN a2enconf limits
+
COPY docker/column-statistics.cnf /etc/mysql/conf.d/column-statistics.cnf
############ INITIAL APPLICATION SETUP #####################
diff --git a/Dockerfile.alpine b/Dockerfile.alpine
index 72578a9234..ab0b1beed3 100644
--- a/Dockerfile.alpine
+++ b/Dockerfile.alpine
@@ -44,6 +44,9 @@ RUN mkdir -p /run/apache2 && chown apache:apache /run/apache2
RUN sed -i 's/variables_order = .*/variables_order = "EGPCS"/' /etc/php84/php.ini
COPY docker/000-default-2.4.conf /etc/apache2/conf.d/default.conf
+# Apache Limits Defaults
+COPY docker/apache-limits.conf /etc/apache2/conf.d/limits.conf
+
# Enable mod_rewrite
RUN sed -i '/LoadModule rewrite_module/s/^#//g' /etc/apache2/httpd.conf
diff --git a/docker/apache-limits.conf b/docker/apache-limits.conf
new file mode 100644
index 0000000000..f05d38b047
--- /dev/null
+++ b/docker/apache-limits.conf
@@ -0,0 +1,10 @@
+# Apache request header limits.
+# Some environments (large SAML/SSO assertions, long Referer/Cookie headers,
+# corporate proxies, etc.) can exceed Apache's conservative defaults and
+# trigger "Bad Request: size of request header exceeds server limit".
+#
+# Override at runtime with the APACHE_LIMIT_REQUEST_* environment variables
+# (see docker/startup.sh).
+LimitRequestFieldSize 8190
+LimitRequestLine 8190
+LimitRequestFields 100
diff --git a/docker/startup.sh b/docker/startup.sh
index 9bce5b154d..3ac34ecf90 100644
--- a/docker/startup.sh
+++ b/docker/startup.sh
@@ -110,6 +110,26 @@ then
done
fi
+# Fix Apache request header limits
+# (defaults live in /etc/apache2/conf-available/limits.conf; override here)
+if [ -v "APACHE_LIMIT_REQUEST_FIELD_SIZE" ]
+then
+ echo "Changing LimitRequestFieldSize to ${APACHE_LIMIT_REQUEST_FIELD_SIZE}"
+ sed -i "s/^LimitRequestFieldSize.*/LimitRequestFieldSize ${APACHE_LIMIT_REQUEST_FIELD_SIZE}/" /etc/apache2/conf-available/limits.conf
+fi
+
+if [ -v "APACHE_LIMIT_REQUEST_LINE" ]
+then
+ echo "Changing LimitRequestLine to ${APACHE_LIMIT_REQUEST_LINE}"
+ sed -i "s/^LimitRequestLine.*/LimitRequestLine ${APACHE_LIMIT_REQUEST_LINE}/" /etc/apache2/conf-available/limits.conf
+fi
+
+if [ -v "APACHE_LIMIT_REQUEST_FIELDS" ]
+then
+ echo "Changing LimitRequestFields to ${APACHE_LIMIT_REQUEST_FIELDS}"
+ sed -i "s/^LimitRequestFields.*/LimitRequestFields ${APACHE_LIMIT_REQUEST_FIELDS}/" /etc/apache2/conf-available/limits.conf
+fi
+
# If the Oauth DB files are not present copy the vendor files over to the db migrations
if [ ! -f "/var/www/html/database/migrations/*create_oauth*" ]
then
diff --git a/docker/startup_alpine.sh b/docker/startup_alpine.sh
index 26ae61b893..55943dd683 100644
--- a/docker/startup_alpine.sh
+++ b/docker/startup_alpine.sh
@@ -94,6 +94,26 @@ then
done
fi
+# Fix Apache request header limits
+# (defaults live in /etc/apache2/conf.d/limits.conf; override here)
+if [ -v "APACHE_LIMIT_REQUEST_FIELD_SIZE" ]
+then
+ echo "Changing LimitRequestFieldSize to ${APACHE_LIMIT_REQUEST_FIELD_SIZE}"
+ sed -i "s/^LimitRequestFieldSize.*/LimitRequestFieldSize ${APACHE_LIMIT_REQUEST_FIELD_SIZE}/" /etc/apache2/conf.d/limits.conf
+fi
+
+if [ -v "APACHE_LIMIT_REQUEST_LINE" ]
+then
+ echo "Changing LimitRequestLine to ${APACHE_LIMIT_REQUEST_LINE}"
+ sed -i "s/^LimitRequestLine.*/LimitRequestLine ${APACHE_LIMIT_REQUEST_LINE}/" /etc/apache2/conf.d/limits.conf
+fi
+
+if [ -v "APACHE_LIMIT_REQUEST_FIELDS" ]
+then
+ echo "Changing LimitRequestFields to ${APACHE_LIMIT_REQUEST_FIELDS}"
+ sed -i "s/^LimitRequestFields.*/LimitRequestFields ${APACHE_LIMIT_REQUEST_FIELDS}/" /etc/apache2/conf.d/limits.conf
+fi
+
# If the Oauth DB files are not present copy the vendor files over to the db migrations
if [ ! -f "/var/www/html/database/migrations/*create_oauth*" ]
then