-
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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,9 +443,30 @@ 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 | ||
|
Comment on lines
+451
to
+457
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. |
||
|
|
||
| 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 [ | ||
|
|
||
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.