Stored XSS via Exif Data
The target site stored uploaded images without stripping their Exif metadata, so a crafted comment tag containing script was saved and later rendered. Anyone viewing the attacker's profile would have the script run in their browser, which the author says could hijack a session and take over an account.
Published on medium.com
{{media:0}}
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.
Context
The target was a website with a photo upload feature for user profiles. The researcher's interest was the Exif metadata attached to uploaded images: the server was not stripping it, so whatever was written into the image's tags survived the upload and was served back with the image.
On its own, Exif data exposure is rated low. The researcher notes that Bugcrowd's VRT places it at P4, and at P3 in some cases. The idea behind this write-up is to take that low-rated exposure and turn it into something more severe by putting an XSS payload into the metadata, so that the stored Exif data becomes stored Cross-Site Scripting.
Setup
The only tool named in the report is Exiftool, used to write the payload into the image's Exif tags. The precondition is a feature that accepts image uploads and later serves the image, with its metadata intact, to other users. In this case the upload was a profile photo, and the image was public.
Finding it
The researcher first uploaded a normal image containing Exif data to check for plain Exif data exposure. The site exposed the image URL, so the image could be fetched and its metadata inspected. That confirmed the server was not stripping the tags.
The reasoning about severity is set out explicitly. Exif data exposure is P3 when the data is publicly available, for example in a comment section, and P4 when only a few invited users work on a specific project. XSS has its own categories, of which the report mentions reflected and stored, with stored rated above reflected. Because the Exif data here was public (P3) and the resulting XSS was stored, the researcher expected the severity to move up to P2. Reporting the exposure alone would have stayed at P3.
Exploitation
Step 1: confirm the upload and the exposure
The target had an option to upload photos for the profile. A normal Exif image was uploaded first, purely to test for Exif data exposure. The image URL was then copied and the Exif data checked.
Step 2: write the payload into the image
The XSS payload was inserted as Exif data into the image with Exiftool. The payload, exactly as given in the report, is:
xss%27);}}});alert(document.cookie);$(function+a(){a();});$(function+a(){if(a){}else+if(a){/*///
This is the value placed in the image's Comment tag, which the report also calls the UserComment tag or ImageDescription tag. The report gives the payload without explaining how it is constructed. The exact context the payload was designed to escape is not described in the report.
Step 3: upload and trigger
The modified image was uploaded to the website. The XSS fired: the report describes getting the XSS popup. Because the image is stored on the profile and is public, anyone who visits the researcher's profile gets the XSS.
Root cause
The researcher's explanation is that image processing libraries handle an image's metadata, including its Exif tags. In this case the Exif/DCF reader that processed the tags did not sanitise them on upload. The library should either have removed the Exif data entirely, or scanned the tags and converted the XSS payload into HTML entities. Because the tags were not sanitised, the payload executed.
Impact
The report states that the XSS can allow an attacker to hijack a user's session and take over the account. Because the payload is stored and the image is public, the researcher considers it more severe than a reflected case.
Fix
The recommendation is to always strip the Exif metadata from uploaded images. If stripping is not wanted, there should be a validation check on the metadata that detects a malicious payload in the Exif data and removes it. The report does not say what the site actually changed.
Variants to test
- Upload an image with a payload in the Comment/UserComment tag and check whether the tag value is rendered unescaped anywhere the image is displayed. A positive result is script execution in the viewer's browser.
- Try the same in other Exif tags that a reader might surface, such as ImageDescription. A positive result is the same execution from a different tag.
- Check whether the image URL itself serves the metadata back and whether any page renders it. A positive result is the payload appearing as live markup rather than text.
- Test uploads in less public places, such as a project visible only to invited users, to see whether the stored payload still fires for those viewers. A positive result is execution for a restricted audience, which changes the severity rating.
- Chain the exposure with other features that display image metadata, such as comment sections, and confirm whether the payload executes there. A positive result is stored XSS in a public context.
What happened, in plain words
A security researcher found a website where people could upload a profile photo. Photos taken by phones or digital cameras often carry a small block of hidden notes inside the file, such as the date, the camera model or a comment. That block of notes is called Exif data. The website kept those notes and showed the photo back to other visitors without cleaning them first.
On its own, leaving those notes in place is a minor problem, rated P4 and in some cases P3. The researcher's idea was to make the problem much bigger. Instead of a harmless comment, he wrote a piece of JavaScript code into the notes. JavaScript is the programming language that runs inside a web page in your browser. If a browser is ever told to run code that an attacker wrote, that is called Cross-Site Scripting, or XSS. When the malicious code is saved on the server and shown to every visitor, it is called stored XSS. That is what happened here: the code was saved inside the image, the image was public on the profile, and the code ran for visitors to the profile.

The image above is the author's avatar on the platform where the write-up was published.
Why the researcher bothered with a low-rated bug
Bug bounty platforms pay and rank findings using a scale. The report refers to Bugcrowd's VRT, the Vulnerability Rating Taxonomy: a public list that maps each kind of bug to a priority level, from P1 (most serious) down to P5 (least). Exif data exposure sits at P4, and at P3 in some cases.
So the researcher looked for a way to raise the rating. The report explains the reasoning in its own terms:
- Exif data exposure is P3 when the data is publicly available, for example in a comment section.
- It is P4 when only a few invited users work on a specific project.
- XSS has its own categories. The report mentions two: reflected (the code bounces straight back from a link you clicked and only affects you) and stored (the code is saved on the server and affects everyone who views the page). Stored is rated above reflected.
In this case the Exif data was public, so the exposure alone was P3. By turning it into stored XSS, the researcher expected the severity to move up to P2. Reporting the exposure by itself would have stayed at P3. The lesson he draws is to chain small issues together until they become something more serious.
What Exif data actually is
The report gives the definition: EXIF stands for Exchangeable Image File Format. The information is formatted according to the TIFF specification and can be found in JPG, TIFF, PNG, JP2, PGF, MIFF, HDP, PSP and XCF images, as well as many TIFF-based RAW images and even some AVI and MOV videos.
Think of Exif data as the label on a jar: the jar is the photo, and the label is a set of small fields written next to it. The fields are organised into groups called Image File Directories, or IFDs. One of those groups, the Exif IFD, holds tags specific to Exif. A tag is simply a named field, like "Camera model" or "Date taken".
The report discusses one tag in particular: the Comment tag, also called the UserComment tag or the ImageDescription tag. It exists so that a photographer can write keywords or comments on an image, beyond what fits in ImageDescription, and without the character code limits of that tag. A program that reads Exif data, called an Exif/DCF reader, processes the UserComment tag when it opens the image.
Why the bug existed
In the researcher's opinion, the cause is in the software libraries that process images. A library here means a reusable piece of code that a website uses to handle a job, in this case reading an image and its metadata. Those libraries read the Exif tags, but this one did not sanitise them on upload. Sanitising means cleaning input so that anything dangerous is neutralised before it is used. The library should either have removed the Exif data entirely, or scanned the tags and converted the XSS payload into HTML entities. An HTML entity is a way of writing a character so that the browser displays it as text instead of treating it as code: for example, the less-than sign becomes <. Because neither happened, the tag content reached the page and ran.
How the researcher found it, step by step
- The target website had an option to upload photos for a profile.
- He first uploaded a normal image that contained Exif data, purely to test whether the site exposed it.
- The site gave him the URL of the uploaded image, so he copied it and checked the Exif data. A URL is the address of a page or file on the web, the thing you type in the address bar. Seeing the tags come back confirmed the server was not stripping them.
- He then wrote the XSS payload into the image's Exif data using Exiftool.
- He uploaded the modified image to the website and the XSS fired: the report describes getting the XSS popup.
- Because the image sits on his public profile, anyone who visits the profile gets the XSS.
The tool: Exiftool
The only tool named in the report is Exiftool. It is a free command-line program that reads and writes the metadata inside image files. Think of it as a label printer for the jar: it lets you type whatever you want into the hidden fields of a photo. The report does not show the exact command used, only that Exiftool was used to insert the payload.
The payload
The value placed in the Comment tag, exactly as given in the report, is:
xss%27);}}});alert(document.cookie);$(function+a(){a();});$(function+a(){if(a){}else+if(a){/*///
Line by line, in plain words:
%27is the URL-encoded form of a single quote character ('). Encoding is a way of writing a character using only safe characters, so it survives being passed around the web. A single quote matters because JavaScript code is often wrapped in quotes, and a stray quote can end the string early and let the rest of the text be treated as code.alert(document.cookie)is the actual attack.alertis a built-in browser function that shows a popup box.document.cookieis the browser's way of reading the cookies for the current page. A cookie is a small piece of data a website stores in your browser, often used to remember that you are logged in. Showing it in a popup proves the attacker can read it.- The final
/*opens a JavaScript comment, so that whatever text follows in the page is ignored by the browser instead of causing an error. The trailing///continues that comment.
The report does not describe the exact context the payload was designed to escape, so we cannot say precisely which piece of code on the page it was breaking out of.
Uploading and triggering
The modified image was uploaded to the website. The XSS fired: the report describes getting the XSS popup. Because the image is stored on the profile and the profile is public, whoever visits the profile gets the XSS. That is the difference between stored and reflected: a reflected payload only affects the person who clicks a crafted link, while a stored payload waits on the server and hits everyone who views the page.
Impact
The report states that the XSS can allow an attacker to hijack a user's session and take over the account. Session hijacking means stealing the cookie that proves you are logged in, and using it to act as you. Because the payload is stored and the image is public, the researcher considers it more severe than a reflected case.
Fix
The recommendation is to always strip the Exif metadata from uploaded images. If stripping is not wanted, there should be a validation check on the metadata that detects a malicious payload in the Exif data and removes it.
Variants to test
- Upload an image with a payload in the Comment/UserComment tag and check whether the tag value is rendered unescaped anywhere the image is displayed. A positive result is script execution in the viewer's browser.
- Try the same in other Exif tags that a reader might surface, such as ImageDescription. A positive result is the same execution from a different tag.
- Check whether the image URL itself serves the metadata back and whether any page renders it. A positive result is the payload appearing as live markup rather than text.
- Test uploads in less public places, such as a project visible only to invited users, to see whether the stored payload still fires for those viewers. A positive result is execution for a restricted audience, which changes the severity rating.
- Chain the exposure with other features that display image metadata, such as comment sections, and confirm whether the payload executes there. A positive result is stored XSS in a public context.
Glossary
- Exif data: hidden notes stored inside an image file, such as camera model, date taken and comments.
- Exchangeable Image File Format (EXIF): the standard that defines those notes and how they are stored.
- TIFF: an image file format; Exif information is formatted according to its specification.
- Image File Directory (IFD): a group of related Exif tags inside an image.
- Tag: a named field in Exif data, such as Comment or ImageDescription.
- Comment / UserComment / ImageDescription tag: the Exif field used to store a photographer's comment on an image.
- Exif/DCF reader: software that reads Exif data from an image.
- Cross-Site Scripting (XSS): a bug where an attacker's JavaScript runs in another user's browser.
- Stored XSS: XSS where the malicious code is saved on the server and shown to every visitor of a page.
- Reflected XSS: XSS where the malicious code comes back from a link the victim clicks and only affects that victim.
- JavaScript: the programming language that runs inside web pages in the browser.
- jQuery: a JavaScript library that simplifies working with page elements;
$is its shorthand. - Payload: the piece of code or data an attacker uses to trigger a bug.
- Sanitise: clean input so that anything dangerous is neutralised before use.
- HTML entity: an encoded way of writing a character so the browser shows it as text rather than code.
- URL: the address of a page or file on the web.
- Cookie: a small piece of data a website stores in your browser, often used to keep you logged in.
- Session hijacking: stealing a logged-in user's cookie and using it to act as that user.
- Bugcrowd VRT: a public taxonomy that maps each kind of vulnerability to a priority level.
- P1 to P5: priority levels used by bug bounty platforms, P1 being the most serious.
- Exiftool: a command-line program for reading and writing metadata in image files.
- Library: reusable code a website uses to perform a task, such as reading images.
- Bug bounty: a programme where a company rewards people for reporting security bugs.
- Chaining: combining several small issues so that together they become more serious.