Fix(finstripe): validate invoice ownership against vendor_id before transfer#445
Open
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Open
Fix(finstripe): validate invoice ownership against vendor_id before transfer#445Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Conversation
…ransfer Root cause: create_transfer passed caller-supplied vendor_id and invoice_id directly to repo.create_transaction without verifying invoice.vendor_id == vendor_id, allowing cross-vendor invoice pairing. Solution: Fetch invoice before transaction creation; return error dict if invoice is not found or vendor_id does not match invoice.vendor_id. No write occurs on mismatch. Impact: No breaking changes. Matching vendor/invoice pairs unaffected. Early return before any DB write on mismatch — deterministic and zero side-effect. Signed-off-by: JEAN REGIS <240509606@firat.edu.tr>
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.
Closes #351
Summary
create_transferaccepted anyvendor_id/invoice_idcombination without verifying ownership, allowing a caller to pair a high-value invoice from Vendor A with Vendor B's bank account silently misdirecting funds.This patch adds a two-step guard directly before
repo.create_transaction: existence check, then ownership check. No write occurs unless both pass.Problem
A caller (or a prompt-injected agent) could supply:
Result: transfer created, funds misdirected. No error raised.
Root Cause
create_transfernever fetched the invoice record prior to writing the transaction. Without fetching it, there was no surface on which to compareinvoice.vendor_idagainst the caller-suppliedvendor_id. The missing check is a validation gap not a logic error in existing code, but the complete absence of an authorization guard.Solution
Fetch the invoice before the write path. Fail fast with an error dict on either missing invoice or ownership mismatch.
create_transactionis only reached when both checks pass.Why this approach
get_transfernot-found responsescreate_transactioncall signature or downstream logicDiff Scope
finbot/mcp/servers/finstripe/server.pywith db_session()blockNo other files touched. No refactoring. No renames.
Security Impact
Edge Cases
invoice_iddoes not exist{"error": "Invoice X not found"}no writeinvoice.vendor_idisNoneNone != vendor_id→ ownership check fails → rejectedvendor_idvendor_idisNoneor invalidTesting
Before: Cross-vendor call returns a completed transfer dict no error.
After: Cross-vendor call returns
{"error": "Invoice X does not belong to vendor Y"}transaction record never written.Checklist