summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Holtermann <info@markusholtermann.eu>2014-10-04 19:49:58 +0200
committerMarkus Holtermann <info@markusholtermann.eu>2014-10-06 19:11:06 +0200
commit04bd84786d39b8a17620dfb3b354599d8d95417b (patch)
treea8aaabf351d65012afd4f9da8ffb54bfd97378a3
parent6fa9fa91a5fcb228b3c385b35a2018b3821a447a (diff)
Fixed #23602 -- Add comment on get_absolute_url regarding user input
-rw-r--r--docs/ref/models/instances.txt13
1 files changed, 13 insertions, 0 deletions
diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt
index f5147090b4..aa38081074 100644
--- a/docs/ref/models/instances.txt
+++ b/docs/ref/models/instances.txt
@@ -660,6 +660,19 @@ framework </ref/contrib/syndication>`, use ``get_absolute_url()`` when it is
defined. If it makes sense for your model's instances to each have a unique
URL, you should define ``get_absolute_url()``.
+.. warning::
+
+ You should avoid building the URL from un-validated user input, in order to
+ reduce possibilities of link or redirect poisoning::
+
+ def get_absolute_url(self):
+ return '/%s/' % self.name
+
+ If ``self.name`` is ``'/example.com'`` this returns ``'//example.com/'``
+ which, in turn, is a valid schema relative URL but not the expected
+ ``'/%2Fexample.com/'``.
+
+
It's good practice to use ``get_absolute_url()`` in templates, instead of
hard-coding your objects' URLs. For example, this template code is bad: