Skip to content
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

Added 0 String Length Check on address_type.ex before decoding. #394

Merged
1 commit merged into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/archethic_web/graphql_schema/address_type.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ defmodule ArchethicWeb.GraphQLSchema.AddressType do

@spec parse_address(Absinthe.Blueprint.Input.String.t()) :: {:ok, binary()} | :error
defp parse_address(%Absinthe.Blueprint.Input.String{value: address}) do
with {:ok, addr} <- Base.decode16(address, case: :mixed),
with true <- String.length(address) > 0,
{:ok, addr} <- Base.decode16(address, case: :mixed),
true <- Crypto.valid_address?(addr) do
{:ok, addr}
else
Expand Down
10 changes: 10 additions & 0 deletions test/archethic_web/graphql_schema_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,16 @@ defmodule ArchethicWeb.GraphQLSchemaTest do
assert Enum.slice(transactions, slice_range)
|> Enum.map(&%{"address" => Base.encode16(&1.address)}) == recv_transactions
end

test "should return error on 0 length address argument", %{conn: conn} do
conn =
post(conn, "/api", %{
"query" => "query { transactionChain(address: \"\") { address } }"
})

%{"errors" => [%{"message" => message}]} = json_response(conn, 200)
assert message |> String.starts_with?("Argument \"address\" has invalid value \"\"")
end
end

describe "query: balance" do
Expand Down