Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognise macaroons as access tokens from Synapse #3797

Merged
merged 1 commit into from
Jan 17, 2025

Conversation

reivilibre
Copy link
Contributor

@reivilibre reivilibre commented Jan 14, 2025

A short and sweet one!

Closes #2150

p.s. I have verified on matrix.org that all tokens start with either MDAx or syt_.

@reivilibre reivilibre requested a review from sandhose January 14, 2025 17:09
Copy link

cloudflare-workers-and-pages bot commented Jan 14, 2025

Deploying matrix-authentication-service-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 42ee1ad
Status: ✅  Deploy successful!
Preview URL: https://a1036bc3.matrix-authentication-service-docs.pages.dev
Branch Preview URL: https://rei-supp-macaroons-from-syna.matrix-authentication-service-docs.pages.dev

View logs

@@ -294,7 +294,8 @@ impl TokenType {
pub fn check(token: &str) -> Result<TokenType, TokenFormatError> {
// these are legacy tokens imported from Synapse
// we don't do any validation on them and continue as is
if token.starts_with("syt_") {
// Tokens starting `MDAx` are macaroons from even older versions of Synapse.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm being pedantic for a second, macaroons are a list of hex length plus (key space value), then HMAC'd and base64'd.

The first K/V is location/servername, which means:

  • it will start with 000flocation for HS with a single character
  • it be 001Nlocation (with N varying) for HS with 2 to 17 characters
  • etc.

So the prefix MDAx works because it's the base64 serialisation of 001. The MDA prefix would work for server names up to 145 characters.

If we want to be extra sure, we would:

  • base64url decode the string
  • check on the result that byte 5 to 13 are exactly 6c 6f 63 61 74 69 6f 6e (location)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair for digging in to the format! I wasn't able to find (and still haven't found) the spec for Macaroons.
I probably should have looked at some code at least

@reivilibre reivilibre force-pushed the rei/supp_macaroons_from_synapse branch from 5dfa9b9 to 62a9bd1 Compare January 16, 2025 17:25
@reivilibre reivilibre force-pushed the rei/supp_macaroons_from_synapse branch from 62a9bd1 to 42ee1ad Compare January 16, 2025 17:27
@reivilibre reivilibre requested a review from sandhose January 16, 2025 17:30
@reivilibre reivilibre merged commit 21e2c36 into main Jan 17, 2025
20 checks passed
@reivilibre reivilibre deleted the rei/supp_macaroons_from_synapse branch January 17, 2025 09:50
@sandhose sandhose added A-Migration Related to the migration tooling T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks. labels Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Migration Related to the migration tooling T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migration advisor doesn't detect macraoon-like tokens
2 participants