The vulnerability lies in the nicegui library, specifically within the ui.navigate.history.push() and ui.navigate.history.replace() methods. These methods failed to properly sanitize or escape the URL argument before incorporating it into a JavaScript string for execution on the client side. The security patch, identified in commit ae20f775a683fdf8643cb8cbb35d14279b866af6, addresses this flaw. The patch alters the push and replace methods in the History class, which is located in nicegui/functions/navigate.py. The vulnerable implementation directly inserted the raw url string into JavaScript's history.pushState or history.replaceState functions. This allowed an attacker to inject a malicious string, such as \");alert(1);//, as the URL, which would prematurely terminate the JavaScript string and lead to the execution of arbitrary code. The fix applies json.dumps() to the url argument, ensuring that the string is correctly escaped and handled as data rather than executable code, thereby neutralizing the Cross-Site Scripting (XSS) threat. The identified vulnerable functions, History.push and History.replace, are the precise points where the insecure processing of user-controlled input takes place.