From 6288716992d6cef8aa854874410f4c093b9e4bed Mon Sep 17 00:00:00 2001 From: king Date: Sun, 24 May 2026 17:58:57 +0900 Subject: [PATCH] =?UTF-8?q?fix(sso):=20AuthGuard=20=EA=B2=BD=EB=A1=9C=20?= =?UTF-8?q?=EC=A0=95=EA=B7=9C=ED=99=94=20=E2=80=94=20scope.path=20?= =?UTF-8?q?=EA=B0=80=20root=5Fpath=20=ED=8F=AC=ED=95=A8=20=EC=97=AC?= =?UTF-8?q?=EB=B6=80=EC=99=80=20=EB=AC=B4=EA=B4=80=ED=95=98=EA=B2=8C=20?= =?UTF-8?q?=EB=8F=99=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit uvicorn --root-path 설정 시 ASGI scope.path 가 환경/버전에 따라 prepend 되는 경우가 있어 매칭이 어긋났다. raw path 가 APP_ROOT_PATH 로 시작하면 잘라내고, 아니면 그대로 사용하도록 정규화. 증상: GET /health/db → 302 (exempt 미작동), next=/corm/corm/ (이중 prefix). --- main.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index c9a8c38..1fb269f 100644 --- a/main.py +++ b/main.py @@ -71,9 +71,16 @@ class AuthGuardMiddleware(BaseHTTPMiddleware): """ async def dispatch(self, request: Request, call_next): - # ASGI scope 의 raw path 는 root_path 가 제외된 형태. - # (request.url.path 는 root_path 가 prepend 된 형태라 prefix 매칭이 어긋남) - path = request.scope.get("path", "") + # 환경별로 scope.path 가 root_path 를 포함할 수도, 안 할 수도 있어 + # 항상 root_path 제외된 형태로 정규화한다. + raw = request.scope.get("path", "") or "/" + if APP_ROOT_PATH and raw.startswith(APP_ROOT_PATH + "/"): + path = raw[len(APP_ROOT_PATH):] + elif APP_ROOT_PATH and raw == APP_ROOT_PATH: + path = "/" + else: + path = raw + for prefix in _AUTH_EXEMPT_PREFIXES: if path == prefix or path.startswith(prefix): return await call_next(request)