Repository navigation
fix(security): apply cloud tracking quota to /tracking/check - #252
Merged
Merged
Conversation
POST /api/tracking/check enqueued a real (full-brand when no promptId) tracking run after only an ownership check, while POST /api/tracking/analyze-new gated the same kind of run behind the cloud subscription check, the daily on-demand limit and the cooldown. Any authenticated user could therefore use /check to bypass billing and trigger unbounded Cloro/LLM spend. Extract the shared cloud-mode guard into lib/tracking-quota.js (enforceOnDemandTrackingQuota + TrackingQuotaError, preserving the exact 402/429 status codes and bodies) and call it from both /check and /analyze-new. /check's job is now tagged onDemand:true so its runs count toward the daily cap and cooldown like analyze-new's. Self-hosted (isCloud()===false) stays unrestricted. Onboarding is unaffected: cloud onboarding triggers tracking via the internal CRON_SECRET endpoint after payment, and the only /check call in onboarding runs in self-hosted mode where the guard is a no-op.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
POST /api/tracking/checkenqueued a real tracking run (full-brand when nopromptIdis passed) after only an ownership check, whilePOST /api/tracking/analyze-newgated the same kind of run behind three cloud-mode controls: an active/trialing subscription (402), a per-brand daily on-demand cap (429), and a per-brand cooldown (429).So any authenticated user could call
/checkto bypass billing and trigger unbounded Cloro + LLM spend — repeatedly, and even with no active subscription.Change
server/src/lib/tracking-quota.js—enforceOnDemandTrackingQuota(brandId, organizationId)+TrackingQuotaError, preserving the exact402/429status codes and response bodies./checkand/analyze-new(the inline block inanalyze-newis replaced by the helper — single source of truth, no drift)./check's job is now taggedonDemand: trueso its runs count toward the daily cap and cooldown (previously untracked).Why it's safe — no impact on legitimate flows
isCloud() === false): the guard is a no-op — unrestricted, unchanged./analyze-newtoday — unaffected./api/internal/trigger-trackingendpoint (CRON_SECRET) after payment, which this guard does not touch; the org istrialing/activeby then anyway./checkcall in the onboarding flow runs in self-hosted mode only (cloud returns to the subscription step before it), where the guard is a no-op./checkare now blocked consistently — they were already blocked on/analyze-new, so this is the existing policy applied uniformly, not a new restriction.Verification
node --check,eslint,prettierclean on both files.active/trialingpass-through, and that the guard logic is a faithful extraction (identical status codes/bodies).Type of change
fix— security / billing-bypass