Commit graph

129 commits

Author SHA1 Message Date
Maybe Waffle
daec5ee13e Hide bot token in errors
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.
2022-04-03 13:34:17 +04:00
Maybe Waffle
1a61d02858 Release 0.4.4 2022-03-21 19:22:22 +04:00
Maybe Waffle
923be2221d Add NotFound error 2022-03-21 19:10:12 +04:00
Hirrolot
2c0748f3ae
Merge branch 'master' into with_payload 2022-03-20 08:08:52 -07:00
Maybe Waffle
d8e3c6ce42 Add WrongFileIdOrUrl and FailedToGetUrlContent errors 2022-03-18 14:21:55 +04:00
Maybe Waffle
c7e32fa247 Add HasPayload::with_payload_mut function
`HasPayload::with_payload_mut` allows to easily apply multiple changes
to the payload without calling `payload_mut()` multiple times and
creating temporary variable for the request. e.g.:
```rust
// without `with_payload_mut`
{
    let mut req = bot.set_webhook(url.clone());

    req.payload_mut().certificate = certificate.take();
    req.payload_mut().drop_pending_updates = drop_pending_updates;

    req.send().await?;
}

// with `with_payload_mut`
bot
    .set_webhook(url.clone())
    .with_payload_mut(|payload| {
        payload.certificate = certificate.take();
        payload.drop_pending_updates = drop_pending_updates;
    })
    .send()
    .await?
```
2022-03-18 14:13:38 +04:00
Maybe Waffle
11c79499e3 Release 0.4.3 2022-03-07 22:43:24 +04:00
Waffle Maybe
0c5f9678d8
Merge pull request #185 from teloxide/revert_better_timeouts
Revert "better timeouts"
2022-03-07 20:16:53 +04:00
Maybe Waffle
b0607f604a update changelog 2022-03-03 02:23:46 +03:00
Maybe Waffle
cfb48a6fa4 Update changelog 2022-03-03 01:48:09 +03:00
mikhailantoshkin
3c09f32723
Update changelog 2022-02-20 23:17:15 +05:00
Maybe Waffle
1d7825c97a Prepare 0.4.2 release 2022-02-17 15:03:41 +03:00
Maybe Waffle
6bf204221f Deprecate Message::chat_id 2022-02-17 14:51:00 +03:00
Maybe Waffle
3477f7eded Fix sending quiz polls 2022-02-17 14:10:39 +03:00
Maybe Waffle
2dc4a915ba Add a way for long-running requests to increase network timeout 2022-02-14 19:52:43 +03:00
Maybe Waffle
bfb64665a6 Release 0.4.1 2022-02-13 21:08:40 +03:00
Maybe Waffle
fb523f153e Fix deserialization of UntilDate 2022-02-13 20:53:41 +03:00
Maybe Waffle
4f85b8dc03 Dump version (-> 0.4.0) 2022-02-03 17:48:36 +03:00
Maybe Waffle
1ae7544578 Update changelog 2022-02-01 20:22:20 +03:00
Maybe Waffle
a36794c5d3 Make WebhookInfo::allowed_updates typed 2022-02-01 18:30:40 +03:00
Hirrolot
bd4218c238
Merge branch 'master' into input_file_refactor 2022-01-30 20:14:30 +06:00
Maybe Waffle
38f2a5fef2 Make WebhookInfo::ip_address typed 2022-01-27 20:25:40 +03:00
Waffle Maybe
87a0718acb
fix typos in changelog 2022-01-25 15:15:04 +03:00
Maybe Waffle
f13732cbb5 Update readme 2022-01-13 17:19:02 +03:00
Hirrolot
1bcf621c7d
Merge branch 'master' into tolerant_updates_for_all 2022-01-12 15:14:37 +07:00
Maybe Waffle
22159867bb Add Chat::has_protected_content 2022-01-11 15:51:28 +03:00
Maybe Waffle
5d743f165b Update changelog 2021-12-29 21:35:43 +03:00
Maybe Waffle
62e9e8afd4 Make ChatPermissions into bitflags 2021-12-29 20:36:08 +03:00
Waffle Maybe
fd3ef0bdf3
Merge pull request #154 from teloxide/bot_command_scope_fix
Fix serialization of `BotCommandScope::Chat{,Administrators}`
2021-12-28 17:07:46 +03:00
Maybe Waffle
f456ab110a Add ApiError::NotEnoughRightsToChangeChatPermissions 2021-12-28 17:04:19 +03:00
Maybe Waffle
f65617e763 Fix serialization of BotCommandScope::Chat{,Administrators} 2021-12-28 16:09:40 +03:00
Hirrolot
ff21d876c4
Merge branch 'master' into fix_some_message_deserialization_bugs 2021-12-28 19:49:08 +07:00
Hirrolot
54f4281754
Merge pull request #150 from teloxide/invalid_json_raw
Add `RequestError::InvalidJson::raw` field
2021-12-25 14:03:58 +06:00
Maybe Waffle
9ce53a2b02 Fix deserialization of VoiceChat{Started,Ended} messages 2021-12-25 04:50:31 +03:00
Maybe Waffle
078ee1d7ce Refactor forwarded messages 2021-12-25 04:27:13 +03:00
Maybe Waffle
2bd19a598e Add User::is_anonymous and User::is_channel functions
Also add documentation for `User::{full_name, mention, url}`
2021-12-25 04:12:59 +03:00
Maybe Waffle
1bcb062d88 Add RequestError::InvalidJson::raw field 2021-12-24 15:47:54 +03:00
Maybe Waffle
3f2d69702f Update changelog and add regression test for issue 481 2021-12-19 18:52:03 +03:00
Sprite
234ac365db Update changelog and comment the PR link in the test 2021-12-19 21:26:39 +08:00
Hirrolot
22de637798
Merge pull request #143 from teloxide/api55
TBA 5.5
2021-12-19 17:16:45 +06:00
Maybe Waffle
f42c1a6098 Fix deserialization of chat migrations 2021-12-10 17:00:49 +03:00
Maybe Waffle
6c1c585733 Update changelog 2021-12-10 16:02:28 +03:00
Maybe Waffle
560fa36e41 re-run payloads codegen 2021-12-07 01:31:49 +03:00
Waffle Maybe
e3a0087644
Merge pull request #140 from SpriteOvO/master
Add the missing method `caption_entities` to `InputMediaPhoto`
2021-12-07 01:08:42 +03:00
Sprite
7a65d52fb7 Update changelog 2021-12-07 04:13:58 +08:00
Sprite
a33588a14b Update changelog 2021-11-28 02:33:33 +08:00
Sprite
30154f6fba Update changelog 2021-11-27 17:50:03 +08:00
Maybe Waffle
b34b4369c7 Update changelog 2021-11-20 19:50:57 +03:00
Maybe Waffle
ca69b6385c Update changelog 2021-11-15 01:47:53 +03:00
Hirrolot
461d882bc1
Merge pull request #134 from teloxide/errfactor
Refactor errors
2021-11-13 19:09:22 +06:00