🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!
Fix #190/#97: contradictory scheme headers and no nginx bypass
Omega (QA)9dfd8f05c3bb
diff --git a/Docker/entrypoint.sh b/Docker/entrypoint.shindex a278b1e..c689505 100644--- a/Docker/entrypoint.sh+++ b/Docker/entrypoint.sh@@ -45,6 +45,15 @@ sed "s|__NGINX_MAX_BODY_SIZE_CONFIG_VALUE__|${EFFECTIVE_SIZE}|g" \/etc/nginx/conf.d/default.conf.template > /tmp/nginx-default.conflog "Nginx config prepared (size: ${EFFECTIVE_SIZE})"++# Optional: run gunicorn directly without nginx (issue #190).+# Set DISABLE_NGINX=true and publish port 5000 to put your own reverse+# proxy in front of the Flask app.+if [ "${DISABLE_NGINX:-false}" = "true" ]; then+ log "DISABLE_NGINX=true: removing nginx from supervisord; gunicorn serves directly on :5000"+ sed -i '/^\[program:nginx\]/,/^$/d' /etc/supervisor/conf.d/supervisord.conf+fi+log "Setup completed successfully!"# Execute the CMD (supervisor) by replacing this shell processdiff --git a/backend/__init__.py b/backend/__init__.pyindex 0e5442f..72e2ec6 100644--- a/backend/__init__.py+++ b/backend/__init__.py@@ -177,8 +177,27 @@ def create_app(config_name=None):app.register_blueprint(statistics_bp, url_prefix='/api')app.register_blueprint(tags_bp, url_prefix='/api')app.register_blueprint(file_bp, url_prefix='/api')-+logger.info("All blueprints registered successfully")++ # Serve the frontend directly when nginx is disabled (DISABLE_NGINX=true,+ # issue #190). In the normal setup nginx serves these paths and the+ # Flask app never sees them, so this is a no-op there.+ if os.environ.get('DISABLE_NGINX', 'false').lower() == 'true':+ from flask import send_from_directory+ frontend_dir = '/var/www/html'++ @app.route('/', defaults={'path': ''})+ @app.route('/<path:path>')+ def serve_frontend(path):+ if path.startswith('api/'):+ return jsonify({'error': 'Not found'}), 404+ full = os.path.join(frontend_dir, path)+ if path and os.path.isfile(full):+ return send_from_directory(frontend_dir, path)+ return send_from_directory(frontend_dir, 'index.html')++ logger.info("DISABLE_NGINX=true: Flask will serve the frontend directly")# Initialize OIDC client after extensions and blueprintstry:diff --git a/nginx.conf b/nginx.confindex df960aa..b0ba16f 100644--- a/nginx.conf+++ b/nginx.conf@@ -55,9 +55,17 @@ server {# $host drops the port, which broke OIDC redirect_uri generation# (issue #238) for anyone serving Warracker on a nonstandard port.proxy_set_header Host $http_host;+ # Pass through the outer proxy's scheme when present (issues #190/#97).+ # An empty value means nginx omits the header, so gunicorn falls back+ # to the direct connection scheme.+ proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;+ # Clear the other scheme headers: gunicorn 400s on contradictory+ # scheme headers, and a single X-Forwarded-Proto is unambiguous.+ # (Empty values are not sent by nginx.)+ proxy_set_header X-Forwarded-Ssl "";+ proxy_set_header X-Forwarded-Protocol "";proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;- proxy_set_header X-Forwarded-Proto $scheme;client_max_body_size __NGINX_MAX_BODY_SIZE_CONFIG_VALUE__; # Configurable limit for API location# Pass Authorization header to backend