whisper-money/resources/js/hooks
Anshul Nitin 4fdb7eebd9
fix: address remaining security audit findings (round 2) (#628)
## Summary

Follow-up to #623 — addresses security findings **not covered** by the
maintainer's draft PR #627. The original scope was larger; out-of-scope
changes were reverted (see `revert: drop out-of-scope changes from
security round 2`) and are **no longer part of this PR** (details under
_Reverted / not included_).

## Changes

### Rate limiting
- `routes/api.php`: authenticated API group throttled at `300,1` (per
user). An SPA with offline sync + multi-widget dashboards fans out many
requests per interaction, so a tighter cap throttled legitimate bursts.
- `routes/web.php`: unauthenticated open-banking callback throttled at
`30,1` (per IP), enough headroom for browser retries and the iOS PWA →
Safari hand-off that can fire the callback twice.
- `use-decrypt-transactions.ts`: the legacy decrypt migration loops
without backoff (~3 requests per 100 encrypted transactions), so a large
account could hit the API throttle and abort the whole migration
silently. It now honours Laravel's `Retry-After` header on 429 and
retries the same request instead of bailing.

### State token persistence on failure
- `AuthorizationController::callback`: clears `state_token` on the
connection when EnableBanking session creation fails, preventing a stale
token from being replayed.

### Trust proxies hardening
- `bootstrap/app.php`: replaced `trustProxies(at: '*')` with an
env-based `TRUSTED_PROXIES` config. When unset, no proxy is trusted
(Laravel default) instead of trusting every IP.
- ⚠️ **Deploy requirement:** production runs behind a reverse proxy /
TLS terminator (`Dockerfile.production` + nginx serve HTTP on :80). With
`TRUSTED_PROXIES` unset, Laravel stops trusting
`X-Forwarded-For`/`X-Forwarded-Proto` → client IPs collapse to the proxy
IP (contaminating logs and per-IP throttling) and HTTPS detection
breaks. `TRUSTED_PROXIES` **must** be set in the production environment
before merge, and should be added to `.env.production.example`.

### XSS-safe Blade-to-JS injection
- `app.blade.php`: replaced `{{ }}` Blade syntax inside `<script>` with
`@json()` to prevent JS injection via variable content.

### TOCTOU defense-in-depth
- `Api/TransactionController::bulkUpdate`: added `->where('user_id',
$userId)` to the per-row UPDATE as belt-and-suspenders behind the
existing `abort(403)` ownership pre-check.

## Reverted / not included

The following were in the original description but were reverted and are
**not** in the current diff:
- `block-demo` middleware on additional route groups (already present
upstream on `routes/settings.php`).
- `->limit(500)` / `has_more` / `since` validation on
`TransactionSyncController`.

## Notes
- `vite.config.ts` appears in the diff only because of an older
merge-base; it is identical to `main` and nets to no change (will vanish
on rebase).
- No tests yet for the `state_token` clearing on `createSession` failure
or for the throttles — worth adding before merge (the callback throttle
is the most exposed surface).

---------

Co-authored-by: Víctor Falcón <victoor89@gmail.com>
2026-07-03 15:04:03 +00:00
..
use-admin.tsx feat: Add privacy mode to hide monetary amounts (#28) 2025-12-14 16:03:02 +01:00
use-appearance.tsx fix: add SSR guards to localStorage/sessionStorage access 2025-12-08 18:19:20 +01:00
use-cashflow-data.ts feat: expand Sankey subcategories inline (#485) 2026-06-04 10:31:40 +02:00
use-categorize-transactions.ts refactor(encryption): strip client-side transaction encryption (#514) 2026-06-20 16:13:26 +00:00
use-chart-color-scheme.tsx Fix net worth chart config UX and color scheme issues (#250) 2026-03-31 11:19:35 +01:00
use-chart-views.ts fix(dashboard): treat loans as debt in net worth (#238) 2026-03-20 09:55:53 +00:00
use-clipboard.ts Set up a fresh Laravel app 2025-11-07 12:01:36 +00:00
use-connect-flow.ts feat(banking): enable Interactive Brokers for all users (#593) 2026-06-26 11:03:21 +02:00
use-count-up.ts User Onboarding Flow (#23) 2025-12-12 13:06:08 +01:00
use-dashboard-data.test.ts feat(settings): centralize currency options and split profile/account support (#256) 2026-04-02 19:23:10 +02:00
use-dashboard-data.ts feat(dashboard): add accounts manager dialog with visibility toggle and reorder (#604) 2026-06-27 16:11:25 +00:00
use-decrypt-account-names.ts Remove encryption from bank account names (#104) 2026-02-09 14:15:26 +01:00
use-decrypt-transactions.test.tsx refactor(encryption): strip client-side transaction encryption (#514) 2026-06-20 16:13:26 +00:00
use-decrypt-transactions.ts fix: address remaining security audit findings (round 2) (#628) 2026-07-03 15:04:03 +00:00
use-expandable-categories.ts feat: expand parent categories inline in breakdowns (#486) 2026-06-04 11:19:21 +02:00
use-initials.tsx Set up a fresh Laravel app 2025-11-07 12:01:36 +00:00
use-locale.ts feat: Spanish localization (#74) 2026-02-08 11:58:08 +01:00
use-mobile-navigation.ts Set up a fresh Laravel app 2025-11-07 12:01:36 +00:00
use-mobile.tsx fix: make useIsMobile hook and utility functions SSR-safe 2025-12-08 17:33:54 +01:00
use-onboarding-state.test.tsx feat(ai): suggest automation rules during onboarding (#523) 2026-06-13 22:51:15 +02:00
use-onboarding-state.ts feat(ai): suggest automation rules during onboarding (#523) 2026-06-13 22:51:15 +02:00
use-online-status.ts Fix CI: Update bun.lock and fix linting errors 2025-12-01 15:16:06 +01:00
use-poll-job-status.ts feat(ai): manage AI consent outside onboarding with live backfill (#591) 2026-06-25 10:50:35 +02:00
use-pwa-install.ts feat: Show PWA install button on mobile landing page (#99) 2026-02-07 09:33:12 +01:00
use-re-evaluate-all-transactions.tsx fix(security): scope job-status endpoints to owner + feature-area fixes (#627) 2026-07-03 14:49:32 +02:00
use-two-factor-auth.ts Set up a fresh Laravel app 2025-11-07 12:01:36 +00:00
use-web-haptics.test.tsx fix(haptics): use a local WebHaptics wrapper (#225) 2026-03-16 11:26:04 +00:00
use-web-haptics.ts fix(haptics): use a local WebHaptics wrapper (#225) 2026-03-16 11:26:04 +00:00