Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the name of the csrf token cookie #375

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion onadata/apps/main/static/js/application.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
$(document).ready(function(){

var CSRF_TOKEN_KEY = 'kobo_csrftoken';

// table sort example
// ==================

Expand Down Expand Up @@ -76,7 +78,7 @@ $(document).ready(function(){
}

if (!safeMethod(settings.type) && sameOrigin(settings.url)) {
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
xhr.setRequestHeader("X-CSRFToken", getCookie(CSRF_TOKEN_KEY));
}
});
// END CSRF Protection for AJAX
Expand Down
8 changes: 8 additions & 0 deletions onadata/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@
LOGIN_URL = '/accounts/login/'
LOGIN_REDIRECT_URL = '/login_redirect/'

# XXX: Since KoBo Toolbox's set of applications is using multiple subdomains,
# the CSRF cookie is established on a wildcard domain, so that it is accessible
# on all of the subdomains. That said, the generic `csrftoken` name might cause
# collisions with other django apps deployed on the same domain. This leads to
# issue where wrong CSRF token might be accepted in the django app, thus,
# breaking POST requests in the django app.
CSRF_COOKIE_NAME = 'kobo_csrftoken'

# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
Expand Down