Escape html tags before save for XSS protection?

23 views
Skip to first unread message

左小龙

unread,
May 26, 2017, 3:36:08 AM5/26/17
to Django REST framework
Before save the instance in database, should DRF add a method to let user escape '<', '>', ''', '"', from codes here https://github.com/encode/django-rest-framework/blob/master/rest_framework/serializers.py#L172

self.instance = self.create(validated_data)
assert self.instance is not None, (
    '`create()` did not return an object instance.'
)

maybe we should add a method like  (from django)

def replace_html(text):
    str(text).replace('&', '&amp;').replace('<', '&lt;')
.replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;')

for XSS protection?
Reply all
Reply to author
Forward
0 new messages