Code

Opened 7 years ago

Closed 6 years ago

Last modified 3 years ago

#3828 closed (fixed)

request.path leads to confusion/errors inside templates and may open XSS attacks

Reported by: David Danier <goliath.mailinglist@…> Owned by: nobody
Component: Template system Version: master
Severity: Keywords: request template
Cc: dev@…, mir@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

django.core.context_processors.request puts the request into the context of templates. As request offers dictionary-access to the provides data (combination of GET and POST) request.XXX is not unambiguous. You can override {{ request.path }} by adding '?path=...' to your URL for example. Other attributes (GET, POST, ..., method, get_full_path or is_secure) can be overwritten the same way, of course.

This has many problems attached:

  • security: request.path is not escaped everywhere, because it is pre-filtered by url-config request.is_secure might be used to display forms only when using a secure connection (WLAN-setting?)
  • errors when using GET, POST, ...: suddenly no dictionary there
  • confusion: different behavior

As request.REQUEST exists the dictionary-access to request could be removed, I think. But to keep API stable I attached a patch that wrapps the request inside templates and will only allow access to the attributes.

Attachments (2)

4828-fix-request-access.diff (851 bytes) - added by David Danier <goliath.mailinglist@…> 7 years ago.
4828-fix-request-access.2.diff (754 bytes) - added by David Danier <goliath.mailinglist@…> 7 years ago.
getitem does not work for methods, as the resolver tries not to call values got by dict-access. Fixed this by using getattr instead.

Download all attachments as: .zip

Change History (8)

Changed 7 years ago by David Danier <goliath.mailinglist@…>

comment:1 Changed 7 years ago by Simon G. <dev@…>

  • Cc dev@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Changed 7 years ago by David Danier <goliath.mailinglist@…>

getitem does not work for methods, as the resolver tries not to call values got by dict-access. Fixed this by using getattr instead.

comment:2 Changed 7 years ago by mir@…

  • Cc mir@… added

comment:3 Changed 6 years ago by David Danier <goliath.mailinglist@…>

Any progress on this issue? It seems like this ticket is accepted but has not been put into SVN for several month now. Are there any problems? Comments missing in the code or anything? If so I will update the patch.

Possible XSS attack probably is gone thanks to autoescaping now. So beeing able to overwrite request.path or request.is_secure inside templates is still possible, but you cannot insert HTML any more.

comment:4 Changed 6 years ago by gwilson

  • Resolution set to fixed
  • Status changed from new to closed

(In [8202]) Fixed #8092, #3828 -- Removed dictionary access for request objects so that GET and POST data doesn't "overwrite" request attributes when used in templates (since dictionary lookup is performed before attribute lookup). This is backwards-incompatible if you were using the request object for dictionary access to the combined GET and POST data, but you should use request.REQUEST for that instead.

comment:5 Changed 6 years ago by gwilson

  • milestone set to 1.0 beta

comment:6 Changed 3 years ago by jacob

  • milestone 1.0 beta deleted

Milestone 1.0 beta deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.