From 9385dfc27ebe02cbc47dc2f1655f3900d0f59d84 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 9 Apr 2024 12:39:02 -0400 Subject: [PATCH] Fix security flaw allowing leaking of meta data in the API Coding bug allows bypassing the API authentication on private servers, to reach the config, network, and build info meta-data endpoints. config and build-info are already public generally, but network meta-data was not. --- OpenBench/views.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/OpenBench/views.py b/OpenBench/views.py index a3c8775..cfca8b7 100644 --- a/OpenBench/views.py +++ b/OpenBench/views.py @@ -822,18 +822,20 @@ def api_authenticate(request, require_enabled=False): try: + # Force requiring an enabled user when require_login_to_view is set + require_enabled = require_enabled or OPENBENCH_CONFIG['require_login_to_view'] + # Don't require a login for Public frameworks - if not require_enabled and not OPENBENCH_CONFIG['require_login_to_view']: + if not require_enabled: return True # Request is made from a browser, and is already logged in if request.user.is_authenticated: - return not require_enabled or bool(Profile.objects.get(user=request.user).enabled) + return Profile.objects.get(user=request.user).enabled # Request might be made from the command line. Check the headers - user = django.contrib.auth.authenticate( - username=request.POST['username'], password=request.POST['password']) - return not require_enabled or Profile.objects.get(user=user).enabled + return django.contrib.auth.authenticate( + username=request.POST['username'], password=request.POST['password']).enabled except Exception: import traceback