Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(auth): clockskew on jwt validation: (#340)

teo67cbe83ab0eb
diff --git a/rust/cloud-storage/macro_auth/src/middleware/decode_jwt.rs b/rust/cloud-storage/macro_auth/src/middleware/decode_jwt.rs
index 29a0188c59..bc1a8000b7 100644
--- a/rust/cloud-storage/macro_auth/src/middleware/decode_jwt.rs
+++ b/rust/cloud-storage/macro_auth/src/middleware/decode_jwt.rs
@@ -1,3 +1,5 @@
+use std::time::Duration;
+
use anyhow::Context;
use jsonwebtoken::{Algorithm, DecodingKey, Validation, decode};
use macro_env::Environment;
@@ -128,6 +130,8 @@ pub fn validate_macro_access_token(
)
}
+const TOKEN_EXPIRATION_BUFFER_SECONDS: Duration = Duration::from_secs(60);
+
fn validate_macro_access_token_inner(
macro_access_token: &str,
jwt_secret: &LocalOrRemoteSecret<JwtSecretKey>,
@@ -137,6 +141,9 @@ fn validate_macro_access_token_inner(
// Verify and decode the JWT
let mut validation = Validation::new(Algorithm::HS256);
+ validation.leeway = 0;
+ validation.reject_tokens_expiring_in_less_than = TOKEN_EXPIRATION_BUFFER_SECONDS.as_secs();
+
validation.set_audience(&[audience.as_ref()]);
validation.set_issuer(&[issuer.as_ref()]);