Skip to content
XSS Write-up Beginner

Getting Paid With Just Picking Color — Bug Bounty

A colour picker field in a hospital dashboard was vulnerable to stored CSS injection because user input was placed into an inline style attribute. An attacker could inject CSS to overlay the page, making the dashboard and appointment colour picker unusable for other hospital users.

Redza Follow

Published on medium.com

Suppppp guysss, this is my first write-up about bug bounty, let me introduce myself, my name is Redza you can call me za, ja, dza, red, or whatever. I’m currently working on Cyber Security Company called Cyber Army Indonesia as Backend Engineer.

rdzsp, 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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

This is a write-up of a finding on a private bug bounty program. The researcher calls the target redacted.com; the company behind it works in healthcare and provides a web application that bridges hospitals and patients, for example online appointments with a doctor at a hospital. The program offers two roles: Patient and Hospital. Researchers are given credentials for both, and the test environment is for testing only: researchers are not permitted to test on the real environment or production. Testing on the Hospital Dashboard is allowed.

The researcher notes that in the real production environment an attacker acting as a user would have to be a patient, because there is no Hospital Account Register page. That is why the first round of testing was done from the Patient role.

The feature at the centre of the finding is a colour picker for the marker of a doctor appointment on the Hospital Dashboard. The chosen colour is saved through a JSON request and later rendered as an inline CSS background-color on the appointment card.

Setup

  • Two roles were available: Patient and Hospital, each with credentials supplied by the program.
  • Testing was restricted to the provided test environment, not production.
  • The researcher worked with Burp Suite, using the HTTP history and the Interceptor.
  • The browser's Inspect Element was used to see how the saved colour was rendered.
  • The researcher also created a Hospital account with limited actions, which could still change the colour of an appointment, to test the effect between accounts.

Finding it

The first pass was on the Patient Dashboard. The researcher focused on PII (Personally Identifiable Information) leakage of other patients through IDOR (Insecure Direct Object Reference), but the endpoint was well handled. XSS was also tried: every input and parameter was injected with payloads, but all tags and quotes were encoded as HTML entities.

Photo by Christian Erfurt on Unsplash From the original on medium.com

Attention then moved to the Hospital Dashboard. The researcher clicked all the buttons and used all the features while watching the HTTP history in Burp Suite, and found nothing. Eventually the colour picker for the marker of a doctor appointment came up. With the Burp Suite Interceptor switched on, clicking the submit button intercepted the following request:

HTTP
POST /hospital/2163/doctor/22/appointment/update
Host: redacted.com
Content-Type: application/json
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Ubuntu/11.04 Chromium/12.0.742.112 Chrome/12.0.742.112 Safari/534.30
Cookie: [redacted]
X-Csrf-Token: [redacted]

{"name": "My Appointment", "color": "#FFFFFF"}

The request updates the appointment of doctor 22 in hospital 2163. It is a JSON body with a name and a color; the colour is a hex value. The request carries a session cookie and an X-Csrf-Token header.

Exploitation

Step 1: probe the colour value

The colour value was changed to #FFFFFF>" and submitted. The response came back 200 OK. The researcher then checked where the injected colour is rendered: on the Hospital Dashboard, the appointment colour of the doctor with id 22 appeared grey. Opening Inspect Element and picking the card of the doctor's appointment showed that the injected >" had been added to the inline CSS with the background-color property. The quotes (") appeared to be encoded to the HTML entity &quotes;, so the tag with the inline CSS looked like this:

HTML
<div style="background-color: #FFFFFF>&quotes;"></div>

The encoding flow could not be bypassed, but the ability to add arbitrary content to the inline CSS still allows stored CSS injection. The researcher doubted this had any impact on other users if it only shows on the Hospital's own user.

Step 2: test across accounts

To check the effect on someone else, a Hospital account with limited actions, but which could still change the colour of an appointment, was created and logged into. The colour picker was then used to inject the following payload, designed to crash the Hospital Dashboard page and the colour picker itself:

