Remove CSRF middleware/processor in aws and dev settings,

not common.  This ensures that we load the MITX_FEATURES
token BEFORE deciding to disable CSRF.
This commit is contained in:
Will Daly
2013-07-31 16:40:54 -04:00
committed by Will Daly
parent 8573ac3909
commit 39030c6683
6 changed files with 38 additions and 20 deletions

View File

@@ -126,6 +126,14 @@ LOGGING = get_logger_config(LOG_DIR,
#theming start:
PLATFORM_NAME = ENV_TOKENS.get('PLATFORM_NAME', 'edX')
# Disable CSRF for load testing
if MITX_FEATURES.get('AUTOMATIC_AUTH_FOR_LOAD_TESTING'):
exclude_csrf = lambda elem: not elem in \
['django.core.context_processors.csrf',
'django.middleware.csrf.CsrfViewMiddleware']
TEMPLATE_CONTEXT_PROCESSORS = filter(exclude_csrf, TEMPLATE_CONTEXT_PROCESSORS)
MIDDLEWARE_CLASSES = filter(exclude_csrf, MIDDLEWARE_CLASSES)
################ SECURE AUTH ITEMS ###############################
# Secret things: passwords, access keys, etc.

View File

@@ -105,12 +105,9 @@ TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.static',
'django.contrib.messages.context_processors.messages',
'django.contrib.auth.context_processors.auth', # this is required for admin
'django.core.context_processors.csrf'
)
# add csrf support unless disabled for load testing
if not MITX_FEATURES.get('AUTOMATIC_AUTH_FOR_LOAD_TESTING'):
TEMPLATE_CONTEXT_PROCESSORS += ('django.core.context_processors.csrf',) # necessary for csrf protection
LMS_BASE = None
#################### CAPA External Code Evaluation #############################
@@ -141,6 +138,7 @@ MIDDLEWARE_CLASSES = (
'request_cache.middleware.RequestCache',
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'method_override.middleware.MethodOverrideMiddleware',
@@ -157,10 +155,6 @@ MIDDLEWARE_CLASSES = (
'django.middleware.transaction.TransactionMiddleware'
)
# add in csrf middleware unless disabled for load testing
if not MITX_FEATURES.get('AUTOMATIC_AUTH_FOR_LOAD_TESTING'):
MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES + ('django.middleware.csrf.CsrfViewMiddleware',)
############################ SIGNAL HANDLERS ################################
# This is imported to register the exception signal handling that logs exceptions
import monitoring.exceptions # noqa

View File

@@ -182,6 +182,15 @@ SEGMENT_IO_KEY = os.environ.get('SEGMENT_IO_KEY')
if SEGMENT_IO_KEY:
MITX_FEATURES['SEGMENT_IO'] = True
########################## LOAD TESTING ########################
# Disable CSRF for load testing
if MITX_FEATURES.get('AUTOMATIC_AUTH_FOR_LOAD_TESTING'):
exclude_csrf = lambda elem: not elem in \
['django.core.context_processors.csrf',
'django.middleware.csrf.CsrfViewMiddleware']
TEMPLATE_CONTEXT_PROCESSORS = filter(exclude_csrf, TEMPLATE_CONTEXT_PROCESSORS)
MIDDLEWARE_CLASSES = filter(exclude_csrf, MIDDLEWARE_CLASSES)
#####################################################################
# Lastly, see if the developer has any local overrides.