Skip to content

fix: [website] fix IS_DEVELOPMENT rebind so dev admin password generates - #876

Open
elhoim wants to merge 1 commit into
MISP:mainfrom
elhoim:fix/065-website-is-development-rebind
Open

fix: [website] fix IS_DEVELOPMENT rebind so dev admin password generates#876
elhoim wants to merge 1 commit into
MISP:mainfrom
elhoim:fix/065-website-is-development-rebind

Conversation

@elhoim

@elhoim elhoim commented Aug 31, 2026

Copy link
Copy Markdown
Member

website/main.py's run_dev() did:

from app.utils import IS_DEVELOPMENT

IS_DEVELOPMENT = True

from app.utils import IS_DEVELOPMENT binds a local name IS_DEVELOPMENT in main.py's own module namespace. The following IS_DEVELOPMENT = True only rebinds that local — it never touches the module-level global IS_DEVELOPMENT in app/utils/utils.py, which is the one gen_admin_password() actually reads (if IS_DEVELOPMENT: at app/utils/utils.py:84). Since gen_admin_password is defined inside app/utils/utils.py, its global scope resolves against that submodule's __dict__, not against app.utils's re-exported copy — so even app.utils.IS_DEVELOPMENT = True would not have worked either, since that's a separate binding created by app/utils/__init__.py's own from .utils import IS_DEVELOPMENT.

Impact: Running the MISP modules website in dev mode (run_dev()) with no ADMIN_PASSWORD env var set is supposed to auto-generate and print a development admin password. Because of this rebind bug, gen_admin_password() always sees IS_DEVELOPMENT as False, so no password is ever generated or printed — an operator standing up a local dev instance gets no way to log in as admin.

Fix: Import the submodule directly — import app.utils.utils as utils — and set utils.IS_DEVELOPMENT = True, so the assignment lands on the actual global that gen_admin_password() reads. The debug= kwarg passed to app.run() is updated to reference utils.IS_DEVELOPMENT since the old local name no longer exists.

Behaviour change: This restores the code's evident intent rather than introducing new behaviour — the IS_DEVELOPMENT flag exists solely to trigger this auto-generate-password path, and the change is scoped entirely to run_dev(), which is never invoked in production.

Verification

website/ has no automated test coverage in this repository. Verification was:

  • python -m py_compile website/main.py: clean
  • Full module test suite: 161 passed, 4 skipped, 5 subtests passed in 25.71s

Found during a review of the repository; other findings are being submitted as separate PRs.

🤖 Generated with Claude Code

https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8

run_dev() imported IS_DEVELOPMENT via `from app.utils import IS_DEVELOPMENT`
and then wrote `IS_DEVELOPMENT = True`, which only rebinds the local name in
main.py. The module-level flag that gen_admin_password() actually reads
(app.utils.utils.IS_DEVELOPMENT) stayed False, so running the dev server
never triggered the auto-generated admin password path, silently leaving
the admin account without a printed credential.

The fix targets app.utils.utils rather than the app.utils package: the
package re-exports IS_DEVELOPMENT via a from-import into its own namespace,
which is a separate copy from the submodule global that gen_admin_password's
function scope resolves against, so rebinding the package attribute would
not have reached the function either.

Verified with py_compile on the changed file and the full pytest suite
against a live misp-modules server on port 6765: 161 passed, 4 skipped, 5
subtests passed, matching baseline.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant