swaps: stop sending whole req exception to client
What changed, and why it matters
This commit changes how Electrum's submarine swap server reports errors back to clients over Nostr. Previously, the server sent the first 100 characters of the actual exception message, which could leak internal details such as file paths, variable names, or other server-side information. Now it only sends the exception type (for example, 'ValueError') with a generic 'Internal Server Error' label. This is a hardening fix that reduces information disclosure but does not by itself stop an attacker from exploiting the underlying bug that caused the exception.
Treat this commit as a minor security hardening improvement. Review whether the underlying exceptions could be triggered by malicious or malformed Nostr messages, and consider adding input validation, rate limiting, and structured server-side logging. If the previous behavior exposed sensitive paths or implementation details, assess whether any of that information was cached or logged by clients.
Security signals we found
Information disclosure reduction: exception message no longer sent to client
Server-side error handling change in a network-facing component (NostrTransport)
No input validation, authentication, or rate-limiting changes present
Commit title and message explicitly describe the behavioral change
Evidence from the diff
In electrum/submarine_swaps.py, the NostrTransport error handler for swap server requests changed the ‘error’ field in JSON error responses from str(e)[:100] to f’Internal Server Error: {str(type(e))}’. This removes the exception message content from the client-visible response, limiting information disclosure. The patch is narrow: it only masks the error text and does not address whatever exception was being raised, nor does it add authentication, rate limiting, or input validation. The change is defensive and aligns with best practice for error handling in networked services.
Changed components
electrum/submarine_swaps.pyNostrTransport error response pathSwap server client-facing error messagesInspect captured patch +1 / −1
diff --git a/electrum/submarine_swaps.py b/electrum/submarine_swaps.py
index 616dae3..5ba8e04 100644
--- a/electrum/submarine_swaps.py
+++ b/electrum/submarine_swaps.py
@@ -1841,7 +1841,7 @@ class NostrTransport(SwapServerTransport):
except Exception as e:
self.logger.exception(f"failed to handle {request=}")
error_response = json.dumps({
- "error": str(e)[:100],
+ "error": f"Internal Server Error: {str(type(e))}",
"reply_to": event_id,
})
await self.taskgroup.spawn(self.send_direct_message(event_pubkey, error_response))
Why this scored 42/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.