Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
09e1f9ed
Commit
09e1f9ed
authored
May 21, 2015
by
Daniel Friedman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix XSS vulnerability in User Profile.
TNL-2248
parent
2ba5d483
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
2 deletions
+42
-2
lms/templates/student_profile/learner_profile.html
+2
-2
openedx/core/lib/json_utils.py
+22
-0
openedx/core/lib/tests/test_json_utils.py
+18
-0
No files found.
lms/templates/student_profile/learner_profile.html
View file @
09e1f9ed
<
%!
import
json
%
>
<
%!
from
django
.
core
.
urlresolvers
import
reverse
%
>
<
%!
from
django
.
utils
.
translation
import
ugettext
as
_
%
>
<
%!
from
xmodule
.
modulestore
import
EdxJSONEncoder
%
>
<
%!
from
openedx
.
core
.
lib
.
json_utils
import
Escaped
EdxJSONEncoder
%
>
<
%
inherit
file=
"/main.html"
/>
<
%
namespace
name=
'static'
file=
'/static_content.html'
/>
...
...
@@ -39,7 +39,7 @@
<script>
(
function
(
require
)
{
require
([
'js/student_profile/views/learner_profile_factory'
],
function
(
setupLearnerProfile
)
{
var
options
=
$
{
json
.
dumps
(
data
,
cls
=
EdxJSONEncoder
)
};
var
options
=
$
{
json
.
dumps
(
data
,
cls
=
E
scapedE
dxJSONEncoder
)
};
setupLearnerProfile
(
options
);
});
}).
call
(
this
,
require
||
RequireJS
.
require
);
...
...
openedx/core/lib/json_utils.py
0 → 100644
View file @
09e1f9ed
"""
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
)
openedx/core/lib/tests/test_json_utils.py
0 → 100644
View file @
09e1f9ed
"""
Tests for json_utils.py
"""
import
json
from
unittest
import
TestCase
from
openedx.core.lib.json_utils
import
EscapedEdxJSONEncoder
class
TestEscapedEdxJSONEncoder
(
TestCase
):
"""Test the EscapedEdxJSONEncoder class."""
def
test_escapes_forward_slashes
(
self
):
"""Verify that we escape forward slashes with backslashes."""
malicious_json
=
{
'</script><script>alert("hello, ");</script>'
:
'</script><script>alert("world!");</script>'
}
self
.
assertNotIn
(
'</script>'
,
json
.
dumps
(
malicious_json
,
cls
=
EscapedEdxJSONEncoder
)
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment