Skip to content
XSS Write-up Beginner

Stored Cross-Site Scripting (XSS) in SourceCodester Web-based Ph

The Category Name field in the pharmacy product management system accepts HTML and JavaScript without sanitisation, and the stored value is later rendered without encoding. An attacker with permission to add a category could store a script that runs in the browser of any user who views the category list.

Sourabhthakur Follow

Published on medium.com

During a security review of the SourceCodester Web-based Pharmacy Product Management System v1.0, I identified a Stored Cross-Site Scripting (XSS) vulnerability. This flaw allows an attacker to inject malicious JavaScript code into the application, which is then stored and executed whenever other users access the…

Sourabhthakur, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the Category Name input is stored as-is and rendered into the category list page without output encoding or input validation.

Impact

An attacker could run arbitrary JavaScript in a victim's browser, potentially stealing session cookies or tokens, performing actions as the victim, or redirecting them to another site; if an administrator views the list, the attacker may gain full control of the application.

What the attacker needed

An account allowed to add categories; victim views the category list

The fix

The application should validate and sanitise the category name on the server and encode it on output before rendering, and a Content Security Policy can add defence in depth.

How it was found

  1. Log in as a user allowed to add categories.
  2. Open Category Management and choose Add Category.
  3. Put a script tag in the Category Name field and save.
  4. Return to the Category List page.
  5. The script runs in the browser of anyone viewing the list.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A stored cross-site scripting bug means the website saves whatever a user types and later shows it to other people as part of the page. If the saved text contains a script, the browser of everyone who views that page runs it, as if the site itself had written it. Here the category name is saved and shown back without being made safe.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.