> 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/reflected-xss-in-a-javascript-string-with-html-encoded-angle-brackets.md).

# HTMLエンコードされた山括弧を含むJavaScript文字列内の反射型XSS

PortSwigger Web Security Academy のラボ向けメモ。HTMLエンコードされた山括弧を含むJavaScript文字列内の反射型XSSに関するもので、攻撃手順、ペイロードのテスト、Burp Suite による検証、および対策 reme

### 山括弧がHTMLエンコードされたJavaScript文字列への反射型XSS

このラボには、検索クエリの追跡機構に反映されるXSS型の脆弱性があります。山括弧（`<` および `>`) はHTMLでエンコードされていますが、反映された値は\*\* JavaScript文字列\*\*の中に挿入されます。目的は、このJS文字列から抜け出して次を呼び出すことです `alert()`.

**観測したコードに関連する部分を抽出**

{% code overflow="wrap" %}

```javascript
var searchTerms = 'hello';
   document.write('<img src="/resources/images/tracker.gif?searchTerms='+encodeURIComponent(searchTerms)+'">');
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d63c624dccd988c20d69f5c1a1c22cd950ab46ff%2F%7BF4D7F7B2-0557-41E0-A2B0-85CCD872B93F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

検索値（`searchTerms`) は次の中で連結されます `document.write` という命令です。JavaScriptで生成されたHTML文字列内にあります。アポストロフィ（`'`) を値に挿入すると、現在のJavaScript文字列を閉じて任意のコードを実行できます。

```javascript
hello'
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a1d42efd972c9f1970689ef4445a2d0836d8d6de%2F%7B4C4E6FD2-56BF-4B1F-A489-67C396363992%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

次の文字列を検索値として送信すると、文字列を閉じて、 `alert(0)` その後に閉じます：

```javascript
hello' ; alert(0);'
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8029beebb7a4c9902dd1bfee11320e7bf6e2a932%2F%7B0F4D322D-7C96-4F38-AC0A-BDA64E513A17%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/reflected-xss-in-a-javascript-string-with-html-encoded-angle-brackets.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.
