Published Date: December 27, 2024
Package | Affected Versions | Patched Versions | Severity |
---|---|---|---|
📦 tltneon/lgsl (Composer) | < 7.0.0 | 7.0.0 | High |
Description
Summary
A Stored Cross-Site Scripting (XSS) vulnerability exists in the
lgsl
package due to improper sanitation of user input. This flaw allows attackers to inject malicious JavaScript code, which executes when users access specific pages.Details
The issue stems from the
lgsl_query_40
function in lgsl_protocol.php
. This function uses an HTTP crawler to fetch data from a registered game server. If the server responds with a malicious payload on the /info
endpoint, the JavaScript executes when displayed on the lgsl_details.php
page.Vulnerable Code Snippet:
Explanation of the Issue:
- The code attempts to convert URLs in user data into clickable links.
html_entity_decode
decodes HTML entities, which could reintroduce malicious JavaScript.$value
is inserted directly into the table row without proper escaping, enabling XSS injection.
Proof of Concept (PoC)
- A malicious user submits the following payload as part of the server’s response:
- When the page renders, the malicious JavaScript executes, causing an alert box to appear.
Patches & Workarounds
Fix Recommendation
Update to version 7.0.0 or later, where this issue is patched.
If upgrading is not immediately possible:
- Ensure all user-provided data is properly sanitized and escaped before rendering.
- Use
htmlspecialchars
instead ofhtml_entity_decode
. - Avoid direct rendering of untrusted content.
Secure Fixed Example
To prevent XSS, we must sanitize user input properly and avoid rendering raw data directly into HTML.
Changes Made in the Fix:
- Escaped User Input: Used
htmlspecialchars
to prevent HTML and JavaScript execution. - Escaped URLs Properly: Ensured even URL links are sanitized before rendering.
- Double Sanitization Check: Both
$key
and$value
are individually escaped before being inserted into HTML.
Best Practices Moving Forward:
- Always sanitize user input using
htmlspecialchars
or a similar method. - Avoid using
html_entity_decode
on user-provided data. - Validate input on both the client and server sides.
- Use strict Content Security Policies (CSP) to minimize XSS risks.