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 constant time eq (#6209)

Will Hutchinsonfbc504ca778f
diff --git a/Cargo.lock b/Cargo.lock
index dfe02fedda..27418003cf 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3119,6 +3119,7 @@ dependencies = [
"serde",
"serde_json",
"sqlx",
+ "subtle",
"thiserror 2.0.18",
"tokio",
"tracing",
@@ -5957,6 +5958,7 @@ dependencies = [
"sqs_worker",
"static_file_service_client",
"strum_macros 0.27.2",
+ "subtle",
"system_properties",
"thiserror 2.0.18",
"tokio",
@@ -15987,6 +15989,7 @@ dependencies = [
"matchit 0.8.4",
"serde",
"serde_json",
+ "subtle",
"sync_service_bebop_schema",
"time",
"tracing",
diff --git a/Cargo.toml b/Cargo.toml
index c59674a54a..39b80d3df6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -359,6 +359,7 @@ url = "2.5.0"
zip = "=2.4.2"
ammonia = "4.1.4"
html-escape = "0.2"
+subtle = "2.6.1"
# Retain Rust DWARF for local cache profiling while keeping release-level LLVM
# optimization. wasm-pack's custom profile metadata prevents the final
diff --git a/crates/call/Cargo.toml b/crates/call/Cargo.toml
index 4bd4adc963..0b74b2d546 100644
--- a/crates/call/Cargo.toml
+++ b/crates/call/Cargo.toml
@@ -87,6 +87,7 @@ utoipa = { workspace = true, optional = true }
urlencoding = { workspace = true, optional = true }
uuid = { workspace = true }
workspace-hack = { version = "0.1", path = "../workspace-hack" }
+subtle = { workspace = true }
[dev-dependencies]
macro_db_migrator = { path = "../macro_db_migrator" }
diff --git a/crates/call/src/domain/service.rs b/crates/call/src/domain/service.rs
index c55382291d..fda197a4a5 100644
--- a/crates/call/src/domain/service.rs
+++ b/crates/call/src/domain/service.rs
@@ -23,6 +23,7 @@ use notification::domain::ports::VoipPushSender;
use notification::domain::service::NotificationIngress;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
+use subtle::ConstantTimeEq;
use uuid::Uuid;
@@ -478,7 +479,7 @@ impl<
fn validate_internal_call(&self, token: &str) -> bool {
self.internal_call_secret
.as_deref()
- .is_some_and(|secret| secret == token)
+ .is_some_and(|secret| secret.as_bytes().ct_eq(token.as_bytes()).into())
}
#[tracing::instrument(err, skip(self))]
diff --git a/crates/github/Cargo.toml b/crates/github/Cargo.toml
index 1b363a88b7..3d409868f8 100644
--- a/crates/github/Cargo.toml
+++ b/crates/github/Cargo.toml
@@ -70,7 +70,7 @@ serde = { workspace = true }
serde_json = { workspace = true }
sha2 = { workspace = true }
sqlx = { workspace = true, optional = true }
-subtle = "2.6.1"
+subtle = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
urlencoding = { workspace = true, optional = true }
diff --git a/services/email_service/Cargo.toml b/services/email_service/Cargo.toml
index ff14c55cbe..c5509896ee 100644
--- a/services/email_service/Cargo.toml
+++ b/services/email_service/Cargo.toml
@@ -181,6 +181,7 @@ urlencoding = { workspace = true }
utoipa = { workspace = true }
utoipa-swagger-ui = { workspace = true }
uuid = { workspace = true }
+subtle = { workspace = true }
macro_service_urls = { path = "../../crates/macro_service_urls" }
workspace-hack = { version = "0.1", path = "../../crates/workspace-hack" }
diff --git a/services/email_service/src/api/calendar_watch.rs b/services/email_service/src/api/calendar_watch.rs
index 13fde2573e..c7620477db 100644
--- a/services/email_service/src/api/calendar_watch.rs
+++ b/services/email_service/src/api/calendar_watch.rs
@@ -10,6 +10,7 @@ use axum::Router;
use axum::extract::State;
use axum::http::{HeaderMap, StatusCode};
use axum::routing::post;
+use subtle::ConstantTimeEq;
use crate::api::context::ApiContext;
use email_service::pubsub::context::calendar_watch_config;
@@ -28,12 +29,18 @@ async fn handler(State(ctx): State<ApiContext>, headers: HeaderMap) -> StatusCod
let Some(config) = calendar_watch_config() else {
return StatusCode::NOT_FOUND;
};
- if header(&headers, "x-goog-channel-token") != Some(config.token.as_str()) {
+
+ let valid = header(&headers, "x-goog-channel-token")
+ .is_some_and(|token| bool::from(token.as_bytes().ct_eq(config.token.as_bytes())));
+
+ if !valid {
return StatusCode::FORBIDDEN;
}
+
if header(&headers, "x-goog-resource-state") == Some("sync") {
return StatusCode::OK;
}
+
let (Some(channel_id), Some(resource_id)) = (
header(&headers, "x-goog-channel-id"),
header(&headers, "x-goog-resource-id"),
diff --git a/services/sync-service/Cargo.toml b/services/sync-service/Cargo.toml
index 46687da287..f05f8f242d 100644
--- a/services/sync-service/Cargo.toml
+++ b/services/sync-service/Cargo.toml
@@ -47,3 +47,4 @@ loro = "1.13"
macro_sync_service_jwt = { path = "../../crates/macro_sync_service_jwt" }
matchit = "0.8.4"
worker-rs-otel = { path = "../../crates/worker-rs-otel" }
+subtle = { workspace = true }
diff --git a/services/sync-service/src/auth.rs b/services/sync-service/src/auth.rs
index 221375ceeb..f4e0f483a1 100644
--- a/services/sync-service/src/auth.rs
+++ b/services/sync-service/src/auth.rs
@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize};
+use subtle::ConstantTimeEq;
use tracing::error;
use worker::Error;
@@ -87,13 +88,13 @@ pub fn decode_jwt(
{
// sholud we warn when false?
Some(internal_key) => {
- let res = internal_key == secrets.internal_api_secret;
+ let res: bool = internal_key
+ .as_bytes()
+ .ct_eq(secrets.internal_api_secret.as_bytes())
+ .into();
+
if !res {
- error!(
- "provided header: {internal_key}
-did not match expected value: {}",
- secrets.internal_api_secret
- );
+ error!("provided header: {internal_key} did not match expected value");
}
res
}