Fix(finmail): reject malformed addresses before routing cascade (MCP-FM-ADDR-002)#437
Open
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Open
Fix(finmail): reject malformed addresses before routing cascade (MCP-FM-ADDR-002)#437Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Conversation
Root cause: route_and_deliver performed no format validation; strings without @ passed all identity lookups and fell through to external dead-drop with sent=True. Solution: Add a three-condition @ guard at the top of the per-address loop. Invalid addresses are appended as type=undeliverable and skipped. Impact: No breaking changes. delivery_count already excludes undeliverable. All valid-address paths are untouched. 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 #345
Malformed email addresses those missing
@, starting with@, or ending with@were silentlyaccepted by
route_and_deliver, passed through the entire routing cascade without matching any knowninbox, and were stored as external dead-drop deliveries with
sent: Truereturned to the caller.This gave agents false confirmation of successful delivery for addresses that can never be valid.
Problem
route_and_deliverinfinbot/mcp/servers/finmail/routing.pyaccepts a raw list of address stringsand immediately enters the vendor → admin → internal → user lookup cascade with no prior format check.
A string like
"no-at-sign"will:Vendor.email)get_admin_addressreturnsadmin@<ns>.finbot)_is_internal_addresslooks for@<ns>.finbotsuffix)User.email)inbox_type="external", logged as awarning, and counted as a successful send
The function then returns:
{ "sent": true, "subject": "...", "deliveries": [{ "type": "external", "email": "no-at-sign", "role": "to" }], "delivery_count": 0 }The agent receives
sent: truewith no error, no rejection signal, and no indication the addresswas invalid. The malformed address is persisted to the database.
Root Cause
There is no RFC 5322 / structural format guard anywhere in the routing path. Any non-empty string
is a valid input to the cascade.
Solution
Insert a three-condition
@guard as the first statement inside the per-address loop, beforeany DB query is attempted:
Malformed addresses are recorded as
type: undeliverableand skipped viacontinue.No other code paths are modified.
What I changed
finbot/mcp/servers/finmail/routing.pyDiff footprint: 4 lines added, 0 deleted, 1 file touched.
Edge Cases Covered
"no-at-sign""@" not in email_addrundeliverable"@domain.com"startswith("@")undeliverable"user@"endswith("@")undeliverable""(empty string)"@" not in ""undeliverable"user@domain.com""user@@domain.com"@, no leading/trailingImpact
delivery_countalready excludesundeliverableno aggregation fix neededdeliveries[n].type == "undeliverable"Testing
Failing test this fixes:
Regression guard:
Manual smoke check: