> 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/ja/web/xss/dom-xss-with-innerhtml-and-location-search.md).

# innerHTML と location.search を用いた DOM XSS

PortSwigger Web Security Academy のラボ向けメモ。innerHTML と location.search を用いた DOM XSS に関するもので、攻撃手順、ペイロードのテスト、Burp Suite による検証、および対策の文脈を含む。

### source location.search を使用した InnerHTML シンクにおける DOM XSS

ブログ検索機能における DOM XSS の脆弱性。コードは次の値を取得します: `location.search` そして、次を介して DOM に直接挿入します: `innerHTML`そのため、値が URL から取得されると JavaScript が挿入され実行されます。

<figure><img src="https://2001299964-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>

**確認されたコードの抜粋**

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

**テストしたペイロード**

* 単純なペイロード（解釈されない）: / `<script>alert("XSS")</script>`
* 画像要素を挿入するテスト:/ `<img src="test"</img>`/（イベント属性がないため、これはスクリプト実行を引き起こしません）

<figure><img src="https://2001299964-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://2001299964-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>

読み込みエラーを強制して次を発生させる `onerror` ハンドラ:/ `<img src=0 onerror=alert("XSS")>` /（このペイロードは次を使用します `onerror` イベント属性を使って実行する `alert` 画像の読み込みに失敗したとき）

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

<figure><img src="https://2001299964-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>

スクリプトは直接影響を与えます `innerHTML` を使って `search` URL の値に; したがって、イベントハンドラを含む HTML フラグメント（例: `onerror`）や実行可能なタグはコード実行につながる可能性があります。 `<img src=0 onerror=alert("XSS")>` このペイロードは読み込みエラーを発生させ、次を実行します `alert("XSS")`、DOM XSS の脆弱性を示しています。


---

# 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/ja/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.
