Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(api): require authentication for the models_dir endpoint
joshistoast00a00a0657d9
diff --git a/invokeai/app/api/routers/model_manager.py b/invokeai/app/api/routers/model_manager.pyindex bcdc6aeabc..2e3b2d54dd 100644--- a/invokeai/app/api/routers/model_manager.py+++ b/invokeai/app/api/routers/model_manager.py@@ -232,7 +232,7 @@ async def list_missing_models(current_user: CurrentUserOrDefault) -> ModelsList:operation_id="get_models_dir",responses={200: {"description": "The absolute path of the models directory"}},)-async def get_models_dir() -> str:+async def get_models_dir(current_user: CurrentUserOrDefault) -> str:"""Get the absolute path of the directory managed models are stored in.Model config `path` values are relative to this directory unless they arediff --git a/invokeai/frontend/web/openapi.json b/invokeai/frontend/web/openapi.jsonindex a63303526d..6a8e71c4cd 100644--- a/invokeai/frontend/web/openapi.json+++ b/invokeai/frontend/web/openapi.json@@ -756,7 +756,12 @@}}}- }+ },+ "security": [+ {+ "HTTPBearer": []+ }+ ]}},"/api/v2/models/get_by_attrs": {diff --git a/tests/app/routers/test_model_manager_authorization.py b/tests/app/routers/test_model_manager_authorization.pyindex 5ee03a161f..50fb9c93f9 100644--- a/tests/app/routers/test_model_manager_authorization.py+++ b/tests/app/routers/test_model_manager_authorization.py@@ -31,6 +31,7 @@ PROTECTED_ROUTES = [("get", "/api/v2/models/scan_folder?scan_path=/etc"),("get", "/api/v2/models/"),("get", "/api/v2/models/missing"),+ ("get", "/api/v2/models/models_dir"),("get", "/api/v2/models/get_by_attrs?name=x&type=main&base=sd-1"),("get", "/api/v2/models/get_by_hash?hash=x"),("get", "/api/v2/models/i/some-key"),@@ -232,6 +233,22 @@ def test_regular_user_can_still_list_models(assert response.json() == {"models": []}+def test_regular_user_can_read_models_dir(+ enable_multiuser: Any,+ client: TestClient,+ user1_token: str,+ tmp_path: Path,+ monkeypatch: Any,+) -> None:+ """The shared model store needs this path when rendering model details for ordinary users."""+ monkeypatch.setattr(InvokeAIAppConfig, "models_path", property(lambda _self: tmp_path))++ response = client.get("/api/v2/models/models_dir", headers=_auth(user1_token))++ assert response.status_code == status.HTTP_200_OK+ assert response.json() == tmp_path.resolve().as_posix()++def _sd1_checkpoint(key: str, path: str) -> Main_Checkpoint_SD1_Config:return Main_Checkpoint_SD1_Config(key=key,