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.

chore: cors updates for more localhost sessions (#2442)

gbirman5bf4022403e8
diff --git a/infra/packages/resources/src/resources/cors.ts b/infra/packages/resources/src/resources/cors.ts
index 7391c0bf72..060bbe8960 100644
--- a/infra/packages/resources/src/resources/cors.ts
+++ b/infra/packages/resources/src/resources/cors.ts
@@ -1,5 +1,14 @@
export const ALLOWED_ORIGINS = [
'http://localhost:3000',
+ 'http://localhost:3001',
+ 'http://localhost:3002',
+ 'http://localhost:3003',
+ 'http://localhost:3004',
+ 'http://localhost:3005',
+ 'http://localhost:3006',
+ 'http://localhost:3007',
+ 'http://localhost:3008',
+ 'http://localhost:3009',
'http://host.local:3000',
'https://app-dev.macro.com',
'https://app-staging.macro.com',
diff --git a/infra/stacks/fusionauth-instance/origins.ts b/infra/stacks/fusionauth-instance/origins.ts
index 474e95fe39..390bc71411 100644
--- a/infra/stacks/fusionauth-instance/origins.ts
+++ b/infra/stacks/fusionauth-instance/origins.ts
@@ -11,6 +11,15 @@ export const ALLOWED_ORIGINS = () => {
return [
...allowedOrigins,
'http://localhost:3000',
+ 'http://localhost:3001',
+ 'http://localhost:3002',
+ 'http://localhost:3003',
+ 'http://localhost:3004',
+ 'http://localhost:3005',
+ 'http://localhost:3006',
+ 'http://localhost:3007',
+ 'http://localhost:3008',
+ 'http://localhost:3009',
'http://localhost:5173',
'https://github.com',
];
@@ -18,6 +27,15 @@ export const ALLOWED_ORIGINS = () => {
return [
...allowedOrigins,
'http://localhost:3000',
+ 'http://localhost:3001',
+ 'http://localhost:3002',
+ 'http://localhost:3003',
+ 'http://localhost:3004',
+ 'http://localhost:3005',
+ 'http://localhost:3006',
+ 'http://localhost:3007',
+ 'http://localhost:3008',
+ 'http://localhost:3009',
'https://dev.macro.com',
'http://localhost:8084',
'http://localhost:5173',
diff --git a/js/app/tauri/src-tauri/src/lib.rs b/js/app/tauri/src-tauri/src/lib.rs
index f4f2cc53b0..ee0280197c 100644
--- a/js/app/tauri/src-tauri/src/lib.rs
+++ b/js/app/tauri/src-tauri/src/lib.rs
@@ -90,6 +90,15 @@ static ALLOWED_DOMAINS: &[&str] = &[
"tauri://localhost",
"https://macro.com",
"http://localhost:3000",
+ "http://localhost:3001",
+ "http://localhost:3002",
+ "http://localhost:3003",
+ "http://localhost:3004",
+ "http://localhost:3005",
+ "http://localhost:3006",
+ "http://localhost:3007",
+ "http://localhost:3008",
+ "http://localhost:3009",
];
#[cfg_attr(mobile, tauri::mobile_entry_point)]
diff --git a/local_stack.just b/local_stack.just
index 728d99fbc9..1c07883682 100644
--- a/local_stack.just
+++ b/local_stack.just
@@ -77,7 +77,7 @@ create_local_buckets:
aws --endpoint-url=http://localhost:4566 s3 mb s3://bulk-upload-staging || true
# Apply CORS configuration to all buckets
for bucket in macro-email-attachments doc-storage docx-upload static-file-storage bulk-upload-staging; do \
- aws --endpoint-url=http://localhost:4566 s3api put-bucket-cors --bucket $bucket --cors-configuration '{"CORSRules":[{"AllowedOrigins":["http://localhost:3000"],"AllowedMethods":["GET","PUT","POST","DELETE","HEAD"],"AllowedHeaders":["*"],"ExposeHeaders":["ETag"],"MaxAgeSeconds":3600}]}' || true; \
+ aws --endpoint-url=http://localhost:4566 s3api put-bucket-cors --bucket $bucket --cors-configuration '{"CORSRules":[{"AllowedOrigins":["http://localhost:3000","http://localhost:3001","http://localhost:3002","http://localhost:3003","http://localhost:3004","http://localhost:3005","http://localhost:3006","http://localhost:3007","http://localhost:3008","http://localhost:3009"],"AllowedMethods":["GET","PUT","POST","DELETE","HEAD"],"AllowedHeaders":["*"],"ExposeHeaders":["ETag"],"MaxAgeSeconds":3600}]}' || true; \
done
@echo "S3 buckets created"
diff --git a/rust/cloud-storage/authentication_service/src/api/utils.rs b/rust/cloud-storage/authentication_service/src/api/utils.rs
index 2432c8b8e0..9f479925b1 100644
--- a/rust/cloud-storage/authentication_service/src/api/utils.rs
+++ b/rust/cloud-storage/authentication_service/src/api/utils.rs
@@ -42,7 +42,10 @@ pub fn generate_session_code() -> String {
/// Returns the default redirect url based on the environment
pub fn default_redirect_url() -> Url {
match Environment::new_or_prod() {
- Environment::Local => "http://localhost:3000".parse().unwrap(), // We don't really care about redirect in local
+ Environment::Local => {
+ let port = std::env::var("FRONTEND_PORT").unwrap_or_else(|_| "3000".to_string());
+ format!("http://localhost:{port}").parse().unwrap()
+ }
Environment::Develop => "https://dev.macro.com/app".parse().unwrap(),
Environment::Production => "https://macro.com/app".parse().unwrap(),
}
diff --git a/rust/cloud-storage/connection_gateway/src/constants.rs b/rust/cloud-storage/connection_gateway/src/constants.rs
index 4514fa1d15..59788dcd84 100644
--- a/rust/cloud-storage/connection_gateway/src/constants.rs
+++ b/rust/cloud-storage/connection_gateway/src/constants.rs
@@ -1,7 +1,16 @@
use axum::http::HeaderValue;
-pub const ORIGINS: [HeaderValue; 14] = [
+pub const ORIGINS: [HeaderValue; 23] = [
HeaderValue::from_static("http://localhost:3000"),
+ HeaderValue::from_static("http://localhost:3001"),
+ HeaderValue::from_static("http://localhost:3002"),
+ HeaderValue::from_static("http://localhost:3003"),
+ HeaderValue::from_static("http://localhost:3004"),
+ HeaderValue::from_static("http://localhost:3005"),
+ HeaderValue::from_static("http://localhost:3006"),
+ HeaderValue::from_static("http://localhost:3007"),
+ HeaderValue::from_static("http://localhost:3008"),
+ HeaderValue::from_static("http://localhost:3009"),
HeaderValue::from_static("http://host.local:3000"),
HeaderValue::from_static("https://app-dev.macro.com"),
HeaderValue::from_static("https://app-staging.macro.com"),
diff --git a/rust/cloud-storage/github/src/domain/service/sync/mod.rs b/rust/cloud-storage/github/src/domain/service/sync/mod.rs
index ef1bc77eb8..555bd33faf 100644
--- a/rust/cloud-storage/github/src/domain/service/sync/mod.rs
+++ b/rust/cloud-storage/github/src/domain/service/sync/mod.rs
@@ -374,7 +374,10 @@ fn create_macro_task_comment_link(name: &str, id: &str) -> String {
let url = match macro_env::Environment::new_or_prod() {
macro_env::Environment::Production => "https://macro.com/app/task",
macro_env::Environment::Develop => "https://dev.macro.com/app/task",
- macro_env::Environment::Local => "http://localhost:3000/app/task",
+ macro_env::Environment::Local => {
+ let port = std::env::var("FRONTEND_PORT").unwrap_or_else(|_| "3000".to_string());
+ return format!("[{name}](http://localhost:{port}/app/task/{id})");
+ }
};
format!("[{name}]({url}/{id})")
diff --git a/rust/cloud-storage/invite_email/src/lib.rs b/rust/cloud-storage/invite_email/src/lib.rs
index 5a72752abb..70c1ab68ca 100644
--- a/rust/cloud-storage/invite_email/src/lib.rs
+++ b/rust/cloud-storage/invite_email/src/lib.rs
@@ -58,11 +58,14 @@ const MINUTES_PER_WEEK: u64 = 60 * 24 * 7;
fn signup_url(env: Environment) -> Url {
let host = match env {
- Environment::Production => "https://macro.com",
- Environment::Develop => "https://dev.macro.com",
- Environment::Local => "http://localhost:3000",
+ Environment::Production => "https://macro.com".to_string(),
+ Environment::Develop => "https://dev.macro.com".to_string(),
+ Environment::Local => {
+ let port = std::env::var("FRONTEND_PORT").unwrap_or_else(|_| "3000".to_string());
+ format!("http://localhost:{port}")
+ }
};
- let mut url = Url::parse(host).expect("all the inputs are static, valid values");
+ let mut url = Url::parse(&host).expect("all the inputs are static, valid values");
url.set_path("/app/signup");
url
}
diff --git a/rust/cloud-storage/macro_env/src/ext/frontend_url.rs b/rust/cloud-storage/macro_env/src/ext/frontend_url.rs
index 8cd02013d6..0833a6af03 100644
--- a/rust/cloud-storage/macro_env/src/ext/frontend_url.rs
+++ b/rust/cloud-storage/macro_env/src/ext/frontend_url.rs
@@ -12,7 +12,10 @@ impl FrontendUrl for Environment {
match self {
Environment::Production => "https://macro.com/app/".parse().unwrap(),
Environment::Develop => "https://dev.macro.com/app/".parse().unwrap(),
- Environment::Local => "http://localhost:3000/app/".parse().unwrap(),
+ Environment::Local => {
+ let port = std::env::var("FRONTEND_PORT").unwrap_or_else(|_| "3000".to_string());
+ format!("http://localhost:{port}/app/").parse().unwrap()
+ }
}
}
}
diff --git a/rust/cloud-storage/macro_service_urls/src/lib.rs b/rust/cloud-storage/macro_service_urls/src/lib.rs
index b97590789e..033f1849d2 100644
--- a/rust/cloud-storage/macro_service_urls/src/lib.rs
+++ b/rust/cloud-storage/macro_service_urls/src/lib.rs
@@ -48,7 +48,10 @@ impl EnvExtMacroServiceUrls for Environment {
match self {
Environment::Production => url("https://macro.com"),
Environment::Develop => url("https://dev.macro.com"),
- Environment::Local => url("http://localhost:3000"),
+ Environment::Local => {
+ let port = std::env::var("FRONTEND_PORT").unwrap_or_else(|_| "3000".to_string());
+ url(&format!("http://localhost:{port}"))
+ }
}
}
diff --git a/rust/sync-service/src/durable_object.rs b/rust/sync-service/src/durable_object.rs
index dbec4ab0b4..83be9e1227 100644
--- a/rust/sync-service/src/durable_object.rs
+++ b/rust/sync-service/src/durable_object.rs
@@ -952,6 +952,15 @@ pub struct PeerResponse {
pub static ALLOWED_ORIGINS: &[&str] = &[
"http://localhost:5173",
"http://localhost:3000",
+ "http://localhost:3001",
+ "http://localhost:3002",
+ "http://localhost:3003",
+ "http://localhost:3004",
+ "http://localhost:3005",
+ "http://localhost:3006",
+ "http://localhost:3007",
+ "http://localhost:3008",
+ "http://localhost:3009",
"http://host.local:3000",
"https://dev.macro.com",
"https://staging.macro.com",
diff --git a/rust/sync-service/tests/cors.test.ts b/rust/sync-service/tests/cors.test.ts
index 6c34818ece..21c3aff068 100644
--- a/rust/sync-service/tests/cors.test.ts
+++ b/rust/sync-service/tests/cors.test.ts
@@ -1,6 +1,6 @@
-import { Miniflare } from "miniflare";
-import { expect, test, describe, beforeEach } from "vitest";
-import { createTestUser, getTokenForDocument, setupMiniflare } from "./utils";
+import type { Miniflare } from 'miniflare';
+import { beforeEach, describe, expect, test } from 'vitest';
+import { createTestUser, getTokenForDocument, setupMiniflare } from './utils';
let mf: Miniflare;
@@ -8,30 +8,39 @@ beforeEach(async () => {
mf = await setupMiniflare();
});
-describe("CORS middleware tests", async () => {
- test("should allow requests from whitelisted origins", async () => {
+describe('CORS middleware tests', async () => {
+ test('should allow requests from whitelisted origins', async () => {
const allowedOrigins = [
- "http://localhost:5173",
- "http://localhost:3000",
- "http://host.local:3000",
- "https://dev.macro.com",
- "https://staging.macro.com",
- "https://www.macro.com",
- "https://macro.com",
- "capacitor://localhost",
- "https://apollo-testing.macro.com",
- "https://my-feature-branch.preview.macro.com",
- "https://fix-123.preview.macro.com",
+ 'http://localhost:5173',
+ 'http://localhost:3000',
+ 'http://localhost:3001',
+ 'http://localhost:3002',
+ 'http://localhost:3003',
+ 'http://localhost:3004',
+ 'http://localhost:3005',
+ 'http://localhost:3006',
+ 'http://localhost:3007',
+ 'http://localhost:3008',
+ 'http://localhost:3009',
+ 'http://host.local:3000',
+ 'https://dev.macro.com',
+ 'https://staging.macro.com',
+ 'https://www.macro.com',
+ 'https://macro.com',
+ 'capacitor://localhost',
+ 'https://apollo-testing.macro.com',
+ 'https://my-feature-branch.preview.macro.com',
+ 'https://fix-123.preview.macro.com',
];
- const token = getTokenForDocument("test-doc", "test-user", "owner");
+ const token = getTokenForDocument('test-doc', 'test-user', 'owner');
for (const origin of allowedOrigins) {
const response = await mf.dispatchFetch(
- "http://localhost:8787/document/test-doc/metadata",
+ 'http://localhost:8787/document/test-doc/metadata',
{
headers: {
- Authorization: "Bearer " + token,
+ Authorization: 'Bearer ' + token,
Origin: origin,
},
}
@@ -41,20 +50,22 @@ describe("CORS middleware tests", async () => {
expect([200, 404]).toContain(response.status);
// Check CORS headers
- expect(response.headers.get("Access-Control-Allow-Origin")).toBe(origin);
- expect(response.headers.get("Access-Control-Allow-Credentials")).toBe("true");
+ expect(response.headers.get('Access-Control-Allow-Origin')).toBe(origin);
+ expect(response.headers.get('Access-Control-Allow-Credentials')).toBe(
+ 'true'
+ );
}
});
- test("should handle preflight OPTIONS requests", async () => {
+ test('should handle preflight OPTIONS requests', async () => {
const response = await mf.dispatchFetch(
- "http://localhost:8787/document/test-doc/metadata",
+ 'http://localhost:8787/document/test-doc/metadata',
{
- method: "OPTIONS",
+ method: 'OPTIONS',
headers: {
- Origin: "https://dev.macro.com",
- "Access-Control-Request-Method": "GET",
- "Access-Control-Request-Headers": "authorization, content-type",
+ Origin: 'https://dev.macro.com',
+ 'Access-Control-Request-Method': 'GET',
+ 'Access-Control-Request-Headers': 'authorization, content-type',
},
}
);
@@ -62,103 +73,119 @@ describe("CORS middleware tests", async () => {
expect(response.status).toBe(200);
// Check preflight response headers
- expect(response.headers.get("Access-Control-Allow-Origin")).toBe("https://dev.macro.com");
- expect(response.headers.get("Access-Control-Allow-Credentials")).toBe("true");
- expect(response.headers.get("Access-Control-Allow-Methods")).toContain("GET");
- expect(response.headers.get("Access-Control-Allow-Methods")).toContain("POST");
- expect(response.headers.get("Access-Control-Allow-Methods")).toContain("OPTIONS");
- expect(response.headers.get("Access-Control-Allow-Headers")).toContain("authorization");
- expect(response.headers.get("Access-Control-Allow-Headers")).toContain("content-type");
+ expect(response.headers.get('Access-Control-Allow-Origin')).toBe(
+ 'https://dev.macro.com'
+ );
+ expect(response.headers.get('Access-Control-Allow-Credentials')).toBe(
+ 'true'
+ );
+ expect(response.headers.get('Access-Control-Allow-Methods')).toContain(
+ 'GET'
+ );
+ expect(response.headers.get('Access-Control-Allow-Methods')).toContain(
+ 'POST'
+ );
+ expect(response.headers.get('Access-Control-Allow-Methods')).toContain(
+ 'OPTIONS'
+ );
+ expect(response.headers.get('Access-Control-Allow-Headers')).toContain(
+ 'authorization'
+ );
+ expect(response.headers.get('Access-Control-Allow-Headers')).toContain(
+ 'content-type'
+ );
});
- test("should reject requests from non-whitelisted origins", async () => {
+ test('should reject requests from non-whitelisted origins', async () => {
const disallowedOrigins = [
- "https://malicious.com",
- "http://localhost:8080",
- "https://evil.macro.com",
- "https://fake-dashboard.macro.com",
- "http://evil.preview.macro.com", // HTTP not allowed for preview
- "https://preview.macro.com", // Must have subdomain
- "https://evil.preview.macro.com.attacker.com", // Suffix attack
+ 'https://malicious.com',
+ 'http://localhost:8080',
+ 'https://evil.macro.com',
+ 'https://fake-dashboard.macro.com',
+ 'http://evil.preview.macro.com', // HTTP not allowed for preview
+ 'https://preview.macro.com', // Must have subdomain
+ 'https://evil.preview.macro.com.attacker.com', // Suffix attack
];
- const token = getTokenForDocument("test-doc", "test-user", "owner");
+ const token = getTokenForDocument('test-doc', 'test-user', 'owner');
for (const origin of disallowedOrigins) {
const response = await mf.dispatchFetch(
- "http://localhost:8787/document/test-doc/metadata",
+ 'http://localhost:8787/document/test-doc/metadata',
{
headers: {
- Authorization: "Bearer " + token,
+ Authorization: 'Bearer ' + token,
Origin: origin,
},
}
);
// CORS should block the request or not set Access-Control-Allow-Origin
- const allowedOrigin = response.headers.get("Access-Control-Allow-Origin");
+ const allowedOrigin = response.headers.get('Access-Control-Allow-Origin');
expect(allowedOrigin).not.toBe(origin);
}
});
- test("should allow all HTTP methods for whitelisted origins", async () => {
- const methods = ["GET", "POST", "PUT", "PATCH", "DELETE"];
- const origin = "https://dev.macro.com";
+ test('should allow all HTTP methods for whitelisted origins', async () => {
+ const methods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
+ const origin = 'https://dev.macro.com';
for (const method of methods) {
const response = await mf.dispatchFetch(
- "http://localhost:8787/document/test-doc/metadata",
+ 'http://localhost:8787/document/test-doc/metadata',
{
- method: "OPTIONS",
+ method: 'OPTIONS',
headers: {
Origin: origin,
- "Access-Control-Request-Method": method,
+ 'Access-Control-Request-Method': method,
},
}
);
expect(response.status).toBe(200);
- const allowedMethods = response.headers.get("Access-Control-Allow-Methods");
+ const allowedMethods = response.headers.get(
+ 'Access-Control-Allow-Methods'
+ );
expect(allowedMethods).toContain(method);
}
});
- test("should allow required headers for API requests", async () => {
+ test('should allow required headers for API requests', async () => {
const response = await mf.dispatchFetch(
- "http://localhost:8787/document/test-doc/metadata",
+ 'http://localhost:8787/document/test-doc/metadata',
{
- method: "OPTIONS",
+ method: 'OPTIONS',
headers: {
- Origin: "https://dev.macro.com",
- "Access-Control-Request-Method": "GET",
- "Access-Control-Request-Headers": "authorization",
+ Origin: 'https://dev.macro.com',
+ 'Access-Control-Request-Method': 'GET',
+ 'Access-Control-Request-Headers': 'authorization',
},
}
);
expect(response.status).toBe(200);
- const allowedHeaders = response.headers.get("Access-Control-Allow-Headers");
- expect(allowedHeaders).toContain("authorization");
- expect(allowedHeaders).toContain("content-type");
+ const allowedHeaders = response.headers.get('Access-Control-Allow-Headers');
+ expect(allowedHeaders).toContain('authorization');
+ expect(allowedHeaders).toContain('content-type');
});
- test("should work with actual API requests after CORS validation", async () => {
+ test('should work with actual API requests after CORS validation', async () => {
// Create a document first
- const user = await createTestUser(mf, "cors-test-doc");
- user.makeChange("CORS test content");
+ const user = await createTestUser(mf, 'cors-test-doc');
+ user.makeChange('CORS test content');
await new Promise((resolve) => setTimeout(resolve, 100));
- const token = getTokenForDocument("cors-test-doc", "test-user", "owner");
+ const token = getTokenForDocument('cors-test-doc', 'test-user', 'owner');
// Make actual API request with CORS headers
const response = await mf.dispatchFetch(
- "http://localhost:8787/document/cors-test-doc/metadata",
+ 'http://localhost:8787/document/cors-test-doc/metadata',
{
headers: {
- Authorization: "Bearer " + token,
- Origin: "https://dev.macro.com",
- "Content-Type": "application/json",
+ Authorization: 'Bearer ' + token,
+ Origin: 'https://dev.macro.com',
+ 'Content-Type': 'application/json',
},
}
);
@@ -167,40 +194,48 @@ describe("CORS middleware tests", async () => {
// Verify both API response and CORS headers
const metadata = await response.json();
- expect(metadata.id).toBe("cors-test-doc");
+ expect(metadata.id).toBe('cors-test-doc');
- expect(response.headers.get("Access-Control-Allow-Origin")).toBe("https://dev.macro.com");
- expect(response.headers.get("Access-Control-Allow-Credentials")).toBe("true");
+ expect(response.headers.get('Access-Control-Allow-Origin')).toBe(
+ 'https://dev.macro.com'
+ );
+ expect(response.headers.get('Access-Control-Allow-Credentials')).toBe(
+ 'true'
+ );
user.connection.getWebSocket().close();
});
- test("should handle mobile app origins (Capacitor)", async () => {
- const token = getTokenForDocument("test-doc", "test-user", "owner");
+ test('should handle mobile app origins (Capacitor)', async () => {
+ const token = getTokenForDocument('test-doc', 'test-user', 'owner');
const response = await mf.dispatchFetch(
- "http://localhost:8787/document/test-doc/metadata",
+ 'http://localhost:8787/document/test-doc/metadata',
{
headers: {
- Authorization: "Bearer " + token,
- Origin: "capacitor://localhost",
+ Authorization: 'Bearer ' + token,
+ Origin: 'capacitor://localhost',
},
}
);
// Should allow Capacitor origin
- expect(response.headers.get("Access-Control-Allow-Origin")).toBe("capacitor://localhost");
- expect(response.headers.get("Access-Control-Allow-Credentials")).toBe("true");
+ expect(response.headers.get('Access-Control-Allow-Origin')).toBe(
+ 'capacitor://localhost'
+ );
+ expect(response.headers.get('Access-Control-Allow-Credentials')).toBe(
+ 'true'
+ );
});
- test("should handle requests without Origin header", async () => {
- const token = getTokenForDocument("test-doc", "test-user", "owner");
+ test('should handle requests without Origin header', async () => {
+ const token = getTokenForDocument('test-doc', 'test-user', 'owner');
const response = await mf.dispatchFetch(
- "http://localhost:8787/document/test-doc/metadata",
+ 'http://localhost:8787/document/test-doc/metadata',
{
headers: {
- Authorization: "Bearer " + token,
+ Authorization: 'Bearer ' + token,
// No Origin header
},
}