Security: disallow API remote-user auth if disabled (#6739)

This commit is contained in:
shamoon
2024-05-15 13:18:50 -07:00
committed by GitHub
parent 97eec44647
commit ed05b40ba4
2 changed files with 44 additions and 0 deletions

View File

@@ -52,6 +52,17 @@ class HttpRemoteUserMiddleware(PersistentRemoteUserMiddleware):
header = settings.HTTP_REMOTE_USER_HEADER_NAME
def process_request(self, request: HttpRequest) -> None:
# If remote user auth is enabled only for the frontend, not the API,
# then we need dont want to authenticate the user for API requests.
if (
"/api/" in request.path
and "paperless.auth.PaperlessRemoteUserAuthentication"
not in settings.REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"]
):
return
return super().process_request(request)
class PaperlessRemoteUserAuthentication(authentication.RemoteUserAuthentication):
"""