Skip to content

Guard verify_order_and_connection against unknown/inactive ad id - #2

Open
Wired4ncer wants to merge 1 commit into
smallworlnd:mainfrom
Wired4ncer:fix/guard-unknown-ad-id
Open

Guard verify_order_and_connection against unknown/inactive ad id#2
Wired4ncer wants to merge 1 commit into
smallworlnd:mainfrom
Wired4ncer:fix/guard-unknown-ad-id

Conversation

@Wired4ncer

Copy link
Copy Markdown

Another one noticed while reading through the order path. In OrderHandler.verify_order_and_connection (publsp/marketplace/lsp.py), the incoming order's ad id is used to index active_ads.ads directly:

ad = self.active_ads.ads[order.d]

If a client sends an order whose d tag references an ad that isn't in active_ads — expired, never existed, or an arbitrary/malicious value — this raises KeyError inside the fire-and-forget order task, which surfaces as an unhandled exception rather than a clean rejection, and the client gets no response.

Fix

Guard the lookup: if the ad id is unknown/inactive, reject the order cleanly and DM the client an error instead of throwing.

Tests

Adds tests/test_order_handler_unknown_ad.py — sends an order referencing an unknown ad id and asserts the handler rejects it gracefully (no unhandled exception, client informed). Node-free, runs in CI as-is.

Proposals not verdicts — glad to shape the error path / message to your preference.

🤖 Generated with Claude Code

An order can reference an ad id we don't have (typo/unknown), or one that was
just inactivated; before any ad is published active_ads is None. The bare
`self.ad_handler.active_ads.ads[order.d]` raised KeyError/AttributeError, and
because orders run as fire-and-forget asyncio tasks the exception was swallowed
so the client got no response at all. Return an OrderErrorResponse instead.

Adds tests/test_order_handler_unknown_ad.py (no node/relay required).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant