Guard verify_order_and_connection against unknown/inactive ad id - #2
Open
Wired4ncer wants to merge 1 commit into
Open
Guard verify_order_and_connection against unknown/inactive ad id#2Wired4ncer wants to merge 1 commit into
Wired4ncer wants to merge 1 commit into
Conversation
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>
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.
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 indexactive_ads.adsdirectly:If a client sends an order whose
dtag references an ad that isn't inactive_ads— expired, never existed, or an arbitrary/malicious value — this raisesKeyErrorinside 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