Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix(integrations): harden the Mount client per review

Raul01e777af8307
diff --git a/packages/ee/src/mount/config.tsx b/packages/ee/src/mount/config.tsx
index 05624d8285..f10fcb8f5f 100644
--- a/packages/ee/src/mount/config.tsx
+++ b/packages/ee/src/mount/config.tsx
@@ -1,13 +1,17 @@
import type { ComponentProps } from "react";
import { z } from "zod";
import { defineIntegration } from "../fns";
-import { MOUNT_DEFAULT_BASE_URL } from "./lib/constants";
+import { isHttpsUrl, MOUNT_DEFAULT_BASE_URL } from "./lib/constants";
const MountSettingsSchema = z.object({
clientId: z.string().min(1),
// Empty means "keep the existing vaulted secret"; presence enforced at install.
clientSecret: z.string(),
- baseUrl: z.string().url().default(MOUNT_DEFAULT_BASE_URL),
+ baseUrl: z
+ .string()
+ .url()
+ .refine(isHttpsUrl, { message: "Must be an HTTPS URL" })
+ .default(MOUNT_DEFAULT_BASE_URL),
tenant: z.string().min(1),
scope: z.string().optional(),
// Slug and titles, not ids. Mount never shows a user a UUID: the object
diff --git a/packages/ee/src/mount/lib/client.ts b/packages/ee/src/mount/lib/client.ts
index 3251a05775..5491b4e147 100644
--- a/packages/ee/src/mount/lib/client.ts
+++ b/packages/ee/src/mount/lib/client.ts
@@ -2,7 +2,11 @@ import { getCarbonServiceRole } from "@carbon/auth/client.server";
import { getLogger } from "@carbon/logger";
import axios, { type AxiosInstance } from "axios";
import { resolveIntegrationSecrets } from "../../integrations/secrets";
-import { MOUNT_API_VERSION, MOUNT_DEFAULT_BASE_URL } from "./constants";
+import {
+ isHttpsUrl,
+ MOUNT_API_VERSION,
+ MOUNT_DEFAULT_BASE_URL
+} from "./constants";
import { getMountIntegration, MOUNT_INTEGRATION_ID } from "./service";
import {
type MountChange,
@@ -77,7 +81,17 @@ export class MountClient {
constructor() {
this.instance = axios.create({
- headers: { "Content-Type": "application/json" }
+ headers: { "Content-Type": "application/json" },
+ // Concurrent callers share one token exchange; a hung endpoint must
+ // reject eventually or all of them wait on it.
+ timeout: MOUNT_REQUEST_TIMEOUT_MS,
+ // Every request carries the client secret or a bearer token, so a
+ // redirect may never downgrade to plain HTTP.
+ beforeRedirect: (options) => {
+ if (options.protocol !== "https:") {
+ throw new Error("Mount redirected to a non-HTTPS URL; refusing");
+ }
+ }
});
}
@@ -184,6 +198,12 @@ export class MountClient {
throw new Error("Mount integration is missing a client ID");
}
+ // Also enforced by the settings schema; checked here for values saved
+ // before that, since the secret is sent to this URL.
+ if (!isHttpsUrl(metadata.baseUrl || MOUNT_DEFAULT_BASE_URL)) {
+ throw new Error("Mount API URL must use HTTPS");
+ }
+
return metadata;
}
@@ -465,6 +485,8 @@ function connectionKey(settings: MountSettings) {
].join("\u0000");
}
+const MOUNT_REQUEST_TIMEOUT_MS = 30_000;
+
const UUID_PATTERN =
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
diff --git a/packages/ee/src/mount/lib/constants.ts b/packages/ee/src/mount/lib/constants.ts
index 75a991b54a..3fde98c76b 100644
--- a/packages/ee/src/mount/lib/constants.ts
+++ b/packages/ee/src/mount/lib/constants.ts
@@ -16,3 +16,12 @@ export const MOUNT_DEFAULT_BASE_URL = "https://api.mount.cloud";
export const MOUNT_API_VERSION = "2026-06-01";
export const MOUNT_INTEGRATION_ID = "mount";
+
+/** The Mount API URL receives the client secret, so it must be HTTPS. */
+export function isHttpsUrl(value: string) {
+ try {
+ return new URL(value).protocol === "https:";
+ } catch {
+ return false;
+ }
+}
diff --git a/packages/ee/src/mount/lib/run.ts b/packages/ee/src/mount/lib/run.ts
index 6dfe5e8c8f..ef13388ae5 100644
--- a/packages/ee/src/mount/lib/run.ts
+++ b/packages/ee/src/mount/lib/run.ts
@@ -39,7 +39,15 @@ export async function runMountPublish({
{ status: "inactive" } | { status: "ran"; summaries: MountPublishSummary[] }
> {
const integration = await getMountIntegration(serviceRole, companyId);
- if (integration.error || !integration.data?.[0]?.active) {
+ // A failed lookup is not "inactive": throw so the job step retries.
+ if (integration.error) {
+ logger.error("Failed to read Mount integration", {
+ companyId,
+ error: integration.error
+ });
+ throw new Error("Failed to read Mount integration");
+ }
+ if (!integration.data?.[0]?.active) {
return { status: "inactive" };
}