CSS
#3fb5ab; position: fixed !important; width: 100% !important; height: 100% !important; top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important; background-color: rgba(0,0,0,1) !important; z-index: -1 !important; cursor: pointer !important;

The inline CSS was then injected with that payload and looked like this:

HTML
<div style="background-color: #3fb5ab; position: fixed !important; width: 100% !important; height: 100% !important; top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important; background-color: rgba(0,0,0,1) !important; z-index: -1 !important; cursor: pointer !important;"></div>

After the submit button was clicked, the colour picker and the Hospital Dashboard crashed with an overlay effect. All the Hospital accounts inside that hospital could not see the appointment or change the colour.

Step 3: what else the injection could do

The researcher notes that this CSS injection could be taken further, for example to steal the CSRF token of other users who view the poisoned inline CSS, using ^ selectors in CSS to enumerate the CSRF token, with reference to an external article on exfiltration via CSS injection. This was not attempted at the time.

Root cause

The colour value from the JSON body ends up in the inline CSS of the appointment card as part of background-color. Quotes appeared to be encoded to an HTML entity, and the researcher could not bypass the encoding, but the value could still add its own CSS properties to the inline style. The quote encoding could not be bypassed, but CSS injection was still possible. The report does not describe any server-side validation of the colour format.

Impact

With a Hospital account that can change the colour of an appointment, an attacker can store CSS that is rendered to other Hospital users who view the appointment. In the demonstrated case, the injected position: fixed overlay with a full-size, opaque background and a negative z-index crashed the colour picker and the Hospital Dashboard, so all Hospital accounts in that hospital could not see the appointment or change the colour. The researcher also points out that the same injection could be used to steal the CSRF token of users who view the poisoned CSS, though this was not carried out. The report does not state any impact on Patient accounts.

Fix

Variants to test

  1. Colour and theme pickers that save a value rendered into an inline style attribute: submit a value with a semicolon followed by extra CSS declarations and check whether the extra properties appear in the rendered element.
  2. Fields whose quotes are encoded but whose other characters are not: try ; and CSS syntax rather than HTML tags, and look for the value being concatenated into a style attribute.
  3. Stored values shown to other users in the same organisation: create a second account with the same permissions and check whether the injected CSS affects that account's view.
  4. CSRF token exfiltration through CSS selectors: if the token appears in the DOM, try attribute selectors with ^ to test character by character, and confirm whether requests are made to an attacker-controlled host.
  5. Layout-breaking payloads such as full-screen fixed overlays: a positive result is the page or a control becoming unusable for other users, as in the overlay above.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 17 min read.

What happened, in plain words

A security researcher was testing a website that hospitals and patients use to book appointments with doctors. The site had a small feature: when a hospital user marks a doctor's appointment on a calendar, they can pick a colour for that marker. The researcher found that the colour you pick is not checked properly. You are supposed to type a colour like #FFFFFF (white), but the site accepts extra text after it, and that extra text is treated as part of the page's styling instructions. By sending a carefully crafted colour, the researcher could make the appointment card cover the whole screen with a black layer, which broke the dashboard for the Hospital accounts in that hospital. This kind of problem is called CSS injection. The report walks through how the researcher found it, what they sent, and what happened.

From the original on medium.com

Who is writing and what the target is

The author introduces himself as Redza, a backend engineer at a company called Cyber Army Indonesia. This is his first bug bounty write-up. He says he has been spending time on Bugcrowd programs, particularly Pinterest, but he is not writing about Pinterest yet because his report there has not been resolved. Instead he writes about a private program, which he calls redacted.com. A private program is a bug bounty program that is not open to the public: only invited researchers can test it, and the details are kept confidential, which is why the real name is hidden.

Photo by Darius Bashar on Unsplash From the original on medium.com

The company behind the program works in healthcare. It provides a web application that connects hospitals with patients, for example letting a patient book an online appointment with a particular doctor at a particular hospital. A web application is simply a program you use through your browser, like an online shop or a webmail. The researcher read some background about the company and then started testing the application.

