dwyl / dwyl/auth

Error when client_id is not valid

Open
#152 0 comments 1 reaction 1 assignee Claimed by @SimonLab View on GitHub
bug
Dominant language
Elixir
Stars
141
Forks
8
PR merge metrics
No merged PRs in 30d

Description

While reviewing the authentication process of the application i noticed that if an invalid `auth_client_id` query parameter is used the application will crash, ex: https://dwylauth.herokuapp.com/?auth_client_id=42

![image](https://user-images.githubusercontent.com/6057298/137628203-d77c4bdc-9e35-47aa-a46b-87b746b9a4ac.png)

This is due to the error returns by Field not being caught in the rescue part of the code:
https://github.com/dwyl/auth/blob/3a9d68720c02d2a8bdec33ffd8b70c35a4e5289a/lib/auth/apikey.ex#L46-L56

The `ArgumentError` and `ArithmeticError` are managed but not `MatchError`.

Instead of catching individual errors we can catch them all together:
```
def decode_decrypt(key) do
try do
key |> Base58.decode() |> Fields.AES.decrypt() |> String.to_integer()
rescue
_ -> 0
end
end
```
The app will then able to return a nice error page:
![image](https://user-images.githubusercontent.com/6057298/137628364-0ccb3053-87aa-4e0a-94d5-0f2e78d9fd6f.png)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.