public
nobgit
read
NobMail
Based on mailcow: dockerized
Languages
Repository composition by tracked source files.
PHP
49%
JavaScript
35%
HTML
9%
CSS
4%
Shell
2%
Python
1%
Lua
0%
Perl
0%
Ruby
0%
SCSS
0%
Create file
Wiki Documentation
Clone
https://nobgit.com/orgs/nobgit/nobmail.git
ssh://[email protected]:2222/orgs/nobgit/nobmail.git
Commit
always check basic auth against user database for EAS and SOGo if ALLOW_ADMIN_EMAIL_LOGIN is enabled
a1103780
data/conf/nginx/site.conf | 41 ++++++++++++++---------------------------
data/web/sogo-auth.php | 30 +++++++++++++++++++++++++++---
docker-compose.yml | 5 ++---
3 files changed, 43 insertions(+), 33 deletions(-)
Diff
diff --git a/data/conf/nginx/site.conf b/data/conf/nginx/site.conf
index a5dc0222..4c6d1daa 100644
--- a/data/conf/nginx/site.conf
+++ b/data/conf/nginx/site.conf
@@ -142,28 +142,6 @@ server {
try_files /autoconfig.php =404;
}
- location ^~ /Microsoft-Server-ActiveSync {
- include /etc/nginx/conf.d/sogo_eas.active;
- proxy_connect_timeout 4000;
- proxy_next_upstream timeout error;
- proxy_send_timeout 4000;
- proxy_read_timeout 4000;
- proxy_buffer_size 8k;
- proxy_buffers 16 64k;
- proxy_temp_file_write_size 64k;
- proxy_busy_buffers_size 64k;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header Host $http_host;
- proxy_set_header x-webobjects-server-protocol HTTP/1.0;
- proxy_set_header x-webobjects-remote-host $remote_addr;
- proxy_set_header x-webobjects-server-name $server_name;
- proxy_set_header x-webobjects-server-url $client_req_scheme://$http_host;
- proxy_set_header x-webobjects-server-port $server_port;
- client_body_buffer_size 128k;
- client_max_body_size 0;
- }
-
# auth_request endpoint if ALLOW_ADMIN_EMAIL_LOGIN is set
location /sogo-auth-verify {
internal;
@@ -175,8 +153,17 @@ server {
proxy_pass_request_body off;
}
- location ^~ /SOGo {
- include /etc/nginx/conf.d/sogo_main.active;
+ location ^~ /Microsoft-Server-ActiveSync {
+ include /etc/nginx/conf.d/sogo_proxy_auth.active;
+ include /etc/nginx/conf.d/sogo_eas.active;
+ proxy_connect_timeout 4000;
+ proxy_next_upstream timeout error;
+ proxy_send_timeout 4000;
+ proxy_read_timeout 4000;
+ proxy_buffer_size 8k;
+ proxy_buffers 16 64k;
+ proxy_temp_file_write_size 64k;
+ proxy_busy_buffers_size 64k;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
@@ -187,11 +174,11 @@ server {
proxy_set_header x-webobjects-server-port $server_port;
client_body_buffer_size 128k;
client_max_body_size 0;
- break;
}
- location ^~ /SOGo/dav {
- include /etc/nginx/conf.d/sogo_dav.active;
+ location ^~ /SOGo {
+ include /etc/nginx/conf.d/sogo_proxy_auth.active;
+ include /etc/nginx/conf.d/sogo.active;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
diff --git a/data/web/sogo-auth.php b/data/web/sogo-auth.php
index b08ca4e7..ae882f26 100644
--- a/data/web/sogo-auth.php
+++ b/data/web/sogo-auth.php
@@ -8,11 +8,31 @@ $ALLOW_ADMIN_EMAIL_LOGIN = (preg_match(
$session_var_user = 'sogo-sso-user';
$session_var_pass = 'sogo-sso-pass';
+// prevent if feature is disabled
if (!$ALLOW_ADMIN_EMAIL_LOGIN) {
- header('HTTP/1.0 401 Forbidden');
+ header('HTTP/1.0 403 Forbidden');
echo "this feature is disabled";
exit;
}
+// validate credentials for basic auth requests
+elseif (isset($_SERVER['PHP_AUTH_USER'])) {
+ // load prerequisites only when required
+ require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
+ $username = $_SERVER['PHP_AUTH_USER'];
+ $password = $_SERVER['PHP_AUTH_PW'];
+ $login_check = check_login($username, $password);
+ if ($login_check === 'user') {
+ header("X-User: $username");
+ header("X-Auth: Basic ".base64_encode("$username:$password"));
+ header("X-Auth-Type: Basic");
+ exit;
+ } else {
+ header('HTTP/1.0 401 Unauthorized');
+ echo 'Invalid login';
+ exit;
+ }
+}
+// check permissions and redirect for direct GET ?login=xy requests
elseif (isset($_GET['login'])) {
// load prerequisites only when required
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
@@ -32,10 +52,14 @@ elseif (isset($_GET['login'])) {
}
}
}
- header('HTTP/1.0 401 Forbidden');
+ header('HTTP/1.0 403 Forbidden');
exit;
}
-else {
+// do not check for admin-login / sogo-sso for EAS and DAV requests, SOGo can check auth itself if no authorization header is set
+elseif (
+ substr($_SERVER['HTTP_X_ORIGINAL_URI'], 0, 28) !== "/Microsoft-Server-ActiveSync" &&
+ substr($_SERVER['HTTP_X_ORIGINAL_URI'], 0, 9) !== "/SOGo/dav"
+) {
// this is an nginx auth_request call, we check for existing sogo-sso session variables
session_start();
if (isset($_SESSION[$session_var_user]) && filter_var($_SESSION[$session_var_user], FILTER_VALIDATE_EMAIL)) {
diff --git a/docker-compose.yml b/docker-compose.yml
index 724c5c6b..efee7ade 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -268,10 +268,9 @@ services:
command: /bin/sh -c "envsubst < /etc/nginx/conf.d/templates/listen_plain.template > /etc/nginx/conf.d/listen_plain.active &&
envsubst < /etc/nginx/conf.d/templates/listen_ssl.template > /etc/nginx/conf.d/listen_ssl.active &&
envsubst < /etc/nginx/conf.d/templates/server_name.template > /etc/nginx/conf.d/server_name.active &&
- . /etc/nginx/conf.d/templates/sogo.auth_request.template.sh > /etc/nginx/conf.d/sogo_main.active &&
- envsubst < /etc/nginx/conf.d/templates/sogo.template >> /etc/nginx/conf.d/sogo_main.active &&
- envsubst < /etc/nginx/conf.d/templates/sogo.template >> /etc/nginx/conf.d/sogo_dav.active &&
+ envsubst < /etc/nginx/conf.d/templates/sogo.template > /etc/nginx/conf.d/sogo.active &&
envsubst < /etc/nginx/conf.d/templates/sogo_eas.template > /etc/nginx/conf.d/sogo_eas.active &&
+ . /etc/nginx/conf.d/templates/sogo.auth_request.template.sh > /etc/nginx/conf.d/sogo_proxy_auth.active &&
nginx -qt &&
until ping phpfpm -c1 > /dev/null; do sleep 1; done &&
until ping sogo -c1 > /dev/null; do sleep 1; done &&