The two roles and the test environment

The program has two kinds of user account, called roles:

  1. Patient.
  2. Hospital.

The program gives every researcher login details (credentials) for one account of each role. The environment being tested is a test environment, not the real one: the researcher is not allowed to test on the real environment, which the report also calls production. Production is the live system that real hospitals and real patients use; a test environment is a copy set up for experiments, so mistakes there do not affect anyone. Testing on the Hospital Dashboard is allowed. A dashboard is the main screen you see after logging in, where the features for your role are collected.

The researcher makes an important observation about the real world: in production, an attacker who is just a normal user would have to be a patient, because there is no page where you can register a Hospital account. In other words, on the live site, only patients can sign themselves up; hospital accounts are created some other way. That is why the first round of testing was done from the Patient role: it is the role a real attacker could actually get.

The feature at the centre of the finding

The feature is a colour picker for the marker of a doctor appointment on the Hospital Dashboard. When a hospital user creates or edits an appointment, they can choose a colour, and that colour is used to draw the appointment on the dashboard. The chosen colour is saved by sending a request to the server, and later the server sends it back and the browser uses it to colour the appointment card. A card here means the small box on the screen that represents the appointment.

The tools used

The researcher worked with Burp Suite. Burp Suite is a program that sits between your browser and the website and lets you see and change everything that travels between them. Two parts of it are used here:

  • HTTP history: a list of every request the browser has sent and every response it got back, so you can look at them afterwards.
  • Interceptor: a mode where Burp pauses each request before it leaves your computer, so you can read it, edit it, and then let it go.

HTTP is the language browsers and websites use to talk to each other. A request is a message from the browser asking the site to do something; a response is the site's answer. The researcher also used the browser's Inspect Element, a built-in tool that shows the underlying code of the page you are looking at, so you can see exactly how something on screen is built.

The researcher also created a Hospital account with limited actions, which could still change the colour of an appointment, to test the effect between accounts. The point of a second account is to check whether what one user does can affect another user.

Finding it

The first pass was on the Patient Dashboard. The researcher focused on two classic problems:

  • PII leakage through IDOR. PII stands for Personally Identifiable Information: data that identifies a person, such as a name, address or medical detail. IDOR stands for Insecure Direct Object Reference: a website uses a simple identifier, like a number in a URL, to decide which record to show, and does not check whether you are allowed to see that record. If you change the number and see someone else's data, that is an IDOR. A useful comparison is a hotel where the room number on your key card is the only check: if room 305's key also opens room 306, the lock is the problem. Here the endpoint was well handled, meaning the site did check permissions, so no leak was found. An endpoint is a specific address on the server that a request is sent to, like a particular counter in a large office.
  • XSS. Cross Site Scripting is when a site takes something a user typed and puts it into a page in a way that makes the browser run it as code instead of showing it as text. The classic goal is to make the browser run a script written by the attacker. The researcher injected every input and parameter with payloads, but all tags and quotes were encoded as HTML entities. A payload is the piece of text you send to try to trigger a bug. HTML entities are a way of writing special characters so they are displayed as text rather than treated as code: for example, the less-than sign < can be written as &lt;, and the browser shows it as a character instead of starting a tag. Encoding is the general process of converting characters into such a safe form. Because everything was encoded, the XSS attempts did not work.
Photo by Christian Erfurt on Unsplash From the original on medium.com

Attention then moved to the Hospital Dashboard. The researcher clicked all the buttons and used all the features while watching the HTTP history in Burp Suite, and found nothing. This is a normal part of testing: you use the application like a real user and watch what it sends. Eventually the colour picker for the marker of a doctor appointment came up. With the Burp Suite Interceptor switched on, clicking the submit button intercepted the following request:

HTTP
POST /hospital/2163/doctor/22/appointment/update
Host: redacted.com
Content-Type: application/json
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Ubuntu/11.04 Chromium/12.0.742.112 Chrome/12.0.742.112 Safari/534.30
Cookie: [redacted]
X-Csrf-Token: [redacted]

