"""Production configuration preflight (``python -m core.cli check-config``; also run by ``core.serve`` and ``core.worker`` at startup when ``WP_ENV=production``). Refuses the development defaults that are safe on a laptop and dangerous on the internet. """ from __future__ import annotations from sqlalchemy.engine import make_url from core.config import Settings DEV_JWT_SECRET = "dev-only-change-me-0123456789abcdef" # noqa: S105 (the known default) DEV_DB_PASSWORDS = {"workpilot_app", "workpilot_owner", "postgres", "app", "owner"} def production_problems(s: Settings) -> list[str]: if s.env.lower() not in ("production", "prod", "staging"): return [] problems: list[str] = [] secret = s.jwt_secret.get_secret_value() if secret == DEV_JWT_SECRET or "change-me" in secret or len(secret) < 32: problems.append("WP_JWT_SECRET is a placeholder or shorter than 32 characters") for name, url in ( ("WP_DATABASE_URL", s.database_url), ("WP_OWNER_DATABASE_URL", s.owner_database_url), ): try: pw = make_url(url).password except Exception: problems.append(f"{name} is not a valid database URL") continue if pw is None or str(pw) in DEV_DB_PASSWORDS: problems.append(f"{name} uses a development password") if make_url(s.database_url).username == make_url(s.owner_database_url).username: problems.append("WP_DATABASE_URL must use the app role, not the owner role (RLS)") if s.ext_allow_http or s.ext_allow_private_hosts: problems.append("WP_EXT_ALLOW_HTTP / WP_EXT_ALLOW_PRIVATE_HOSTS disable the SSRF guard") return problems