Files
edx-platform/openedx/core/lib/json_utils.py
Daniel Friedman 09e1f9ed71 Fix XSS vulnerability in User Profile.
TNL-2248
2015-05-26 13:17:54 -04:00

23 lines
533 B
Python

"""
Utilities for dealing with JSON.
"""
import simplejson
from xmodule.modulestore import EdxJSONEncoder
class EscapedEdxJSONEncoder(EdxJSONEncoder):
"""
Class for encoding edx JSON which will be printed inline into HTML
templates.
"""
def encode(self, obj):
"""
Encodes JSON that is safe to be embedded in HTML.
"""
return simplejson.dumps(
simplejson.loads(super(EscapedEdxJSONEncoder, self).encode(obj)),
cls=simplejson.JSONEncoderForHTML
)