Opened 18 years ago

Closed 16 years ago

Last modified 13 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: dev
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: no UI/UX: no

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@…> 18 years ago.
4828-fix-request-access.2.diff (754 bytes ) - added by David Danier <goliath.mailinglist@…> 18 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)

by David Danier <goliath.mailinglist@…>, 18 years ago

comment:1 by Simon G. <dev@…>, 18 years ago

Cc: dev@… added
Triage Stage: UnreviewedAccepted

by David Danier <goliath.mailinglist@…>, 18 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.

comment:2 by mir@…, 17 years ago

Cc: mir@… added

comment:3 by David Danier <goliath.mailinglist@…>, 17 years ago

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 by Gary Wilson, 16 years ago

Resolution: fixed
Status: newclosed

(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 by Gary Wilson, 16 years ago

milestone: 1.0 beta

comment:6 by Jacob, 13 years ago

milestone: 1.0 beta

Milestone 1.0 beta deleted

Note: See TracTickets for help on using tickets.
Back to Top