{"name": "My Appointment", "color": "#FFFFFF"}

Line by line, in plain words:

  • POST /hospital/2163/doctor/22/appointment/update is the first line of the request. POST is the method, meaning "I am sending data and asking you to change something". The path says which thing is being changed: the appointment of doctor 22 in hospital 2163. The numbers are identifiers, like row numbers in a spreadsheet.
  • Host: redacted.com says which website the request is for. The real name is hidden.
  • Content-Type: application/json tells the server the body is in JSON format. JSON is a simple text format for structured data, built from names and values in curly braces, like a labelled form.
  • User-Agent: ... describes the browser that sent the request. It is a long string of version details; servers often use it to decide what to send back.
  • Cookie: [redacted] carries the session cookie. A cookie is a small piece of text the site stored in your browser when you logged in, and the browser sends it back with every request so the site knows who you are. Think of it as the wristband you get at an event: it proves you are already inside. The value is hidden here because it would let anyone who has it act as the researcher.
  • X-Csrf-Token: [redacted] carries a CSRF token. CSRF stands for Cross-Site Request Forgery: an attack where another website tricks your browser into sending a request to a site where you are logged in. To prevent it, the site gives your browser a secret value, the token, and expects it back with every state-changing request. A token is a value that is hard to guess and is checked by the server. The value is hidden here for the same reason as the cookie.
  • The blank line separates the headers from the body.
  • {"name": "My Appointment", "color": "#FFFFFF"} is the body: the data being saved. It sets the appointment's name and its colour. #FFFFFF is a hex colour code, a way of writing a colour as six hexadecimal digits; #FFFFFF is white.

So the request updates the appointment of doctor 22 in hospital 2163. It is a JSON body with a name and a color; the colour is a hex value. The request carries a session cookie and an X-Csrf-Token header.

Exploitation

Step 1: probe the colour value

The colour value was changed to #FFFFFF>" and submitted. The idea is simple: if the site puts your colour into the page without checking it, adding a few odd characters may reveal how it is handled. The response came back 200 OK, which is the standard HTTP status code meaning the request succeeded. A status code is a number the server sends back to say how things went; 200 means fine.

