File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change 2020def _cookie_params () -> dict :
2121 # In production behind HTTPS, cookies must be Secure.
2222 secure = not settings .DEBUG
23- return {
23+ params = {
2424 "httponly" : True ,
2525 "secure" : secure ,
2626 "samesite" : "Lax" ,
2727 "path" : "/" ,
2828 }
29+ domain = getattr (settings , 'COOKIE_DOMAIN' , None )
30+ if domain :
31+ params ["domain" ] = domain
32+ return params
2933
3034
3135class CsrfView (APIView ):
Original file line number Diff line number Diff line change 280280CSRF_COOKIE_SAMESITE = config ('CSRF_COOKIE_SAMESITE' , default = 'Lax' )
281281CSRF_COOKIE_HTTPONLY = False
282282
283+ # Share cookies across subdomains when needed (e.g. atonixdev.org + api.atonixdev.org).
284+ # Set COOKIE_DOMAIN=.atonixdev.org in production if the frontend needs to read csrftoken.
285+ COOKIE_DOMAIN = config ('COOKIE_DOMAIN' , default = '' ).strip () or None
286+ if COOKIE_DOMAIN :
287+ SESSION_COOKIE_DOMAIN = COOKIE_DOMAIN
288+ CSRF_COOKIE_DOMAIN = COOKIE_DOMAIN
289+
283290# Content Security Policy (start in report-only to avoid breaking third-party assets)
284291CSP_REPORT_ONLY = config ('CSP_REPORT_ONLY' , default = True , cast = bool )
285292CSP_DEFAULT_SRC = ("'self'" , 'https:' , 'data:' )
You can’t perform that action at this time.
0 commit comments