[Django] #21495: Add a setting for CSRF Header name

23 views
Skip to first unread message

Django

unread,
Nov 22, 2013, 2:34:57 PM11/22/13
to django-...@googlegroups.com
#21495: Add a setting for CSRF Header name
-------------------------------+-----------------------------------
Reporter: hello@… | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: 1.6
Severity: Normal | Keywords: csrf,header,angularjs
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------+-----------------------------------
CSRF includes a few customizations in settings:
https://github.com/django/django/blob/master/django/conf/global_settings.py#L544
but neglects allowing the user to set the Header name used by the server.

It would be very helpful to have this setting to use with AngularJS. While
AngularJS allows overriding the cookie and header name, it would be better
for my workflow (and I'm sure others) to set this on the server side and
then AngularJS's CSRF functionality will "just work".

Details on the AngularJS CSRF workings:
http://docs.angularjs.org/api/ng.$http § Cross Site Request Forgery (XSRF)
Protection

Pull request:
https://github.com/django/django/pull/1958

--
Ticket URL: <https://code.djangoproject.com/ticket/21495>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 23, 2013, 6:09:59 AM11/23/13
to django-...@googlegroups.com
#21495: Add a setting for CSRF Header name
-------------------------------------+-------------------------------------

Reporter: hello@… | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
csrf,header,angularjs | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by zerok):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

Since also the cookie name is also configurable it definitely makes sense
to also make the header name configurable since it might be used from the
Django-context. The same is not necessarily true for the name of the form-
field so keeping this one hard-coded is IMO valid.

--
Ticket URL: <https://code.djangoproject.com/ticket/21495#comment:1>

Django

unread,
Nov 24, 2013, 8:55:14 PM11/24/13
to django-...@googlegroups.com
#21495: Add a setting for CSRF Header name
-------------------------------------+-------------------------------------

Reporter: hello@… | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
csrf,header,angularjs | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------

Comment (by susan):

I made a separate PR that addresses other people's suggestions here:
https://github.com/django/django/pull/1989 Feel free to code review; I'm
unsure what test(s) to add.

--
Ticket URL: <https://code.djangoproject.com/ticket/21495#comment:2>

Django

unread,
Nov 24, 2013, 8:55:14 PM11/24/13
to django-...@googlegroups.com
#21495: Add a setting for CSRF Header name
-------------------------------------+-------------------------------------

Reporter: hello@… | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
csrf,header,angularjs | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------

Comment (by susan):

I made a separate PR that addresses other people's suggestions here:
https://github.com/django/django/pull/1989 Feel free to code review; I'm
unsure what test(s) to add.

--
Ticket URL: <https://code.djangoproject.com/ticket/21495#comment:3>

Django

unread,
Nov 25, 2013, 2:19:07 PM11/25/13
to django-...@googlegroups.com
#21495: Add a setting for CSRF Header name
-------------------------------------+-------------------------------------

Reporter: hello@… | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
csrf,header,angularjs | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------

Comment (by anonymous):

YAPR (Yet Another PR) with a different interpretation for this change:
https://github.com/django/django/pull/1995

--
Ticket URL: <https://code.djangoproject.com/ticket/21495#comment:4>

Django

unread,
Nov 25, 2013, 7:25:06 PM11/25/13
to django-...@googlegroups.com
#21495: Add a setting for CSRF Header name
-------------------------------------+-------------------------------------

Reporter: hello@… | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
csrf,header,angularjs | Needs documentation: 1

Has patch: 1 | Patch needs improvement: 0
Needs tests: 1 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by unaizalakain):

* needs_docs: 0 => 1
* easy: 1 => 0
* needs_tests: 0 => 1


Comment:

