Skip to content

Commit 7e583e7

Browse files
[Fixex #13805] Fix lockdown middleware order (#13806) (#13815)
(cherry picked from commit baa10c0) Co-authored-by: Giovanni Allegri <giohappy@gmail.com>
1 parent ab57998 commit 7e583e7

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

geonode/settings.py

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -863,18 +863,23 @@
863863
if SESSION_ENGINE in ("django.contrib.sessions.backends.cached_db", "django.contrib.sessions.backends.cache"):
864864
SESSION_CACHE_ALIAS = "memcached" # use memcached cache if a cached backend is requested
865865

866-
# Security stuff
867-
868-
# Require users to authenticate before using Geonode
869-
LOCKDOWN_GEONODE = ast.literal_eval(os.getenv("LOCKDOWN_GEONODE", "False"))
870-
# Require users to authenticate before using Geonode
871-
if LOCKDOWN_GEONODE:
872-
MIDDLEWARE += ("geonode.security.middleware.LoginRequiredMiddleware",)
873-
874-
# LOCKDOWN API endpoints to prevent unauthenticated access.
875-
# If set to True, search won't deliver results and filtering ResourceBase-objects is not possible for anonymous users
876-
API_LOCKDOWN = ast.literal_eval(os.getenv("API_LOCKDOWN", "False"))
866+
# Add additional paths (as regular expressions) that don't require
867+
# authentication.
868+
# - authorized exempt urls needed for oauth when GeoNode is set to lockdown
869+
AUTH_EXEMPT_URLS = (
870+
f"{FORCE_SCRIPT_NAME}/o/*",
871+
f"{FORCE_SCRIPT_NAME}/gs/*",
872+
f"{FORCE_SCRIPT_NAME}/account/*",
873+
f"{FORCE_SCRIPT_NAME}/static/*",
874+
f"{FORCE_SCRIPT_NAME}/api/o/*",
875+
f"{FORCE_SCRIPT_NAME}/api/roles",
876+
f"{FORCE_SCRIPT_NAME}/api/adminRole",
877+
f"{FORCE_SCRIPT_NAME}/api/users",
878+
f"{FORCE_SCRIPT_NAME}/api/datasets",
879+
r"^/i18n/setlang/?$",
880+
)
877881

882+
# Security stuff
878883
SESSION_EXPIRED_CONTROL_ENABLED = ast.literal_eval(os.environ.get("SESSION_EXPIRED_CONTROL_ENABLED", "True"))
879884

880885
if SESSION_EXPIRED_CONTROL_ENABLED:
@@ -975,22 +980,6 @@
975980
# 1 day expiration time by default
976981
ACCESS_TOKEN_EXPIRE_SECONDS = int(os.getenv("ACCESS_TOKEN_EXPIRE_SECONDS", "86400"))
977982

978-
# Add additional paths (as regular expressions) that don't require
979-
# authentication.
980-
# - authorized exempt urls needed for oauth when GeoNode is set to lockdown
981-
AUTH_EXEMPT_URLS = (
982-
f"{FORCE_SCRIPT_NAME}/o/*",
983-
f"{FORCE_SCRIPT_NAME}/gs/*",
984-
f"{FORCE_SCRIPT_NAME}/account/*",
985-
f"{FORCE_SCRIPT_NAME}/static/*",
986-
f"{FORCE_SCRIPT_NAME}/api/o/*",
987-
f"{FORCE_SCRIPT_NAME}/api/roles",
988-
f"{FORCE_SCRIPT_NAME}/api/adminRole",
989-
f"{FORCE_SCRIPT_NAME}/api/users",
990-
f"{FORCE_SCRIPT_NAME}/api/datasets",
991-
r"^/i18n/setlang/?$",
992-
)
993-
994983
ANONYMOUS_USER_ID = os.getenv("ANONYMOUS_USER_ID", "-1")
995984
GUARDIAN_GET_INIT_ANONYMOUS_USER = os.getenv(
996985
"GUARDIAN_GET_INIT_ANONYMOUS_USER", "geonode.people.models.get_anonymous_user_instance"
@@ -1039,6 +1028,16 @@
10391028
AUTHENTICATION_BACKENDS = ("geonode.security.backends.AdminRestrictedAccessBackend",) + AUTHENTICATION_BACKENDS
10401029
MIDDLEWARE += ("geonode.security.middleware.AdminAllowedMiddleware",)
10411030

1031+
# LOCKDOWN API endpoints to prevent unauthenticated access.
1032+
# If set to True, search won't deliver results and filtering ResourceBase-objects is not possible for anonymous users
1033+
API_LOCKDOWN = ast.literal_eval(os.getenv("API_LOCKDOWN", "False"))
1034+
1035+
# Require users to authenticate before using Geonode
1036+
LOCKDOWN_GEONODE = ast.literal_eval(os.getenv("LOCKDOWN_GEONODE", "False"))
1037+
# Require users to authenticate before using Geonode
1038+
if LOCKDOWN_GEONODE:
1039+
MIDDLEWARE += ("geonode.security.middleware.LoginRequiredMiddleware",)
1040+
10421041
# A tuple of hosts the proxy can send requests to.
10431042
try:
10441043
# try to parse python notation, default in dockerized env

0 commit comments

Comments
 (0)