> 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

Notizen zu DOM-XSS mit innerHTML und location.search für Labs der PortSwigger Web Security Academy, einschließlich Ausnutzungs-Workflow, Payload-Tests, Burp-Suite-Validierung und Behebungskontext.

### DOM-XSS im 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 mittels `innerHTML`, wodurch JavaScript eingeschleust und ausgeführt werden kann, wenn der Wert aus der URL stammt.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b8aa13280eb3315c3528a9d2f7eb497be0dd6550%2F%7B444963A0-370C-4F85-93C2-2326197EB4F0%7D.png?alt=media" 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**

* Einfacher 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9d9efd80509a8f8ce27bb73dd64d4adfb8d92fc2%2F%7B50C1DB2A-BBDD-44E0-928A-257F04334961%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7b594a4e05aaaf7c0f0ede7df51965c9e9a42931%2F%7B24AED474-87F4-494A-AF22-B2D9ACC0341F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Ladefehler erzwingen, um einen `onerror` Handler auszulösen:/ `<img src=0 onerror=alert("XSS")>` / (Dieser 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="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8c45da08fcdb3080fc6cb4f6629f73c9ec937ec0%2F%7B3A8EB142-F97F-4D96-9104-AFF814B2380C%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