I'm +1 on the last implementation
(https://github.com/django/django/pull/1995) but this needs tests and
docs. I would also propose to the mailing list to follow a deprecation
timeline with the settings moved inside `CsrfViewMiddleware`. I'd be glad
if an issue initially requiring Yet An Other Setting turned out in an
issue removing 6 settings.

--
Ticket URL: <https://code.djangoproject.com/ticket/21495#comment:5>

Django

unread,
Nov 25, 2013, 7:25:59 PM11/25/13
to django-...@googlegroups.com
#21495: Add a setting for CSRF Header name
-------------------------------------+-------------------------------------

Reporter: hello@… | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
csrf,header,angularjs | Needs documentation: 1
Has patch: 1 | Patch needs improvement: 0
Needs tests: 1 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by unaizalakain):

* cc: unai@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/21495#comment:6>

Django

unread,
Nov 25, 2013, 7:46:01 PM11/25/13
to django-...@googlegroups.com
#21495: Add a setting for CSRF Header name
-------------------------------------+-------------------------------------

Reporter: hello@… | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
csrf,header,angularjs | Needs documentation: 1
Has patch: 1 | Patch needs improvement: 0
Needs tests: 1 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by WesAlvaro):

Sure. If we're good on the idea, I'll create tests and mail the list. I
much prefer the idea of configuring the middleware vs adding settings!

--
Ticket URL: <https://code.djangoproject.com/ticket/21495#comment:7>

Django

unread,
Aug 1, 2014, 8:27:31 AM8/1/14
to django-...@googlegroups.com
#21495: Add a setting for CSRF Header name
-------------------------------------+-------------------------------------

Reporter: hello@… | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
csrf,header,angularjs | Needs documentation: 1
Has patch: 1 | Patch needs improvement: 0
Needs tests: 1 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by timo):

As I noted on the [https://groups.google.com/d/topic/django-
developers/8bqbJ_6YArc/discussion mailing list thread]: "The main problem
I see with this approach is that it would no longer be straightforward for
3rd party code to access these settings. You'd need something akin to
get_user_model() to retrieve the currently installed CSRF middleware so
you could access its settings."

--
Ticket URL: <https://code.djangoproject.com/ticket/21495#comment:8>

Django

unread,
Aug 4, 2014, 3:53:57 PM8/4/14
to django-...@googlegroups.com
#21495: Add a setting for CSRF Header name
-------------------------------------+-------------------------------------

Reporter: hello@… | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
csrf,header,angularjs | Needs documentation: 1
Has patch: 1 | Patch needs improvement: 0
Needs tests: 1 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by anonymous):

Thanks for the comment, I've replied to the thread. An interesting
concern, but one that I don't think we should be accommodating.

--
Ticket URL: <https://code.djangoproject.com/ticket/21495#comment:9>

Django

unread,
Aug 28, 2014, 7:38:40 PM8/28/14
to django-...@googlegroups.com
#21495: Add a setting for CSRF Header name
-------------------------------------+-------------------------------------

Reporter: hello@… | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
csrf,header,angularjs | Needs documentation: 1
Has patch: 1 | Patch needs improvement: 1

Needs tests: 1 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1


Comment:

The idea of moving settings into middleware has been thoroughly rejected
on [https://groups.google.com/d/topic/django-
developers/t8ybImtdnpM/discussion a django-developers thread] discussing
integrating django-secure's middleware. If it can be done in a backwards
compatible way, maybe it would make sense to group the CSRF settings into
a dictionary as suggested in the thread. See #22734 which discusses doing
this for the SMTP & email settings and also has a patch with proof of
concept code.

--
Ticket URL: <https://code.djangoproject.com/ticket/21495#comment:10>

Django

unread,
Dec 3, 2014, 11:50:32 AM12/3/14
to django-...@googlegroups.com
#21495: Add a setting for CSRF Header name
-------------------------------------+-------------------------------------

Reporter: hello@… | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
csrf,header,angularjs | Needs documentation: 1
Has patch: 1 | Patch needs improvement: 1
Needs tests: 1 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by carljm):

