Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(auth): add original_url allowlist (#5108)
Will Hutchinson05e91860651d
diff --git a/services/authentication_service/src/api/login/sso.rs b/services/authentication_service/src/api/login/sso.rsindex f891f3ba45..fbc1171b0e 100644--- a/services/authentication_service/src/api/login/sso.rs+++ b/services/authentication_service/src/api/login/sso.rs@@ -35,6 +35,20 @@ pub(crate) struct LoginQueryParams {referral_code: Option<String>,}+fn is_allowed_original_url(url: &Url) -> bool {+ match url.scheme() {+ // The iOS app uses macro://login as its authentication callback.+ "macro" => url.host_str() == Some("login"),+ "tauri" => url.host_str() == Some("localhost"),+ "http" => matches!(url.host_str(), Some("localhost" | "tauri.localhost")),+ "https" => matches!(+ url.host_str(),+ Some("localhost" | "tauri.localhost" | "dev.macro.com" | "macro.com")+ ),+ _ => false,+ }+}+/// Initiates an SSO login#[utoipa::path(get,@@ -68,6 +82,21 @@ pub async fn handler(referral_code,}) = query;+ let original_url = original_url.map(|url| url.0);+ if original_url+ .as_ref()+ .is_some_and(|url| !is_allowed_original_url(url))+ {+ tracing::error!("original_url is not allowed");+ return Err((+ StatusCode::BAD_REQUEST,+ Json(ErrorResponse {+ message: "provided original_url is not allowed".into(),+ }),+ )+ .into_response());+ }+if idp_name.is_none() && idp_id.is_none() {tracing::error!("idp_name and idp_id are both missing");return Err((@@ -128,7 +157,7 @@ pub async fn handler(let state = SsoState {is_mobile,- original_url: original_url.map(|x| x.0),+ original_url,referral_code,};diff --git a/services/authentication_service/src/api/login/sso/tests.rs b/services/authentication_service/src/api/login/sso/tests.rsindex 584538b6b6..e876d05769 100644--- a/services/authentication_service/src/api/login/sso/tests.rs+++ b/services/authentication_service/src/api/login/sso/tests.rs@@ -6,6 +6,47 @@ use cool_asserts::assert_matches;use super::*;+#[test]+fn allowed_original_urls_are_accepted() {+ for original_url in [+ "macro://login",+ "tauri://localhost/app/login",+ "http://tauri.localhost/app/login",+ "https://tauri.localhost/app/login",+ "http://localhost:3000/app/login",+ "https://localhost/app/login",+ "https://dev.macro.com/app/login",+ "https://macro.com/app/login",+ ] {+ let original_url = Url::parse(original_url).expect("test URL should parse");+ assert!(+ is_allowed_original_url(&original_url),+ "{original_url} should be allowed"+ );+ }+}++#[test]+fn untrusted_original_urls_are_rejected() {+ for original_url in [+ "https://example.com/app/login",+ "https://macro.com.example.com/app/login",+ "https://staging.macro.com/app/login",+ "http://macro.com/app/login",+ "http://dev.macro.com/app/login",+ "macro://attacker.example",+ "tauri://example.com/app/login",+ "http://127.0.0.1:3000/app/login",+ "javascript:alert('redirected')",+ ] {+ let original_url = Url::parse(original_url).expect("test URL should parse");+ assert!(+ !is_allowed_original_url(&original_url),+ "{original_url} should be rejected"+ );+ }+}+#[tokio::test]async fn it_works_with_no_params() {let request = Request::builder()@@ -116,7 +157,7 @@ async fn it_works_with_everything() {#[tokio::test]async fn it_works_with_macro_scheme() {- let request = Request::builder().uri("https://example.com/login/sso?original_url=macro%3A%2F%2Fapp%2Flogin&idp_name=google&is_mobile=true").body(Body::from(())).unwrap();+ let request = Request::builder().uri("https://example.com/login/sso?original_url=macro%3A%2F%2Flogin&idp_name=google&is_mobile=true").body(Body::from(())).unwrap();let extracted = Query::<LoginQueryParams>::from_request(request, &()).await@@ -131,7 +172,7 @@ async fn it_works_with_macro_scheme() {referral_code: _}) => {assert_eq!(idp_name, "google");- assert_eq!(original_url.0.as_str(), "macro://app/login");+ assert_eq!(original_url.0.as_str(), "macro://login");});}