-
Notifications
You must be signed in to change notification settings - Fork 0
Don't proxy or log malformed requests #8
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -260,13 +260,21 @@ defmodule Network.Rpc do | |
| end | ||
|
|
||
| "dio_traffic" -> | ||
| chain_id = Base16.decode_int(hd(params)) | ||
| chain_id_param = | ||
| case params do | ||
| [] -> throw(:badrequest) | ||
| [nil | _] -> throw(:badrequest) | ||
| [param | _] -> param | ||
| end | ||
|
|
||
| chain_id = Base16.decode_int(chain_id_param) | ||
| peak = RemoteChain.peaknumber(chain_id) | ||
| peak_epoch = RemoteChain.epoch(chain_id, peak) | ||
|
|
||
| epoch = | ||
| case params do | ||
| [_chain_id, epoch] -> Base16.decode_int(epoch) | ||
| [_chain_id, epoch] when epoch != nil -> Base16.decode_int(epoch) | ||
| [_chain_id, _epoch] -> peak_epoch | ||
| [_chain_id] -> peak_epoch | ||
| end | ||
|
Comment on lines
275
to
279
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. |
||
|
|
||
|
|
@@ -302,14 +310,22 @@ defmodule Network.Rpc do | |
| }) | ||
|
|
||
| "dio_tickets" -> | ||
| chain_id = Base16.decode_int(hd(params)) | ||
| chain_id_param = | ||
| case params do | ||
| [] -> throw(:badrequest) | ||
| [nil | _] -> throw(:badrequest) | ||
| [param | _] -> param | ||
| end | ||
|
|
||
| chain_id = Base16.decode_int(chain_id_param) | ||
| peak = RemoteChain.peaknumber(chain_id) | ||
| peak_epoch = RemoteChain.epoch(chain_id, peak) | ||
|
|
||
| epoch = | ||
| case params do | ||
| [_chain_id, epoch] when is_integer(epoch) -> epoch | ||
| [_chain_id, epoch] when is_binary(epoch) -> Base16.decode_int(epoch) | ||
| [_chain_id, epoch] when epoch == nil -> peak_epoch | ||
| [_chain_id] -> peak_epoch | ||
| end | ||
|
Comment on lines
325
to
330
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. Similar to the |
||
|
|
||
|
|
@@ -427,10 +443,34 @@ defmodule Network.Rpc do | |
| end | ||
|
|
||
| defp handle_proxy(method, params, opts) do | ||
| [node | params] = params | ||
| node = Base16.decode(node) | ||
| server = KademliaLight.find_node_object(node) | ||
| case params do | ||
| [] -> | ||
| result(nil, 400) | ||
|
|
||
| [nil | _] -> | ||
| result(nil, 400) | ||
|
|
||
| [node | params] -> | ||
| # Validate that params don't contain nil values for methods that require them | ||
| invalid_params = | ||
| method in ["dio_traffic", "dio_tickets"] and | ||
| params != [] and | ||
| case params do | ||
| [nil | _] -> true | ||
| _ -> false | ||
| end | ||
|
|
||
| if invalid_params do | ||
| result(nil, 400) | ||
| else | ||
| node = Base16.decode(node) | ||
| server = KademliaLight.find_node_object(node) | ||
| handle_proxy_continue(method, params, opts, node, server) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| defp handle_proxy_continue(method, params, opts, node, server) do | ||
| cond do | ||
| method not in [ | ||
| "dio_checkConnectivity", | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic for extracting
chain_id_paramis duplicated in thedio_ticketshandler (lines 313-318). To improve code reuse and maintainability, consider extracting this logic into a private function. For example:You could then call
get_chain_id_param(params)in both places.