keep the Referer on the redirect to Zarinpal so StartPay accepts our domain
A test payment on 2026-10-01 stopped at StartPay with "access from this
domain is not allowed". The app opens /api/payment/orders/{id}/pay, which
302s to Zarinpal, and that response carried Django's default
Referrer-Policy: same-origin, so the browser dropped the Referer on the
cross-site hop and Zarinpal could not see tadrisino2.ir. Only this view now
sends strict-origin-when-cross-origin (origin only, no path or query);
every other response keeps same-origin.
Not yet confirmed by a second real attempt in a browser.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -137,6 +137,17 @@ class PaymentRedirectView(APIView):
|
||||
throttle_scope = 'payment_pay'
|
||||
throttle_classes = [ScopedRateThrottle]
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
response = super().dispatch(request, *args, **kwargs)
|
||||
# زرینپال در StartPay از روی Referer میسنجد کاربر از دامنهی ثبتشده
|
||||
# آمده یا نه. پیشفرضِ جنگو `same-origin` است و روی همین ریدایرکتِ
|
||||
# بیندامنهای Referer را حذف میکرد؛ زرینپال میگفت «دسترسی از این
|
||||
# دامنه مجاز نمیباشد» (۲۰۲۶-۱۰-۰۱، پرداختِ آزمایشیِ صاحبِ پروژه).
|
||||
# با این مقدار فقط origin صفحهی فرانت (math.tadrisino2.ir) میرود، نه
|
||||
# مسیر و کوئری. SecurityMiddleware با setdefault این را دست نمیزند.
|
||||
response['Referrer-Policy'] = 'strict-origin-when-cross-origin'
|
||||
return response
|
||||
|
||||
@extend_schema(
|
||||
responses={302: OpenApiTypes.NONE},
|
||||
description='به درگاهِ زرینپال ریدایرکت میکند؛ بدنهی JSON ندارد.',
|
||||
|
||||
Reference in New Issue
Block a user