Skip to content

Commit d1d95ee

Browse files
committed
Fix some old Synapse access tokens not being recognized
1 parent 17c5fd5 commit d1d95ee

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

crates/data-model/src/tokens.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// Copyright 2024 New Vector Ltd.
1+
// Copyright 2024, 2025 New Vector Ltd.
22
// Copyright 2021-2024 The Matrix.org Foundation C.I.C.
33
//
44
// SPDX-License-Identifier: AGPL-3.0-only
55
// Please see LICENSE in the repository root for full details.
66

7-
use base64ct::{Base64Url, Encoding};
7+
use base64ct::{Base64UrlUnpadded, Encoding};
88
use chrono::{DateTime, Utc};
99
use crc::{CRC_32_ISO_HDLC, Crc};
1010
use mas_iana::oauth::OAuthTokenTypeHint;
@@ -353,7 +353,7 @@ impl PartialEq<OAuthTokenTypeHint> for TokenType {
353353
/// We won't bother to decode them fully, but we can check to see if the first
354354
/// constraint is the `location` constraint.
355355
fn is_likely_synapse_macaroon(token: &str) -> bool {
356-
let Ok(decoded) = Base64Url::decode_vec(token) else {
356+
let Ok(decoded) = Base64UrlUnpadded::decode_vec(token) else {
357357
return false;
358358
};
359359
decoded.get(4..13) == Some(b"location ")
@@ -443,8 +443,8 @@ mod tests {
443443
"MDAxYmxvY2F0aW9uIGxpYnJlcHVzaC5uZXQKMDAx"
444444
));
445445

446-
// Whilst this is a macaroon, it's not a Synapse macaroon
447-
assert!(!is_likely_synapse_macaroon(
446+
// This is a valid macaroon (even though Synapse did not generate this one)
447+
assert!(is_likely_synapse_macaroon(
448448
"MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVzZWQgb3VyIHNlY3JldCBrZXkKMDAyZnNpZ25hdHVyZSDj2eApCFJsTAA5rhURQRXZf91ovyujebNCqvD2F9BVLwo"
449449
));
450450

0 commit comments

Comments
 (0)