-
Notifications
You must be signed in to change notification settings - Fork 42
[ANCHOR-1943]: rpc observer DoS via malformed soroban transfer event #1944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
amandagonsalves
wants to merge
13
commits into
develop
Choose a base branch
from
fix/empty-scvmap-dos
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5573766
test(platform): add test for empty scv_map event
amandagonsalves afbefe2
fix(stellar-observer): handle muxed account creation
amandagonsalves d358bee
refactor(observer): update stellar rpc observer error handling
amandagonsalves b86ec5e
fix(stellar-rpc-observer): add error handling for events
amandagonsalves f58d2a1
refactor(observer): update cursor saving logic
amandagonsalves a1e51f8
fix(stellar): fix parsing malformed contract events
amandagonsalves cec4e25
test(observer): add tests for varied event map values
amandagonsalves 067f834
test(payment-observer): update test assertions and timeout
amandagonsalves 583b3ef
test(stellar-rpc-observer): add poison resilience tests
amandagonsalves 3a4abce
test(payment-observer): update event wait timeout
amandagonsalves 37c5447
refactor(test): update test failure assertion
amandagonsalves 6d6275b
fix(observer): shut down executor service
amandagonsalves 53b8d7c
refactor(tests): update assertion failure mechanism
amandagonsalves File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,6 +82,7 @@ void startInternal() { | |
| @Override | ||
| void shutdownInternal() { | ||
| task.cancel(true); | ||
| executorService.shutdownNow(); | ||
| status = ObserverStatus.SHUTDOWN; | ||
| } | ||
|
|
||
|
|
@@ -123,17 +124,18 @@ void fetchEvents() { | |
| lastActivityTime = Instant.now(); | ||
| silenceTimeoutCount = 0; | ||
| metricLatestBlockRead.set(response.getLatestLedger()); | ||
| if (response.getEvents() != null && !response.getEvents().isEmpty()) { | ||
| processEvents(response.getEvents()); | ||
| } | ||
| // Save the cursor for the next request | ||
| cursor = response.getCursor(); | ||
| try { | ||
| saveCursor(cursor); | ||
| metricLatestBlockProcessed.set(response.getLatestLedger()); | ||
| } catch (Exception tex) { | ||
| warnF("Failed to persist RPC cursor. Will retry next tick. ex={}", tex.getMessage()); | ||
| setStatus(ObserverStatus.DATABASE_ERROR); | ||
| if (response.getEvents() != null && !response.getEvents().isEmpty()) { | ||
| processEvents(response.getEvents()); | ||
| } | ||
| } finally { | ||
| try { | ||
| saveCursor(response.getCursor()); | ||
| metricLatestBlockProcessed.set(response.getLatestLedger()); | ||
|
Comment on lines
+133
to
+134
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need Without this, an operator could still observe slow walks toward self-shutdown that have nothing to do with the malformed-event attack. |
||
| } catch (Exception tex) { | ||
| warnF("Failed to persist RPC cursor. Will retry next tick. ex={}", tex.getMessage()); | ||
| setStatus(ObserverStatus.DATABASE_ERROR); | ||
| } | ||
| } | ||
| } catch (IOException ioex) { | ||
| warnF( | ||
|
|
@@ -153,9 +155,16 @@ private void processEvents(List<EventInfo> events) { | |
| debugF("Processing {} 'transfer' events", events.size()); | ||
|
|
||
| for (EventInfo event : events) { | ||
| ShouldProcessResult result = shouldProcess(event); | ||
| if (result.shouldProcess) { | ||
| processTransferEvent(result); | ||
| try { | ||
| ShouldProcessResult result = shouldProcess(event); | ||
| if (result.shouldProcess) { | ||
| processTransferEvent(result); | ||
| } | ||
| } catch (Exception ex) { | ||
| warnF( | ||
| "Skip event due to unexpected error: {}. ex={}", | ||
| GsonUtils.getInstance().toJson(event), | ||
| ex.toString()); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -219,8 +228,16 @@ private ShouldProcessResult shouldProcess(EventInfo event) { | |
| if (scValue.getDiscriminant() == SCValType.SCV_I128) { | ||
| amount = Scv.fromInt128(scValue).longValue(); | ||
| } else if (scValue.getDiscriminant() == SCValType.SCV_MAP) { | ||
| amount = Scv.fromInt128(scValue.getMap().getSCMap()[0].getVal()).longValue(); | ||
| SCVal memoVal = scValue.getMap().getSCMap()[1].getVal(); | ||
| var entries = scValue.getMap() == null ? null : scValue.getMap().getSCMap(); | ||
| if (entries == null || entries.length < 2) { | ||
| return builder.build(); | ||
| } | ||
| SCVal amountVal = entries[0].getVal(); | ||
| SCVal memoVal = entries[1].getVal(); | ||
| if (amountVal.getDiscriminant() != SCValType.SCV_I128) { | ||
| return builder.build(); | ||
| } | ||
| amount = Scv.fromInt128(amountVal).longValue(); | ||
| eventMemo = | ||
| switch (memoVal.getDiscriminant()) { | ||
| case SCV_STRING -> memoVal.getStr().getSCString().toString(); | ||
|
|
@@ -229,12 +246,17 @@ private ShouldProcessResult shouldProcess(EventInfo event) { | |
| new String(Base64.getEncoder().encode(memoVal.getBytes().getSCBytes())); | ||
| default -> null; | ||
| }; | ||
| if (scValue.getMap().getSCMap()[1].getVal().getDiscriminant() == SCValType.SCV_U64) { | ||
| toAddr = | ||
| new MuxedAccount( | ||
| Scv.fromAddress(to).toString(), | ||
| Scv.fromUint64(scValue.getMap().getSCMap()[1].getVal())) | ||
| .getAddress(); | ||
| if (memoVal.getDiscriminant() == SCValType.SCV_U64) { | ||
| try { | ||
| toAddr = | ||
| new MuxedAccount(Scv.fromAddress(to).toString(), Scv.fromUint64(memoVal)) | ||
| .getAddress(); | ||
| } catch (IllegalArgumentException iae) { | ||
| warnF( | ||
| "Cannot build MuxedAccount for address '{}', using unmuxed value. ex={}", | ||
| toAddr, | ||
| iae.getMessage()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -252,11 +274,9 @@ private ShouldProcessResult shouldProcess(EventInfo event) { | |
| .eventMemo(eventMemo) | ||
| .sep11Asset(asset.getStr().getSCString().toString()) | ||
| .build(); | ||
| } catch (IOException ioex) { | ||
| } catch (Exception ex) { | ||
| warnF( | ||
| "Skip processing event: {}. ex={}", | ||
| GsonUtils.getInstance().toJson(event), | ||
| ioex.getMessage()); | ||
| "Skip processing event: {}. ex={}", GsonUtils.getInstance().toJson(event), ex.toString()); | ||
| return builder.build(); | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.