Django

Code

Ticket #3828 (closed: fixed)

Opened 2 years ago

Last modified 4 months ago

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

Reported by: David Danier <goliath.mailinglist@gmx.de> Assigned to: nobody
Milestone: 1.0 beta Component: Template system
Version: SVN Keywords: request template
Cc: dev@simon.net.nz, mir@noris.net Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

4828-fix-request-access.diff (0.8 kB) - added by David Danier <goliath.mailinglist@gmx.de> on 03/26/07 16:10:25.
4828-fix-request-access.2.diff (0.7 kB) - added by David Danier <goliath.mailinglist@gmx.de> on 03/27/07 02:50:54.
getitem does not work for methods, as the resolver tries not to call values got by dict-access. Fixed this by using getattr instead.

Change History

03/26/07 16:10:25 changed by David Danier <goliath.mailinglist@gmx.de>

  • attachment 4828-fix-request-access.diff added.

03/26/07 17:11:50 changed by Simon G. <dev@simon.net.nz>

  • cc set to dev@simon.net.nz.
  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

03/27/07 02:50:54 changed by David Danier <goliath.mailinglist@gmx.de>

  • attachment 4828-fix-request-access.2.diff added.

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

09/05/07 04:26:06 changed by mir@noris.de

  • cc changed from dev@simon.net.nz to dev@simon.net.nz, mir@noris.net.

01/12/08 05:57:18 changed by David Danier <goliath.mailinglist@gmx.de>

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.

08/03/08 14:55:27 changed by gwilson

  • status changed from new to closed.
  • resolution set to fixed.

(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.

08/03/08 15:02:30 changed by gwilson

  • milestone set to 1.0 beta.

Add/Change #3828 (request.path leads to confusion/errors inside templates and may open XSS attacks)




Change Properties
Action