Step 1: Payload Delivery: An attacker crafts a malicious payload containing JavaScript code (e.g., <script>alert('XSS')</script>) and submits it as a rating item's data, such as the rating's title or description.
Step 2: Data Storage: The vulnerable script fails to sanitize the input. The malicious JavaScript payload is stored in the application's database along with the rating item's other data.
Step 3: User Interaction: A legitimate user views the rating item. The script retrieves the rating item's data, including the attacker's malicious payload, from the database.
Step 4: Payload Execution: The script displays the rating item's data, including the unsanitized JavaScript payload, within the user's browser. The browser interprets the JavaScript code and executes it, triggering the XSS attack. This could involve stealing cookies, redirecting the user, or other malicious actions.