Skip to content

Commit baa10c0

Browse files
authored
[Fixex #13805] Fix lockdown middleware order (#13806)
1 parent cc94699 commit baa10c0

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
@@ -862,18 +862,23 @@
862862
if SESSION_ENGINE in ("django.contrib.sessions.backends.cached_db", "django.contrib.sessions.backends.cache"):
863863
SESSION_CACHE_ALIAS = "memcached" # use memcached cache if a cached backend is requested
864864

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

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

879884
if SESSION_EXPIRED_CONTROL_ENABLED:
@@ -974,22 +979,6 @@
974979
# 1 day expiration time by default
975980
ACCESS_TOKEN_EXPIRE_SECONDS = int(os.getenv("ACCESS_TOKEN_EXPIRE_SECONDS", "86400"))
976981

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

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

0 commit comments

Comments
 (0)