nxtgauge-backend-rust/crates/db/src/models
Ashwin Kumar Sivakumar 3e701f2fe6
Some checks failed
build-and-release / build (ugc-content-creators) (push) Waiting to run
build-and-release / build (users) (push) Waiting to run
build-and-release / build (video-editors) (push) Waiting to run
build-and-release / build (catering-services) (push) Successful in 1m47s
build-and-release / build (companies) (push) Successful in 2m0s
build-and-release / build (cron) (push) Successful in 2m12s
build-and-release / build (customers) (push) Successful in 2m42s
build-and-release / build (gateway) (push) Successful in 1m0s
build-and-release / build (developers) (push) Successful in 1m27s
build-and-release / build (fitness-trainers) (push) Successful in 1m54s
build-and-release / build (employees) (push) Successful in 1m59s
build-and-release / build (job-seekers) (push) Successful in 1m57s
build-and-release / build (makeup-artists) (push) Successful in 1m39s
build-and-release / build (graphic-designers) (push) Has been cancelled
build-and-release / build (payments) (push) Has been cancelled
build-and-release / build (jobs) (push) Has been cancelled
build-and-release / build (social-media-managers) (push) Has been cancelled
build-and-release / build (tutors) (push) Has been cancelled
build-and-release / build (photographers) (push) Has been cancelled
fix: close two real money/spend races (Tracecoin double-credit, unbounded AI overspend)
Asked to review Tracecoin and AI implementation safety. Found and fixed
two exploitable TOCTOU races, plus a data-integrity bug:

1. apps/payments/src/main.rs::verify_payment — the PayU success callback
   is called directly by the client (not a server-to-server webhook), so
   a user fully controls how many times they replay a valid success
   payload. The payment "is it still PENDING" check and the "mark
   SUCCESS + credit wallet" write were separate, non-transactional
   queries — concurrent replays could both pass the check before either
   commits, double- (or N-times-) crediting the wallet for one real
   payment. Now wrapped in a single transaction with
   `SELECT ... FOR UPDATE` on the payments row, so a second concurrent
   call blocks until the first commits, then correctly sees the row is
   no longer PENDING (Postgres re-evaluates the WHERE clause via
   EvalPlanQual after the lock is granted).

2. crates/db/src/models/ai/repository.rs — UserAiSubscriptionRepository
   had the exact same shape of bug: apps/users/src/ai/credits.rs::
   charge_feature read the subscription, checked daily-limit and credit
   balance, THEN issued two separate unconditional `UPDATE ... SET x =
   x + $1` statements with no WHERE guard on the balance. N concurrent
   requests from one user all pass the check before any deduction
   lands, running up unlimited LLM API spend (this endpoint is called
   before/around real LiteLLM calls, so the cost is real). Added
   UserAiSubscriptionRepository::try_charge — a single conditional
   UPDATE that checks the daily limit and credit balance and deducts
   atomically, returning None (mapped to the existing error types) if
   either check fails.

3. apps/cron/src/tasks/auto_apply.rs — daily_actions_used was being
   incremented twice per auto-applied job (once in the credit-deduct
   UPDATE, once more in a second, redundant UPDATE right after) —
   silently halving job seekers' effective daily auto-apply limit.
   Removed the redundant second UPDATE.

Also added non-negative CHECK constraints directly to the live
database (tracecoin_wallets.balance/reserved,
user_ai_subscriptions.daily_actions_used/monthly_credits_used/
purchased_credits_used) as defense in depth — belt-and-suspenders in
case a future code path reintroduces a similar bug.
2026-07-21 05:51:23 +05:30
..
ai fix: close two real money/spend races (Tracecoin double-credit, unbounded AI overspend) 2026-07-21 05:51:23 +05:30
activity_log.rs feat(admin): wire management modules to live backend and add UGC role 2026-04-02 13:09:43 +02:00
ai_credits.rs fix: resolve warnings (partial) 2026-07-06 02:55:42 +05:30
application.rs feat: human-readable reference numbers + fix verification document visibility 2026-07-19 16:34:00 +05:30
catering_service.rs feat(db): update service handlers and models for new schema 2026-04-13 00:29:44 +02:00
company.rs feat: auto-approve dummy company accounts 2026-06-12 06:02:20 +05:30
config.rs chore: checkpoint workspace updates 2026-04-26 23:58:43 +02:00
customer.rs feat: update DB schema - split users.first_name, users.last_name, roles split 2026-04-15 06:23:27 +02:00
department.rs chore: checkpoint workspace updates 2026-04-26 23:58:43 +02:00
designation.rs feat(admin): wire management modules to live backend and add UGC role 2026-04-02 13:09:43 +02:00
developer.rs feat(db): update service handlers and models for new schema 2026-04-13 00:29:44 +02:00
employee.rs feat(admin-auth): add POST /api/admin/auth/refresh for sliding session window 2026-07-19 00:14:08 +05:30
fitness_trainer.rs feat(db): update service handlers and models for new schema 2026-04-13 00:29:44 +02:00
graphic_designer.rs feat(db): update service handlers and models for new schema 2026-04-13 00:29:44 +02:00
job.rs fix: convert all SQLx macros to runtime API, remove SQLX_OFFLINE requirement 2026-04-09 07:40:15 +02:00
job_seeker.rs fix: company job posting, job seeker profile submission, and job applications 2026-07-21 01:00:47 +05:30
lead_request.rs feat: human-readable reference numbers + fix verification document visibility 2026-07-19 16:34:00 +05:30
makeup_artist.rs feat(db): update service handlers and models for new schema 2026-04-13 00:29:44 +02:00
mod.rs fix: resolve cherry-pick breakage and add missing modules 2026-07-06 02:23:29 +05:30
onboarding_state.rs fix: convert all SQLx macros to runtime API, remove SQLX_OFFLINE requirement 2026-04-09 07:40:15 +02:00
photographer.rs chore: checkpoint workspace updates 2026-04-26 23:58:43 +02:00
professional.rs fix: portfolio_items/services tables never existed; wallet ledger read used stale column names 2026-07-21 02:21:52 +05:30
requirement.rs feat: profile photo upload, PDF resume generation, AI auto-apply, schema fixes 2026-07-02 13:31:06 +02:00
role.rs fix: convert all SQLx macros to runtime API, remove SQLX_OFFLINE requirement 2026-04-09 07:40:15 +02:00
social_media_manager.rs feat(db): update service handlers and models for new schema 2026-04-13 00:29:44 +02:00
tracecoin_wallet.rs feat: update DB schema - split users.first_name, users.last_name, roles split 2026-04-15 06:23:27 +02:00
tutor.rs feat(db): update service handlers and models for new schema 2026-04-13 00:29:44 +02:00
ugc_content_creator.rs feat(db): update service handlers and models for new schema 2026-04-13 00:29:44 +02:00
user.rs feat: human-readable reference numbers + fix verification document visibility 2026-07-19 16:34:00 +05:30
user_role_profile.rs fix: suppress dead_code warnings with #[allow(dead_code)] 2026-04-18 18:30:56 +02:00
verification.rs feat: human-readable reference numbers + fix verification document visibility 2026-07-19 16:34:00 +05:30
video_editor.rs feat(db): update service handlers and models for new schema 2026-04-13 00:29:44 +02:00