/

CVE-2026-30562

Severity:

CRITICAL RISK

(9.3)

XSS in SourceCodester Sales and Inventory System

CVE-2026-30562

Analyzed

Vulnerability type

Category:

Cross-Site Scripting (XSS)

CWE:

CWE-79

Impact:

Client-Side Code Execution / Session Compromise

Severity:

CRITICAL RISK

(9.3)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A reflected Cross-Site Scripting (XSS) vulnerability in SourceCodester Sales and Inventory System 1.0 allows untrusted data from the msg URL parameter to be rendered directly in the browser without proper sanitization or encoding.

By luring a user into visiting a crafted URL, an attacker can inject arbitrary JavaScript or HTML into the application's pages, enabling session theft, credential harvesting, or other browser-based attacks under the victim's context.

Affected context

This vulnerability occurs in the web UI of the SourceCodester Sales and Inventory System 1.0, specifically in add_stock.php, where the msg parameter from the query string is reflected back into the page response.

The issue is relevant when:

  • User-controlled input from the msg parameter is included in the HTML response
  • No output encoding or HTML/JavaScript escaping is applied
  • The page is accessed in a standard web browser with an active authenticated session or sensitive application state

Exploit preconditions

  • Attack surface: HTTP(S) interface of the Sales and Inventory System, particularly requests to add_stock.php.
  • Required access: Ability to send a crafted URL to a victim (e.g., via email, chat, or another web page). The attacker does not need direct access to the server.
  • User interaction: A victim must click or otherwise load the maliciously crafted URL in their browser.
  • Trigger point: The application reflects the msg parameter value into the HTML response without proper sanitization or output encoding.
  • Why exploitation is possible: Untrusted input is inserted into the response in a context where it is interpreted as active HTML/JavaScript, violating output encoding and context separation best practices.

Why this happens

The underlying bug is a classic reflected XSS pattern, mapped to CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').

Specifically, the application:

  • Accepts data from the msg query parameter
  • Directly embeds that data into the HTML response generated by add_stock.php
  • Fails to properly encode or sanitize the content for the specific output context (e.g., HTML body, attribute, or script block)

This allows an attacker to craft msg values containing HTML and script constructs that the browser then executes in the origin of the Sales and Inventory System application.

Potential impact

  • Theft of session identifiers, potentially allowing account hijacking for currently logged-in users
  • Execution of arbitrary JavaScript in the victim's browser within the application origin
  • Unauthorized actions performed on behalf of the victim (e.g., manipulating inventory, changing records) via forged requests
  • Injection of misleading UI elements or phishing forms inside the trusted application page
  • Browser-side exfiltration of sensitive data rendered in the affected page or accessible via same-origin APIs

General mitigation guidance

Effective mitigation typically focuses on robust, context-aware output encoding and strict handling of user-supplied data:

  • Apply output encoding/escaping appropriate for the context (HTML, attribute, JavaScript, URL) before rendering any user-controlled data such as msg.
  • Prefer server-side frameworks or templating engines that automatically escape variables by default, and avoid manually concatenating raw input into HTML.
  • Normalize and validate input to restrict values for parameters like msg to expected formats (e.g., fixed status codes, whitelisted message keys instead of arbitrary free text).
  • Avoid reflecting arbitrary user input in responses; instead, use predefined, server-side messages mapped from safe identifiers.
  • Consider implementing defense-in-depth mechanisms such as a Content Security Policy (CSP) to limit the impact of potential residual XSS bugs.

How teams detect issues like this

Detection efforts can focus on both code-level review and runtime testing:

  • Static analysis: Use rules that flag direct inclusion of $_GET, $_POST, or other superglobal variables in HTML output without passing through an encoding or sanitization function.
  • Code review: Look for echo/print statements or template variables in add_stock.php (and similar files) that incorporate the msg parameter or other user-controlled data without escaping.
  • Security testing: Perform targeted input fuzzing on query parameters; automated scanners can identify reflected XSS by injecting test payloads and analyzing the rendered response.
  • Security policies and CI checks: Enforce guidelines that disallow raw HTML construction with unsanitized input and integrate automated SAST/DAST tools into the development pipeline to surface XSS patterns early.

Sources

SourceLink
github.comgithub.com/meifukun/Web-Security-PoCs/blob/main/Inventory-System/XSS-AddStock-msg.md

Frequently asked

questions

Yes. An attacker can exploit it remotely by crafting a malicious URL containing an XSS payload in the msg parameter and convincing a victim to load that URL in their browser.

The attacker does not need their own authenticated account to trigger the vulnerability, but the impact is greatest when a logged-in user (such as an administrator or staff member) visits the malicious link, because the executed script runs with their session and privileges.

Ensure that any data derived from user input, including the msg parameter, is properly context-encoded before being added to HTML, and avoid reflecting arbitrary free-form text; instead, use server-side mappings from safe identifiers to predefined messages and rely on templating systems that escape output by default.

Adopt a systematic output-encoding strategy across the application, minimize direct use of user-controlled data in views, integrate static and dynamic security testing into the development lifecycle, and apply defense-in-depth controls such as CSP and rigorous coding standards for handling untrusted input.

Find out what's already
exploitable in your codebase.