-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More complete handling for preventing XSS attacks.
- Loading branch information
Showing
11 changed files
with
116 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<div> | ||
->{{ hello }}<- | ||
<b>{{ hello }}</b> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
->{{ hello }}<- | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
{{ hello }} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import orjson | ||
|
||
from tests.views.message.utils import post_and_get_response | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from django_unicorn.components import UnicornView | ||
from tests.views.message.utils import post_and_get_response | ||
|
||
|
||
class FakeComponent(UnicornView): | ||
template_name = "templates/test_component_variable.html" | ||
|
||
hello = "" | ||
|
||
|
||
class FakeComponentSafe(UnicornView): | ||
template_name = "templates/test_component_variable.html" | ||
|
||
hello = "" | ||
|
||
class Meta: | ||
safe = ("hello",) | ||
|
||
|
||
def test_html_entities_encoded(client): | ||
data = {"hello": "test"} | ||
action_queue = [ | ||
{"payload": {"name": "hello", "value": "<b>test1</b>"}, "type": "syncInput",} | ||
] | ||
response = post_and_get_response( | ||
client, | ||
url="/message/tests.views.test_process_component_request.FakeComponent", | ||
data=data, | ||
action_queue=action_queue, | ||
) | ||
|
||
assert not response["errors"] | ||
assert response["data"].get("hello") == "<b>test1</b>" | ||
assert "<b>test1</b>" in response["dom"] | ||
|
||
|
||
def test_safe_html_entities_not_encoded(client): | ||
data = {"hello": "test"} | ||
action_queue = [ | ||
{"payload": {"name": "hello", "value": "<b>test1</b>"}, "type": "syncInput",} | ||
] | ||
response = post_and_get_response( | ||
client, | ||
url="/message/tests.views.test_process_component_request.FakeComponentSafe", | ||
data=data, | ||
action_queue=action_queue, | ||
) | ||
|
||
assert not response["errors"] | ||
assert response["data"].get("hello") == "<b>test1</b>" | ||
assert "<b>test1</b>" in response["dom"] |