Noting here that that mailing list thread also eventually reached a fairly
negative conclusion about the benefits of grouping related settings into
dictionaries. So I think an implementation of this ticket would best just
add a new setting.

--
Ticket URL: <https://code.djangoproject.com/ticket/21495#comment:11>

Django

unread,
Feb 21, 2015, 5:08:51 PM2/21/15
to django-...@googlegroups.com
#21495: Add a setting for CSRF Header name
-------------------------------------+-------------------------------------
Reporter: hello@… | Owner: gregorth
Type: New feature | Status: assigned

Component: HTTP handling | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
csrf,header,angularjs |
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by gregorth):

* status: new => assigned
* needs_better_patch: 1 => 0
* owner: nobody => gregorth


Comment:

created pr here:
https://github.com/django/django/pull/4183

--
Ticket URL: <https://code.djangoproject.com/ticket/21495#comment:12>

Django

unread,
Feb 21, 2015, 6:02:49 PM2/21/15
to django-...@googlegroups.com
#21495: Add a setting for CSRF Header name
-------------------------------------+-------------------------------------
Reporter: hello@… | Owner: gregorth
Type: New feature | Status: assigned
Component: CSRF | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
csrf,header,angularjs |
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* version: 1.6 => master
* component: HTTP handling => CSRF


Comment:

Thanks, but tests and documentation are also required. See our
[https://docs.djangoproject.com/en/dev/internals/contributing/writing-code
/submitting-patches/#patch-review-checklist patch review checklist] for
tips. Please uncheck the appropriate flags on this ticket when that's been
added.

--
Ticket URL: <https://code.djangoproject.com/ticket/21495#comment:13>

Django

unread,
Feb 26, 2015, 4:53:02 PM2/26/15
to django-...@googlegroups.com
#21495: Add a setting for CSRF Header name
-------------------------------------+-------------------------------------
Reporter: hello@… | Owner: gregorth
Type: New feature | Status: assigned
Component: CSRF | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
csrf,header,angularjs |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by gregorth):

* needs_docs: 1 => 0
* needs_tests: 1 => 0


Comment:

pr fixed, tests and documentation added

--
Ticket URL: <https://code.djangoproject.com/ticket/21495#comment:14>

Django

unread,
Mar 2, 2015, 12:15:49 PM3/2/15
to django-...@googlegroups.com
#21495: Add a setting for CSRF Header name
-------------------------------------+-------------------------------------
Reporter: hello@… | Owner: gregorth
Type: New feature | Status: assigned
Component: CSRF | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
csrf,header,angularjs |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1


Comment:

I've added comments for improvement on the PR.

--
Ticket URL: <https://code.djangoproject.com/ticket/21495#comment:15>

Django

unread,
Mar 3, 2015, 3:48:44 PM3/3/15
to django-...@googlegroups.com
#21495: Add a setting for CSRF Header name
-------------------------------------+-------------------------------------
Reporter: hello@… | Owner: gregorth
Type: New feature | Status: assigned
Component: CSRF | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
csrf,header,angularjs |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by gregorth):

* needs_better_patch: 1 => 0


Comment:

improved patch, squashed changes, updated PR

--
Ticket URL: <https://code.djangoproject.com/ticket/21495#comment:16>

Django

unread,
Mar 5, 2015, 3:03:51 PM3/5/15
to django-...@googlegroups.com
#21495: Add a setting for CSRF Header name
-------------------------------------+-------------------------------------
Reporter: hello@… | Owner: gregorth
Type: New feature | Status: closed
Component: CSRF | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
csrf,header,angularjs |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"668d53cd125175eb708cc0af143f47b42cd42153"]:
{{{
#!CommitTicketReference repository=""
revision="668d53cd125175eb708cc0af143f47b42cd42153"
Fixed #21495 -- Added settings.CSRF_HEADER_NAME
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21495#comment:17>

Reply all
Reply to author
Forward
0 new messages