The researcher then checked where the injected colour is rendered: on the Hospital Dashboard, the appointment colour of the doctor with id 22 appeared grey. Opening Inspect Element and picking the card of the doctor's appointment showed that the injected >" had been added to the inline CSS with the background-color property. CSS stands for Cascading Style Sheets: the language that describes how a page looks, such as colours, sizes and positions. Inline CSS means style instructions written directly on a single element in the page's code, in a style attribute. A property is one named setting in CSS, such as background-color, and its value is what follows the colon. The quotes (") appeared to be encoded to the HTML entity &quotes;, so the tag with the inline CSS looked like this:

HTML
<div style="background-color: #FFFFFF>&quotes;"></div>

In plain words: the page contains a div, which is a generic box on the page. Its style attribute says the background colour is #FFFFFF, and then the researcher's extra characters follow. The double quote the researcher sent was turned into &quotes;, so it could not close the style attribute early. That is why the encoding flow could not be bypassed: the site neutralises the character that would let you break out of the attribute and write new HTML. But the ability to add arbitrary content to the inline CSS still allows stored CSS injection. Stored means the value is saved on the server and shown again later to anyone who views it, rather than only appearing once in the researcher's own browser. CSS injection means your input ends up being treated as CSS instructions, so you can add style rules the site never intended.

The researcher doubted this had any impact on other users if it only shows on the Hospital's own user. In other words, if the broken styling only ever appears on the screen of the person who typed it, it is not a security problem, just a cosmetic one.

Step 2: test across accounts

To check the effect on someone else, a Hospital account with limited actions, but which could still change the colour of an appointment, was created and logged into. The colour picker was then used to inject the following payload, designed to crash the Hospital Dashboard page and the colour picker itself:

CSS
#3fb5ab; position: fixed !important; width: 100% !important; height: 100% !important; top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important; background-color: rgba(0,0,0,1) !important; z-index: -1 !important; cursor: pointer !important;

Line by line, in plain words:

  • #3fb5ab is a valid hex colour, so the beginning of the value looks normal. The semicolon ; after it is the character CSS uses to end one declaration and start the next. That semicolon is the key: it lets the researcher add new properties after the colour.
  • position: fixed !important makes the element stay in the same place on the screen even when the page scrolls. !important is a CSS marker that tells the browser this rule must win over other rules for the same property.
  • width: 100% !important and height: 100% !important make the element as wide and as tall as its container, so it fills the screen.
  • top: 0, left: 0, right: 0 and bottom: 0 pin the element to all four edges of the screen.
  • background-color: rgba(0,0,0,1) !important paints it black. rgba is a way of writing a colour with red, green, blue and opacity values; 0,0,0 is black and 1 means fully opaque.
  • z-index: -1 !important controls stacking order, meaning which element is drawn on top of which. A negative value pushes this element behind others.
  • cursor: pointer !important changes the mouse cursor to the hand shape, as if the element were clickable.

Together, these declarations create a full-screen black layer. The inline CSS was then injected with that payload and looked like this:

HTML
<div style="background-color: #3fb5ab; position: fixed !important; width: 100% !important; height: 100% !important; top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important; background-color: rgba(0,0,0,1) !important; z-index: -1 !important; cursor: pointer !important;"></div>

In plain words: the site took the whole value and pasted it after background-color: inside the style attribute. The first colour is still there, but the semicolons turn the rest into separate CSS declarations, which the browser obeys. The second background-color overrides the first because it comes later and is marked !important.

After the submit button was clicked, the colour picker and the Hospital Dashboard crashed with an overlay effect. An overlay is a layer drawn on top of the page. All the Hospital accounts inside that hospital could not see the appointment or change the colour. This is the proof that the problem affects other people: the researcher's saved value changed what other users saw.

Step 3: what else the injection could do

The researcher notes that this CSS injection could be taken further, for example to steal the CSRF token of other users who view the poisoned inline CSS, using ^ selectors in CSS to enumerate the CSRF token, with reference to an external article on exfiltration via CSS injection. This was not attempted at the time.

In plain words: CSS has selectors, which are patterns that pick which elements a rule applies to. Some selectors can test whether an attribute starts with certain characters, written with ^. If a secret value such as a CSRF token appears in the page's code, an attacker can write rules that test one character at a time and load a different image or font depending on the result, which leaks the value out to a server the attacker controls. Exfiltration means getting data out of a system. The researcher did not try this, so it is a possibility, not a demonstrated result.

Root cause

The colour value from the JSON body ends up in the inline CSS of the appointment card as part of background-color. Quotes appeared to be encoded to an HTML entity, and the researcher could not bypass the encoding, but the value could still add its own CSS properties to the inline style. The quote encoding could not be bypassed, but CSS injection was still possible. The report does not describe any server-side validation of the colour format. Server-side validation means the server itself checks the value before saving it, rather than trusting the browser to send something sensible.

Impact

With a Hospital account that can change the colour of an appointment, an attacker can store CSS that is rendered to other Hospital users who view the appointment. In the demonstrated case, the injected position: fixed overlay with a full-size, opaque background and a negative z-index crashed the colour picker and the Hospital Dashboard, so all Hospital accounts in that hospital could not see the appointment or change the colour. The researcher also points out that the same injection could be used to steal the CSRF token of users who view the poisoned CSS, though this was not carried out. The report does not state any impact on Patient accounts.

Fix

Variants to test

  1. Colour and theme pickers that save a value rendered into an inline style attribute: submit a value with a semicolon followed by extra CSS declarations and check whether the extra properties appear in the rendered element.
  2. Fields whose quotes are encoded but whose other characters are not: try ; and CSS syntax rather than HTML tags, and look for the value being concatenated into a style attribute.
  3. Stored values shown to other users in the same organisation: create a second account with the same permissions and check whether the injected CSS affects that account's view.
  4. CSRF token exfiltration through CSS selectors: if the token appears in the DOM, try attribute selectors with ^ to test character by character, and confirm whether requests are made to an attacker-controlled host. The DOM is the browser's in-memory model of the page, which is what Inspect Element shows you.
  5. Layout-breaking payloads such as full-screen fixed overlays: a positive result is the page or a control becoming unusable for other users, as in the overlay above.

Timeline

The report ends with a timeline of the submission:

  • 05 Jun 2022: submission submitted.
  • 07 Jun 2022: the program asked for more information about the submission.
  • 13 Jun 2022: submission marked as Triage with P4. Triage is the stage where the program confirms the report is valid and assigns a priority; P4 is the lowest priority level.
  • 13 Jun 2022: submission marked as Unresolved with P4 (Points: 5, $XXX).
  • 27 Aug 2022: submission marked as Resolved.

Glossary

  • API: a defined way for one program to ask another for data or actions, like a service counter with set procedures.
  • Burp Suite: a tool that sits between browser and website so you can view and edit requests and responses.
  • Cookie: a small piece of text a site stores in your browser and gets back with each request, used to recognise you.
  • Credentials: the login details, such as username and password, that let you sign in.
  • CSRF (Cross-Site Request Forgery): an attack where another site tricks your browser into sending a request to a site where you are logged in.
  • CSRF token: a secret value the site expects with state-changing requests, to prove the request came from its own pages.
  • CSS (Cascading Style Sheets): the language that describes how a page looks.
  • CSS injection: getting your input treated as CSS instructions, so you can add style rules the site did not intend.
  • Dashboard: the main screen you see after logging in, collecting the features for your role.
  • DOM: the browser's in-memory model of the page, which Inspect Element shows.
  • Endpoint: a specific address on the server that a request is sent to.
  • Exfiltration: getting data out of a system, often to a server the attacker controls.
  • Hex colour: a colour written as six hexadecimal digits after #, such as #FFFFFF for white.
  • HTML entities: a way of writing special characters so they display as text, such as &lt; for <.
  • HTTP: the language browsers and websites use to exchange requests and responses.
  • HTTP history: Burp Suite's list of every request and response that passed through it.
  • IDOR (Insecure Direct Object Reference): using a simple identifier such as a number to reach a record, without the site checking you are allowed to see it.
  • Inline CSS: style instructions written directly on one element in a style attribute.
  • Inspect Element: a browser tool that shows the code behind what you see on the page.
  • Interceptor: a Burp Suite mode that pauses each request so you can read and edit it before it is sent.
  • JSON: a simple text format for structured data, built from names and values in curly braces.
  • Overlay: a layer drawn on top of the page.
  • Payload: the piece of text you send to try to trigger a bug.
  • PII (Personally Identifiable Information): data that identifies a person, such as a name, address or medical detail.
  • Private program: a bug bounty program open only to invited researchers, with details kept confidential.
  • Production: the live system real users rely on, as opposed to a test environment.
  • Property (CSS): one named setting in CSS, such as background-color, with a value after the colon.
  • Request: a message from the browser asking the site to do something.
  • Response: the site's answer to a request.
  • Role: a kind of user account with its own permissions, here Patient and Hospital.
  • Selector (CSS): a pattern that picks which elements a CSS rule applies to.
  • Server-side validation: the server itself checking a value before saving it, rather than trusting the browser.
  • Session: the period during which the site recognises you as logged in, tracked by a cookie.
  • Status code: a number the server sends back to say how a request went, such as 200 for success.
  • Stored: saved on the server and shown again later to anyone who views it.
  • Test environment: a copy of a system set up for experiments, separate from production.
  • Token: a value that is hard to guess and is checked by the server.
  • Triage: the stage where a program confirms a report is valid and assigns a priority.
  • XSS (Cross Site Scripting): getting a site to put your input into a page in a way that makes the browser run it as code.
  • z-index: the CSS property that controls which element is drawn on top of which.

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.