chore(topup): harden direct-open guard and admin toggle defenses

Post-review nits:
* AdminPaymentMethodEdit.tsx: `config.open_url_direct ?? false` when seeding
  state — defends against stale backend rendering (e.g. cache invalidation
  race before migration applies)
* Same file: aria-label now uses the localized `admin.paymentMethods.openUrlDirect`
  translation key instead of hardcoded English
* TopUpAmount.tsx: case-insensitive guard for Telegram deep-link URLs —
  `https://t.me/`, `http://t.me/`, and `tg://` all match regardless of provider
  casing quirks. Lowercase normalization done once before the comparisons.
This commit is contained in:
Fringg
2026-05-13 11:13:33 +03:00
parent aa8bfc9d08
commit 5493c25e5f
2 changed files with 11 additions and 3 deletions

View File

@@ -279,7 +279,14 @@ export default function TopUpAmount() {
// handler (openInvoice / openTelegramLink в setPaymentUrl-ветке).
// Stars уже отбит раньше через starsPaymentMutation, здесь — защита
// на случай CryptoBot и других Telegram-deep-link провайдеров.
if (method?.open_url_direct && !redirectUrl.startsWith('https://t.me/')) {
// toLowerCase для устойчивости к редким провайдерам, которые могут вернуть
// URL в нестандартном регистре. Также покрываем tg:// scheme на всякий случай.
const lowerUrl = redirectUrl.toLowerCase();
const isTelegramDeepLink =
lowerUrl.startsWith('https://t.me/') ||
lowerUrl.startsWith('http://t.me/') ||
lowerUrl.startsWith('tg://');
if (method?.open_url_direct && !isTelegramDeepLink) {
window.location.href = redirectUrl;
return;
}