Repository navigation
fix: resolve cross-tenant data leakage, timezone revenue calculation, and db connection pool - #214
AARUSH-SING wants to merge 2 commits into
Conversation
…connection pool - Scope Redis cache keys by tenant_id to prevent cross-tenant data collisions - Calculate reservation revenue in property local timezone using AT TIME ZONE - Fix DatabasePool asyncpg connection string parsing from settings.database_url - Enforce Decimal ROUND_HALF_UP precision to resolve sub-cent discrepancies - Support slug tenant IDs and dynamic property dropdowns in frontend - Add local redis:7-alpine container in docker-compose.yml
| session_ctx = db_pool.get_session() | ||
| session = await session_ctx.__aenter__() |
There was a problem hiding this comment.
Bug: The call to db_pool.get_session() within an async with block is missing an await. This will always raise a TypeError when the database is available.
Severity: CRITICAL
Suggested Fix
The coroutine returned by db_pool.get_session() must be awaited before it can be used as an async context manager. Change the line async with db_pool.get_session() as session: to async with await db_pool.get_session() as session:. This ensures the session is correctly acquired before use.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: backend/app/services/reservations.py#L43-L44
Potential issue: In `calculate_total_revenue`, the database session is acquired using
`async with db_pool.get_session()`. However, `get_session` is a coroutine and must be
awaited. The current code will raise a `TypeError` whenever the database connection is
successful. This error is caught, causing the function to silently fall back to
returning static mock data instead of querying the database. As a result, the
application will always serve incorrect, hardcoded data for total revenue.
Also affects:
backend/app/services/reservations.py:97~97
Did we get this right? 👍 / 👎 to inform future reviews.
| const slugRegex = /^[a-z0-9_-]+$/i; | ||
| return uuidRegex.test(tenantId) || slugRegex.test(tenantId); |
There was a problem hiding this comment.
Bug: The backend accepts an x-simulated-tenant header without validating it against the authenticated user's tenant, creating a potential cross-tenant access vulnerability.
Severity: HIGH
Suggested Fix
In dashboard.py, remove the fallback logic that reads the tenant ID from the x-simulated-tenant header. The tenant ID should be derived exclusively from the authenticated user's session (current_user.tenant_id) to ensure data is always scoped correctly.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: frontend/src/lib/secureApi.ts#L248-L249
Potential issue: The backend endpoint for the dashboard allows a tenant ID to be
specified via the `x-simulated-tenant` header. This value is used if a `tenant_id` is
not present on the authenticated user object. However, the backend does not validate
that this header-provided ID matches the user's actual tenant, creating a potential
cross-tenant data access vulnerability. An authenticated user without a tenant ID in
their session could potentially access another tenant's data by setting this header.
Also affects:
backend/app/api/v1/dashboard.py:23~25
Did we get this right? 👍 / 👎 to inform future reviews.
📌 Summary
Resolves reported dashboard revenue discrepancies, cross-tenant data leakage, and precision bugs across Client A, Client B, and Finance:
tenant_id(revenue:{tenant_id}:{property_id}) incache.py.AT TIME ZONE p.timezone) inreservations.py. Bookingres-tz-1(2024-02-29 23:30 UTC = 2024-03-01 00:30 Paris time) is now accurately included in March revenue ($2,250.00 / 4 bookings).DecimalandROUND_HALF_UPto two decimal places to fix cent-level rounding errors.database_pool.py, stopping silent fallbacks to static mock data.secureApi.ts,jwtUtils.ts, andDashboard.tsxto validate tenant slugs (tenant-a,tenant-b) and dynamically display each client's properties.🧪 Verification Results
Verified live via
docker-composewith client credentials:tenant-a)prop-001)tenant-b)prop-001)tenant-b)prop-004)📂 Key Files Modified
database_pool.py,cache.py,reservations.py,dashboard.py,login.pysecureApi.ts,jwtUtils.ts,Dashboard.tsx,RevenueSummary.tsxdocker-compose.yml,frontend/Dockerfile,.gitignore