This fixes a potential[^1] security vulnerability -- if bot shows errors
from teloxide to the user & for some reason network error happened[^2]
the url of the request would be included in the error. Since TBA
includes bot token in the error this may lead to token leakage.
This commit fixes that issue by removing the token from the urls of
`reqwest::Error`, we try to only replace the token, but if we fail we
remove the whole url.
This can be tested by using a very low timeout value for the http
reqwest client:
```rust
let client = reqwest::Client::builder()
.timeout(std::time::Duration::from_millis(1))
.build()
.unwrap();
let bot = Bot::from_env_with_client(client).auto_send();
// see if the token is redacted when network error (timeout) happens
// while sending common requests
let _ = dbg!(bot.get_me().await);
// see if the token is redacted when network error (timeout) happens
// while downloading files ("path" is unimportant as the timeout is so
// low the request probably won't even be sent)
let _ = dbg!(bot.download_file_stream("path").next().await);
```
For me this gives the following result:
```text
[t.rs:26] bot.get_me().await = Err(
Network(
reqwest::Error {
kind: Request,
url: Url {
scheme: "https",
cannot_be_a_base: false,
username: "",
password: None,
host: Some(
Domain(
"api.telegram.org",
),
),
port: None,
path: "/token:redacted/GetMe",
query: None,
fragment: None,
},
source: TimedOut,
},
),
)
[t.rs:31] bot.download_file_stream("path").next().await = Some(
Err(
reqwest::Error {
kind: Request,
url: Url {
scheme: "https",
cannot_be_a_base: false,
username: "",
password: None,
host: Some(
Domain(
"api.telegram.org",
),
),
port: None,
path: "/file/token:redacted/path",
query: None,
fragment: None,
},
source: TimedOut,
},
),
)
```
Note that this commits parent is `d0be260` and not the current master
the master branch currently contains breaking changes (we'll need to
make a release from this brach directly).
[^1]: Note that there are recorded cases where the token got exposed.
[^2]: Note that this can be theoretically be controlled by the user when
sending/downloading bigger files.
That's not **really** an override, but by adding an inherent methods
we "hide" methods from `Deref<Target = User>`, that allows us to return
non-option types from `me.mention()` and `me.tme_url()` -- bots must
always have usernames.
Note that this is different from the previous `ChatId` (that was renamed
to `Recipient`), since it can't hold @channelusername.
Reason: same as w/ `UserId`
Reason: when user id is just an integer, it's easy to accidentally
use a "random" integer instead of actual user id, typed APIs make code
less prone to some mistakes.
This commit also fixes an issue when a wrong integer type was used for
`user_id` in `Contact`.
Another option that this addition unlocks is adding methods/implementing
foreign trait for `UserId`.