Skip to content

Commit

Permalink
adding configurable csrf settings and including withXSRFToken in axio… (
Browse files Browse the repository at this point in the history
#1042)

* adding configurable csrf settings and including withXSRFToken in axios config

* removing 'CORS_ORIGIN_ALLOW_ALL' settings

* adding in default settings

* adding in CORS_ALLOWED_ORIGIN_REGEXES setting

* making CSRF_COOKIE_SECURE True by default

* adding CORS_REPLACE_HTTPS_REFERER

* Revert "adding CORS_REPLACE_HTTPS_REFERER"

This reverts commit 913cd7a.
  • Loading branch information
shanbady authored Jun 10, 2024
1 parent 4386fc2 commit 4c9ce08
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions frontends/api/src/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import axios from "axios"
const instance = axios.create({
xsrfCookieName: "csrftoken",
xsrfHeaderName: "X-CSRFToken",
withXSRFToken: true,
withCredentials:
APP_SETTINGS.axios_with_credentials?.toLowerCase() === "true",
})
Expand Down
15 changes: 13 additions & 2 deletions main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,22 @@
# CORS
CORS_ALLOWED_ORIGINS = get_list_of_str("CORS_ALLOWED_ORIGINS", [])
CORS_ALLOWED_ORIGIN_REGEXES = get_list_of_str("CORS_ALLOWED_ORIGIN_REGEXES", [])
CORS_ALLOW_CREDENTIALS = True

CSRF_TRUSTED_ORIGINS = get_list_of_str("CSRF_TRUSTED_ORIGINS", [])
CORS_ALLOW_CREDENTIALS = get_bool("CORS_ALLOW_CREDENTIALS", True) # noqa: FBT003
SECURE_CROSS_ORIGIN_OPENER_POLICY = get_string(
"SECURE_CROSS_ORIGIN_OPENER_POLICY",
"same-origin",
)

CSRF_COOKIE_SECURE = get_bool("CSRF_COOKIE_SECURE", True) # noqa: FBT003
SESSION_COOKIE_DOMAIN = get_string("SESSION_COOKIE_DOMAIN", None)
CSRF_COOKIE_DOMAIN = get_string("CSRF_COOKIE_DOMAIN", None)

CSRF_HEADER_NAME = get_string("CSRF_HEADER_NAME", "HTTP_X_CSRFTOKEN")


CSRF_TRUSTED_ORIGINS = get_list_of_str("CSRF_TRUSTED_ORIGINS", [])

# enable the nplusone profiler only in debug mode
if DEBUG:
INSTALLED_APPS += ("nplusone.ext.django",)
Expand Down

0 comments on commit 4c9ce08

Please sign in to comment.