fix(sync-service): redact internal exception details from 500 responses#4556
Merged
Conversation
Uncaught errors in ServeShapePlug previously serialized the full Elixir stacktrace via Exception.format/2 into the 500 response body, exposing internal module paths, library versions, and partial query text to any caller. The catch-all error clause now returns a generic "Internal server error" message; full detail is still captured server-side via OpenTelemetry.record_exception/3 and the error.type span attribute. GHSA-p869-vmqw-939q Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4556 +/- ##
==========================================
- Coverage 56.94% 56.73% -0.21%
==========================================
Files 376 361 -15
Lines 40163 39567 -596
Branches 11128 11127 -1
==========================================
- Hits 22869 22448 -421
+ Misses 17223 17048 -175
Partials 71 71
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
alco
approved these changes
Jun 11, 2026
Contributor
|
This PR has been released! 🚀 The following packages include changes from this PR:
Thanks for contributing to Electric! |
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
Uncaught exceptions in the shape-serving plug no longer leak the full Elixir stacktrace to HTTP clients.
Addresses security advisory GHSA-p869-vmqw-939q.
Problem
When an uncaught exception reached the error handler in
ServeShapePlug, the full Elixir stacktrace was serialized viaException.format/2and returned to the HTTP client in the 500 response body. For example:{ "error": "** (Postgrex.Error) ERROR 42601 (syntax_error) at query: SELECT ...\n (electric 1.x.x) lib/electric/shapes/querying.ex:44: Electric.Shapes.Querying.query/3\n (db_connection 2.6.0) lib/db_connection.ex:1855: DBConnection.execute/4" }This exposed internal module paths, function names, line numbers, library versions, and partial database query text to any caller.
Solution
The catch-all
handle_specific_error/3clause inlib/electric/plug/serve_shape_plug.exnow returns a generic"Internal server error"message instead of the formatted exception.No observability is lost: the full detail is still recorded server-side via
OpenTelemetry.record_exception/3inhandle_error/4, and theerror.typespan attribute (assigned from:error_str) is retained. The more specific error clauses (e.g.DBConnection.ConnectionError→"Database is unreachable") already returned static messages and are unchanged.Test Plan
"500 response body redacts internal exception details"raises an exception whose message mimics leaked internals and asserts the 500 body is exactly{"error": "Internal server error"}with noPostgrex/ query text / function name leaking through.serve_shape_plug_test.exssuite passes (51 tests, 0 failures).Generated with Claude Code