File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 135135
136136AUTH_USER_MODEL = "users.User"
137137CSRF_COOKIE_HTTPONLY = True
138+ CSRF_COOKIE_SAMESITE = "Lax"
138139# See https://docs.djangoproject.com/en/4.2/ref/settings/#csrf-trusted-origins
139140csrf_trusted_origins = env .list (
140141 "CSRF_TRUSTED_ORIGINS" , default = ["http://0.0.0.0" , "http://localhost" ]
257258# Increase default cookie age from 2 to 12 weeks
258259SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 12
259260
261+ # Not "Strict": the social auth providers redirect back cross-site, and that
262+ # request must still carry the session cookie for the callback to resolve.
263+ SESSION_COOKIE_SAMESITE = "Lax"
264+
260265# Internationalization
261266# https://docs.djangoproject.com/en/1.10/topics/i18n/
262267
500505 "HTTP_X_FORWARDED_PROTO" ,
501506 ACCOUNT_DEFAULT_HTTP_PROTOCOL ,
502507 )
508+ SESSION_COOKIE_SECURE = True
509+ CSRF_COOKIE_SECURE = True
503510
504511# Admin banner configuration
505512ENV_NAME = env ("ENVIRONMENT_NAME" , default = "Unknown Environment" )
635642
636643CORS_ALLOW_ALL_ORIGINS = True
637644CORS_ALLOW_CREDENTIALS = True
638- SESSION_COOKIE_HTTPONLY = False
645+ SESSION_COOKIE_HTTPONLY = True
639646
640647CORS_ALLOW_METHODS = (
641648 "DELETE" ,
Original file line number Diff line number Diff line change @@ -153,18 +153,11 @@ <h3>{% trans 'Delete Account' %}</h3>
153153
154154 {% include "modal.html" %}
155155
156- < script >
157- document . body . addEventListener ( 'htmx:configRequest' , function ( event ) {
158- /* only set CSRF token if config-sessionid cookie exists.
159- we don't really need this check while this functionality is limited to this
160- page, but I'm adding it anyway in case we move this in the future so we don't
161- overlook it. */
162- const hasSessionId = document . cookie . split ( ';' ) . some ( function ( cookie ) {
163- return cookie . trim ( ) . startsWith ( 'config-sessionid=' ) ;
164- } ) ;
165- if ( hasSessionId ) {
156+ {% if request.user.is_authenticated %}
157+ < script >
158+ document . body . addEventListener ( 'htmx:configRequest' , function ( event ) {
166159 event . detail . headers [ 'X-CSRFToken' ] = '{{ csrf_token }}' ;
167- }
168- } ) ;
169- </ script >
160+ } ) ;
161+ </ script >
162+ {% endif %}
170163{% endblock %}
You can’t perform that action at this time.
0 commit comments