Fix(finstripe): resolve missing invoice amount validation in create_transfer#463
Open
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Open
Fix(finstripe): resolve missing invoice amount validation in create_transfer#463Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Conversation
…ing transaction Root cause: create_transfer passed invoice_id directly to repo.create_transaction() without ever fetching the Invoice record, allowing arbitrary amounts to bypass validation. Solution: Query Invoice within the db_session block before create_transaction; return an error dict if invoice is not found or amount (rounded to 2dp) does not match. Impact: No breaking changes. Matching amounts pass unchanged. Early return prevents any DB mutation on mismatch. Namespace-scoped query prevents cross-tenant leakage. 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.
Summary
Fixes #335
create_transfercommitted any caller-suppliedamountto the database without evercomparing it against the linked invoice's recorded amount, enabling silent over- and
under-payment.
Problem
Inside
create_finstripe_server, thecreate_transfertool acceptedinvoice_idas a parameter but passed it straight to
repo.create_transaction()with no priorlookup of the
Invoicerecord:Any caller could pass
amount=9999.0against an invoice of1000.0and receive a"status": "completed"transfer. Both directions are exploitable:injected via
MCPServerConfig.tool_overrides_jsonRoot Cause
invoice_idwas used solely as a foreign-key reference for the transaction record.The
Invoicerow was never queried, so no business-rule enforcement on amountwas possible. This is a validation gap at the service boundary the tool accepted
untrusted input and wrote it to the database without asserting a known invariant.
Solution
Added two sequential guards inside the existing
with db_session() as db:block,before
repo.create_transaction()is called:Invoicefiltered by bothidandsession_context.namespace(prevents cross-tenant leakage); return an error dictif not found.
round(amount, 2)againstround(invoice.amount, 2)to absorb floating-point representation noise atcent-level precision; return an error dict on mismatch.
The happy path matching amounts is completely unaffected. The return shape
of
{"error": str}is consistent with the existing pattern used inget_transfer.Impact
create_transferfunction bodyTesting
Tasks
Invoicerecord never fetched beforecreate_transaction()callfrom finbot.core.data.models import Invoiceimportget_transfertest_mcp_float_007passes with fix appliedtest_mcp_create_transfer_001continues to pass