Skip to content
XSS Write-up Intermediate

From Shodan to Securing Government Systems: BFLA + Stored XSS Write-Up

An unauthenticated API endpoint allowed creating and reading records, and a text field accepted HTML/JavaScript without sanitisation, leading to stored cross-site scripting. When an administrator viewed the records, the script executed in their browser and could steal their authentication token, and a weak Content-Security-Policy did not block it.

eclipsedmarauder Follow

Published on medium.com

While conducting a black-box security assessment, I discovered a publicly exposed API belonging to a Mauritanian government system.

IntelIberia, 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 API endpoints lacked authentication and authorisation checks, and user-supplied input was stored and rendered without sanitisation, while the Content-Security-Policy was configured permissively.

Impact

An unauthenticated attacker could read and create records, and could execute arbitrary JavaScript in an administrator's browser to steal their authentication token and perform actions as the admin; the weak CSP allowed the script to run, and the endpoint also lacked rate limiting, enabling a logical denial of service.

What the attacker needed

Internet access to the exposed API; no authentication required; victim is an administrator who views the records

The fix

The text does not state that the issue was fixed; it should be fixed by enforcing authentication and authorisation on all API endpoints, sanitising or encoding user input before storage and display, and replacing the permissive CSP with a restrictive policy such as script-src 'self' with nonces.

How it was found

  1. Use Shodan to find an exposed JHipster API with an open port and a government-linked certificate.
  2. Check robots.txt for API paths and note that most return 401 but some do not.
  3. Send GET and POST requests to /api/statuts without authentication to read and create records.
  4. Insert HTML/JavaScript into the nom field of a new record.
  5. Wait for an administrator to view the record list, causing the script to run and the token to be stolen.

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.

Some web APIs forget to check who is calling them, so anyone on the internet can read or add data. Here, a text field also accepted code that runs in a browser, so when an admin looked at the data, that code ran on their computer and could steal their login token. A security header called Content-Security-Policy is meant to stop such code, but it was set too loosely to help.

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.