Fix DisallowedHost error during initial setup from unknown hosts#36
Merged
Fix DisallowedHost error during initial setup from unknown hosts#36
Conversation
…tests Co-authored-by: vbrunelle <27235114+vbrunelle@users.noreply.github.com>
…ric Exception Co-authored-by: vbrunelle <27235114+vbrunelle@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix allowed host check before NoHands server initialization
Fix DisallowedHost error during initial setup from unknown hosts
Nov 26, 2025
Owner
|
@copilot Have you tried testing the problem by using the Docker-compose file for no hands and reproducing step by step? |
Contributor
Author
I wasn't able to build the Docker image in this sandboxed environment due to network restrictions, but I did simulate the Docker environment behavior by testing with the exact host from your issue ( The test confirms the fix works: The fix ensures that when no users exist (fresh install), any host is allowed through the middleware, preventing the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Accessing NoHands from an external host (e.g.,
machine.local:8000) before initial setup caused aDisallowedHosterror instead of showing the setup page. The middleware now gracefully handles database unavailability during host validation.Changes:
User.objects.exists()inInitialSetupMiddlewareandDynamicAllowedHostsMiddlewareAllowedHost.get_all_active_hosts()DatabaseErrorandOperationalErrorexceptionsType of Change
How Has This Been Tested?
Added
InitialSetupUnknownHostTest(5 tests) andDatabaseUnavailableMiddlewareTest(1 test) covering:Test Configuration:
Checklist
Related Issues
Closes #(issue number)
Screenshots (if applicable)
N/A
Additional Notes
The existing test
test_get_shows_form_when_oauth_not_configuredintest_utils_views.pywas already failing before these changes (unrelated template text mismatch).Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
dl.dagger.io/usr/bin/python python manage.py test(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>Still checking to see if current host is in the allowed host before the first initialization of the NoHands server</issue_title>
<issue_description>Still checking to see if current host is in the allowed host before the first initialization of the NoHands server.
Steps to reproduce:
It is very import to me that you follow a step by step methodology.
Comments on the Issue (you are @copilot in this section)
@vbrunelle Here is the message that I get in the container log after trying to access the web UI for the first time.`nohands-1 | System check identified some issues:
nohands-1 |
nohands-1 | WARNINGS:
nohands-1 | ?: settings.ACCOUNT_AUTHENTICATION_METHOD is deprecated, use: settings.ACCOUNT_LOGIN_METHODS = {'email', 'username'}
nohands-1 | ?: settings.ACCOUNT_EMAIL_REQUIRED is deprecated, use: settings.ACCOUNT_SIGNUP_FIELDS = ['email', 'username*', 'password1*', 'password2*']
nohands-1 | Operations to perform:
nohands-1 | Apply all migrations: account, admin, auth, builds, contenttypes, projects, sessions, sites, socialaccount
nohands-1 | Running migrations:
nohands-1 | No migrations to apply.
nohands-1 | Watching for file changes with StatReloader
nohands-1 | Performing system checks...
nohands-1 |
nohands-1 | System check identified some issues:
nohands-1 |
nohands-1 | WARNINGS:
nohands-1 | ?: settings.ACCOUNT_AUTHENTICATION_METHOD is deprecated, use: settings.ACCOUNT_LOGIN_METHODS = {'username', 'email'}
nohands-1 | ?: settings.ACCOUNT_EMAIL_REQUIRED is deprecated, use: settings.ACCOUNT_SIGNUP_FIELDS = ['email', 'username*', 'password1*', 'password2*']
nohands-1 |
nohands-1 | System check identified 2 issues (0 silenced).
nohands-1 | November 26, 2025 - 02:12:19
nohands-1 | Django version 5.2.8, using settings 'nohands_project.settings'
nohands-1 | Starting development server at http://0.0.0.0:8000/
nohands-1 | Quit the server with CONTROL-C.
nohands-1 |
nohands-1 | WARNING: This is a development server. Do not use it in a production setting. Use a production WSGI or ASGI server instead.
nohands-1 | For more information on production servers see: https://docs.djangoproject.com/en/5.2/howto/deployment/
nohands-1 | Traceback (most recent call last):
nohands-1 | File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
nohands-1 | response = get_response(request)
nohands-1 | ^^^^^^^^^^^^^^^^^^^^^
nohands-1 | File "/usr/local/lib/python3.11/site-packages/django/utils/deprecation.py", line 119, in call
nohands-1 | response = self.process_request(request)
nohands-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
nohands-1 | File "/usr/local/lib/python3.11/site-packages/django/middleware/common.py", line 48, in process_request
nohands-1 | host = request.get_host()
nohands-1 | ^^^^^^^^^^^^^^^^^^
nohands-1 | File "/usr/local/lib/python3.11/site-packages/django/http/request.py", line 202, in get_host
nohands-1 | raise DisallowedHost(msg)
nohands-1 | django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: 'ceos.home:8000'. You may need to add 'ceos.home' to ALLOWED_HOSTS.
nohands-1 |
nohands-1 | During handling of the above exception, another exception occurred:
nohands-1 |
nohands-1 | Traceback (most recent call last):
nohands-1 | File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
nohands-1 | response = get_response(request)
nohands-1 | ^^^^^^^^^^^^^^^^^^^^^
nohands-1 | File "/usr/local/lib/python3.11/site-packages/django/utils/deprecation.py", line 120, in call
nohands-1 | response = response or self.get_response(request)
nohands-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^
nohands-1 | File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 57, in inner
nohands-1 | response = response_for_exception(request, exc)
nohands-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
nohands-1 | File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 120, in respons...
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.