Fix budget-control bypass and enforce strict spend rules - #5
Open
mozluk wants to merge 1 commit into
Open
Conversation
Summary: This PR patches a HIGH-severity vulnerability where transient governance API failures allowed bounded jobs to execute as unbounded, unmetered tasks. It enforces a "fail closed" policy on spend-rule creation and integrates strict, pre-call budget checks into the orchestration engine. Changes: Fail Closed Policy: Updated app/api/jobs/create/route.ts to treat spend-rule creation failures as fatal. The API now rejects job creation and returns a 502 status if sapiomCreateSpendRule fails, preventing the persistence of jobs without budget boundaries. Authoritative Pre-Call Checks: Refactored lib/orchestrator.ts to perform a strict budget check (spendRef.total + cost > job.budget) inside trackAndExecute before invoking any paid tool APIs. Tools are preemptively aborted if their execution would exceed the job's defined limits.
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:
This PR patches a HIGH-severity vulnerability where transient governance API failures allowed bounded jobs to execute as unbounded, unmetered tasks. It enforces a "fail closed" policy on spend-rule creation and integrates strict, pre-call budget checks into the orchestration engine.
Changes:
Fail Closed Policy: Updated app/api/jobs/create/route.ts to treat spend-rule creation failures as fatal. The API now rejects job creation and returns a 502 status if sapiomCreateSpendRule fails, preventing the persistence of jobs without budget boundaries.
Authoritative Pre-Call Checks: Refactored lib/orchestrator.ts to perform a strict budget check (spendRef.total + cost > job.budget) inside trackAndExecute before invoking any paid tool APIs. Tools are preemptively aborted if their execution would exceed the job's defined limits.