Skip to content

Commit 56f0b8c

Browse files
authored
Do not validate nor replace bearer tokens (#3338)
Fixes #3337
1 parent da271c8 commit 56f0b8c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/secrets.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ impl Token {
7575
/// This performs the following checks on a given token:
7676
/// - Is not empty;
7777
/// - Is optionally prefixed with `"Bot "` or `"Bearer "`;
78-
/// - Contains 3 parts (split by the period char `'.'`);
79-
///
80-
/// Note that a token prefixed with `"Bearer "` will have its prefix changed to `"Bot "` when
81-
/// parsed.
78+
/// - Contains 3 parts (for bot tokens) (split by the period char `'.'`);
8279
///
8380
/// # Examples
8481
///
@@ -102,7 +99,11 @@ impl FromStr for Token {
10299
type Err = TokenError;
103100

104101
fn from_str(s: &str) -> Result<Self, Self::Err> {
105-
let token = s.trim().trim_start_matches("Bot ").trim_start_matches("Bearer ");
102+
if s.starts_with("Bearer ") {
103+
return Ok(Self(SecretString::new(Arc::from(s))));
104+
}
105+
106+
let token = s.trim().trim_start_matches("Bot ");
106107

107108
let mut parts = token.split('.');
108109
let is_valid = parts.next().is_some_and(|p| !p.is_empty())

0 commit comments

Comments
 (0)