File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 11from typing import Any , Callable , Union
22from urllib .parse import urlparse
33
4- from .. import background_tasks
4+ from .. import background_tasks , json
55from ..client import Client
66from ..context import context
77from ..element import Element
@@ -89,7 +89,7 @@ def push(self, url: str) -> None:
8989
9090 :param url: relative or absolute URL
9191 """
92- run_javascript (f'history.pushState({{}}, "", " { url } " );' )
92+ run_javascript (f'history.pushState({{}}, "", { json . dumps ( url ) } );' )
9393
9494 def replace (self , url : str ) -> None :
9595 """Replace the current URL in the browser history.
@@ -100,7 +100,7 @@ def replace(self, url: str) -> None:
100100
101101 :param url: relative or absolute URL
102102 """
103- run_javascript (f'history.replaceState({{}}, "", " { url } " );' )
103+ run_javascript (f'history.replaceState({{}}, "", { json . dumps ( url ) } );' )
104104
105105
106106navigate = Navigate ()
Original file line number Diff line number Diff line change @@ -77,3 +77,14 @@ def page():
7777 screen .click ('Send mail' )
7878 screen .wait (0.5 )
7979 assert screen .selenium .execute_script ('return window.__open_calls' ) == [['mailto:test@example.com' , '_self' ]]
80+
81+
82+ def test_xss_via_history_push (screen : Screen ):
83+ @ui .page ('/' )
84+ def page ():
85+ ui .button ('Push' , on_click = lambda : ui .navigate .history .push ('/");console.log("XSS");//' ))
86+
87+ screen .open ('/' )
88+ screen .click ('Push' )
89+ screen .wait (1 )
90+ assert 'XSS' not in screen .render_js_logs ()
You can’t perform that action at this time.
0 commit comments