# 17) Reflected XSS in canonical link tag

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FOC8aoKfZbNYSrVmPVzEk%2Fimage.png?alt=media&#x26;token=e8616cc6-80aa-4486-81a8-583e87888120" alt=""><figcaption></figcaption></figure></div>

this lab demonstrates how its possible to have a cross site scripting attack vector on an element that is not visible to the user

for exemple head tag elements are not displayed on the page so if we manage to put an onclick listener on this element the user doesn't see this element no the page to click on it

#### Locate possible injection points

As usual the first step is to analyse the application, we don't have a search functionnality. opening the devtools we find the url is reflected in a head link tag

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FlGjc0T8094DfvrCmcL4d%2Fimage.png?alt=media&#x26;token=7ff53a1c-31bd-4f28-bf22-7987a8eef0e9" alt=""><figcaption></figcaption></figure></div>

so we have a link tag that we can inject xss payloads on, so let's try to escape the href attribute and add onclick event

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FeRAW3UZ4onX8YQP17BHJ%2Fimage.png?alt=media&#x26;token=c5b75e27-53d6-42b0-8489-edec6083b1da" alt=""><figcaption></figcaption></figure></div>

let's do some modification

```
https://0a6800df03a9ab0c81ea02ea00ca00d0.web-security-academy.net/?'onclick='alert(1)
```

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FntEcs5nNP0zFoCzgKwJc%2Fimage.png?alt=media&#x26;token=f2227018-84d4-46d7-a06e-eebdc09b7c9c" alt=""><figcaption></figcaption></figure></div>

but how this event is going to be fired if the element is not visible on the page?

yes we can by using **`html accesskeys`**

### <mark style="color:blue;">HTML AccessKeys</mark>&#x20;

is a keyboard shortcut for clicking on a certain element and its functionality depends on the browser and the operating system used, since not all browsers support access keys. access keys are added as an attribute

```
https://0a6800df03a9ab0c81ea02ea00ca00d0.web-security-academy.net/?'accesskey='x'onclick='alert(1)
```

This sets the `X` key as an access key for the whole page. When a user presses the access key, the `alert` function is called.

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FrxFSb7flwukQUq2Nf0gZ%2Fimage.png?alt=media&#x26;token=4f11ec0e-0d64-4b4d-8056-ac45b8e11144" alt=""><figcaption></figcaption></figure></div>

To trigger the exploit on yourself, press one of the following key combinations:

* On Windows: `ALT+SHIFT+X`
* On MacOS: `CTRL+ALT+X`
* On Linux: `Alt+X`

i am using windows so when i click on `ALT+SHIFT+X` the alert is triggered

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FeXX9yxej6lse0fC4pAb5%2Fimage.png?alt=media&#x26;token=1e74568e-4552-4a55-a6c0-e3fa7c4668d9" alt=""><figcaption></figcaption></figure></div>

and the lab is solved

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FDeuvo6I873lfJ3aE4RZO%2Fimage.png?alt=media&#x26;token=982b21d0-c428-470a-b26b-8c3cce3e960a" alt=""><figcaption></figcaption></figure></div>
