fix(sso): AuthGuard 경로 정규화 — scope.path 가 root_path 포함 여부와 무관하게 동작

uvicorn --root-path 설정 시 ASGI scope.path 가 환경/버전에 따라 prepend 되는
경우가 있어 매칭이 어긋났다. raw path 가 APP_ROOT_PATH 로 시작하면 잘라내고,
아니면 그대로 사용하도록 정규화.

증상: GET /health/db → 302 (exempt 미작동), next=/corm/corm/ (이중 prefix).
This commit is contained in:
2026-05-24 17:58:57 +09:00
parent a8ea265e61
commit 6288716992
+10 -3
View File
@@ -71,9 +71,16 @@ class AuthGuardMiddleware(BaseHTTPMiddleware):
""" """
async def dispatch(self, request: Request, call_next): async def dispatch(self, request: Request, call_next):
# ASGI scope 의 raw path root_path 가 제외된 형태. # 환경별로 scope.path root_path 를 포함할 수도, 안 할 수도 있어
# (request.url.path 는 root_path 가 prepend 된 형태라 prefix 매칭이 어긋남) # 항상 root_path 제외된 형태로 정규화한다.
path = request.scope.get("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: for prefix in _AUTH_EXEMPT_PREFIXES:
if path == prefix or path.startswith(prefix): if path == prefix or path.startswith(prefix):
return await call_next(request) return await call_next(request)