self.assert_(r.last_activity > 0, r.last_activity)
+ def test_XSS(self):
+ """Check that chat is protected against cross-site scripting (by disabling html tags)."""
+
+ response = self.client.post('/jqchat/room_with_description/2/ajax/', {'time': 0,
+ 'action': 'change_description',
+ 'description': '<script>alert("boo!");</script>'})
+ self.assert_(response.status_code == 200, response.status_code)
+ payload = simplejson.loads(response.content)
+ self.assert_(payload['description'] == '<script>alert("boo!");</script>', payload)
+
if self.request.method == "POST":
action = self.request.POST['action']
if action == 'change_description':
- self.ThisRoom.description = self.request.POST['description']
+ # Note that we escape descriptions as a protection against XSS.
+ self.ThisRoom.description = escape(self.request.POST['description'])
self.ThisRoom.save()
Message.objects.create_event(self.request.user, self.ThisRoom, 1)
# Is there a description more recent than the timestamp sent by the client?