Skip to content

Fix(finstripe): reject zero-and-negative amount transfers with pre-DB guard#432

Open
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M:patch-34
Open

Fix(finstripe): reject zero-and-negative amount transfers with pre-DB guard#432
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M:patch-34

Conversation

@Jean-Regis-M
Copy link
Copy Markdown
Contributor

Summary

Fixes #334

Adds amount <= 0 validation to create_transfer, blocking zero-amount
transactions before any DB write or transfer ID generation occurs.

Problem

create_transfer(amount=0.0, ...) succeeded, creating a completed
transaction record — polluting audit logs with financially meaningless
entries and allowing invoice/vendor ID probing at zero cost.

Root Cause

No amount validation existed in create_transfer. The function
called _generate_transfer_id() and repo.create_transaction()
unconditionally, regardless of amount value.

Solution

Insert a two-line guard at function entry:

if amount <= 0:
    return {"error": f"Invalid amount: {amount}. Amount must be greater than zero."}

Returns before any side-effectful call is made.

Impact

  • No breaking changes
  • Minimal diff (2 lines added)
  • Deterministic behavior
  • Zero regression risk to valid-amount paths

Testing

pytest tests/unit/mcp/test_finstripe.py::TestFloatEdgeCases::test_mcp_float_005_zero_amount_raises -v
pytest tests/unit/mcp/test_finstripe.py::TestFloatEdgeCases::test_mcp_float_001_max_payment_boundary_accepted -v

Root cause:
create_transfer lacked an amount > 0 guard, allowing amount=0.0
to persist a completed transaction record.

Solution:
Added `if amount <= 0` check at function entry, returning an error
dict before _generate_transfer_id() or db_session() are reached.

Impact:
No DB writes on invalid input. Consistent error shape with existing
tool responses. Zero regression risk to valid-amount paths.

Signed-off-by: JEAN REGIS <240509606@firat.edu.tr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug_125_MUST_FIX: Test Case MCP-FLOAT-005: Zero-amount transfer accepted — no minimum amount validation

1 participant