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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
chore: OSS Scanner build image and threat model; fix the npm Dependabot job (#2000)
Sid42b9bfbde6be
diff --git a/.github/dependabot.yml b/.github/dependabot.ymlindex eefe4c460f..0ed4dde3ed 100644--- a/.github/dependabot.yml+++ b/.github/dependabot.yml@@ -4,28 +4,24 @@# One npm entry with directory "/" covers the whole pnpm workspace via the# root pnpm-lock.yaml; one cargo entry likewise covers the Rust workspace via# Cargo.lock. Updates are grouped to keep PR volume manageable in this monorepo.+# npm version updates are off; see the npm entry.version: 2updates:# JavaScript/TypeScript — pnpm workspace (root lockfile covers all packages/apps)+ # Version updates are off (limit 0). The workspace has ~340 direct+ # dependencies and Dependabot runs `pnpm update -r` for each, about 2.5 hours,+ # while a job is killed at 55 minutes. Every weekly run timed out, and a run+ # started by a change to this file blocked the release of that commit.+ # Vulnerable npm dependencies come from Dependabot security updates, which+ # run per advisory and are unaffected by this limit.- package-ecosystem: "npm"directory: "/"schedule:interval: "weekly"day: "monday"- open-pull-requests-limit: 10+ open-pull-requests-limit: 0labels:- "dependencies"- groups:- dev-dependencies:- dependency-type: "development"- update-types:- - "minor"- - "patch"- production-minor-patch:- dependency-type: "production"- update-types:- - "minor"- - "patch"# Rust — cargo workspace (root Cargo.lock covers all crates + assembler)- package-ecosystem: "cargo"@@ -69,6 +65,11 @@ updates:open-pull-requests-limit: 5labels:- "dependencies"+ # Major image versions (a new Node or Postgres line) are upgraded on purpose,+ # not by a weekly bot PR.+ ignore:+ - dependency-name: "*"+ update-types: ["version-update:semver-major"]# Images pinned in the dev and self-host compose files- package-ecosystem: "docker-compose"@@ -81,3 +82,8 @@ updates:open-pull-requests-limit: 5labels:- "dependencies"+ # Major image versions (a new Node or Postgres line) are upgraded on purpose,+ # not by a weekly bot PR.+ ignore:+ - dependency-name: "*"+ update-types: ["version-update:semver-major"]diff --git a/.oss-scanner/Dockerfile b/.oss-scanner/Dockerfilenew file mode 100644index 0000000000..8205ea86dd--- /dev/null+++ b/.oss-scanner/Dockerfile@@ -0,0 +1,106 @@+# Build image for Anthropic's OSS Scanner (https://github.com/anthropics/oss-scanner).+# The scanner builds this with the repository as context, then audits /src with no+# network, so everything the tests need is fetched here.+#+# It covers both workspaces: the TypeScript monorepo (apps/erp, apps/mes,+# packages/*) and the Rust workspace (crates/*, apps/assembler). The Rust crates+# link OpenCASCADE, FCL and Draco, built below from the same pinned sources as+# apps/assembler/Dockerfile and occt.Dockerfile; keep the versions in step. Those+# stages build in parallel with the JavaScript install, which keeps the whole+# build inside the scanner's 45-minute limit.++# ---- OpenCASCADE, static (as apps/assembler/occt.Dockerfile) ----+FROM debian:bookworm AS occt+RUN apt-get update && apt-get install -y --no-install-recommends \+ git cmake g++ make ninja-build ca-certificates perl \+ && rm -rf /var/lib/apt/lists/*+RUN git clone --depth 1 --branch V8_0_0_p1 https://github.com/Open-Cascade-SAS/OCCT.git /occt+COPY apps/assembler/occt-patches /occt-patches+RUN /occt-patches/apply.sh /occt+RUN cmake -S /occt -B /occt/build -G Ninja \+ -DCMAKE_BUILD_TYPE=Release \+ -DCMAKE_INSTALL_PREFIX=/opt/occt \+ -DBUILD_LIBRARY_TYPE=Static \+ -DBUILD_MODULE_Draw=OFF \+ -DBUILD_MODULE_Visualization=OFF \+ -DBUILD_MODULE_ApplicationFramework=ON \+ -DBUILD_MODULE_DataExchange=ON \+ -DBUILD_MODULE_ModelingAlgorithms=ON \+ -DBUILD_MODULE_ModelingData=ON \+ -DBUILD_MODULE_FoundationClasses=ON \+ -DUSE_FREETYPE=OFF -DUSE_XLIB=OFF -DUSE_TK=OFF -DUSE_TCL=OFF \+ -DUSE_OPENGL=OFF -DUSE_GLES2=OFF -DUSE_RAPIDJSON=OFF -DUSE_TBB=OFF \+ -DUSE_FREEIMAGE=OFF -DUSE_DRACO=OFF -DUSE_VTK=OFF -DUSE_FFMPEG=OFF \+ && cmake --build /occt/build --target install++# ---- FCL + libccd, static (as apps/assembler/Dockerfile) ----+FROM debian:bookworm AS fcl+RUN apt-get update && apt-get install -y --no-install-recommends \+ git cmake ninja-build g++ libeigen3-dev ca-certificates \+ && rm -rf /var/lib/apt/lists/*+RUN git clone --depth 1 --branch v2.1 https://github.com/danfis/libccd.git /ccd \+ && cmake -S /ccd -B /ccd/b -G Ninja -DCMAKE_BUILD_TYPE=Release \+ -DCMAKE_INSTALL_PREFIX=/opt/fcl -DCMAKE_POSITION_INDEPENDENT_CODE=ON \+ -DBUILD_SHARED_LIBS=OFF -DENABLE_DOUBLE_PRECISION=ON \+ && cmake --build /ccd/b --target install+RUN git clone --depth 1 --branch 0.7.0 https://github.com/flexible-collision-library/fcl.git /fcl \+ && cmake -S /fcl -B /fcl/b -G Ninja -DCMAKE_BUILD_TYPE=Release \+ -DCMAKE_INSTALL_PREFIX=/opt/fcl -DCMAKE_PREFIX_PATH=/opt/fcl \+ -DCMAKE_POSITION_INDEPENDENT_CODE=ON \+ -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_STANDARD_REQUIRED=ON \+ -DFCL_STATIC_LIBRARY=ON -DFCL_WITH_OCTOMAP=OFF -DFCL_BUILD_TESTS=OFF \+ && cmake --build /fcl/b --target install++# ---- Draco encoder, static (as apps/assembler/Dockerfile) ----+FROM debian:bookworm AS draco+RUN apt-get update && apt-get install -y --no-install-recommends \+ git cmake ninja-build g++ ca-certificates \+ && rm -rf /var/lib/apt/lists/*+RUN git clone --depth 1 --branch 1.5.7 https://github.com/google/draco.git /draco \+ && cmake -S /draco -B /draco/b -G Ninja -DCMAKE_BUILD_TYPE=Release \+ -DCMAKE_INSTALL_PREFIX=/opt/draco -DCMAKE_POSITION_INDEPENDENT_CODE=ON \+ -DBUILD_SHARED_LIBS=OFF -DDRACO_TRANSCODER_SUPPORTED=OFF \+ && cmake --build /draco/b --target install++# ---- Rust toolchain (the assembler's builder image) ----+FROM rust:1.99-bookworm AS rust++# ---- The image the scanner audits ----+FROM node:24.22.1-bookworm++# Eigen for the collision shim, OpenBLAS and gfortran for the planner.+RUN apt-get update && apt-get install -y --no-install-recommends \+ libeigen3-dev libopenblas-dev gfortran cmake ninja-build \+ && rm -rf /var/lib/apt/lists/*++ENV CI=1 \+ COREPACK_ENABLE_DOWNLOAD_PROMPT=0 \+ NODE_OPTIONS=--max-old-space-size=8024 \+ RUSTUP_HOME=/usr/local/rustup \+ CARGO_HOME=/usr/local/cargo \+ PATH=/usr/local/cargo/bin:$PATH \+ OCCT_PREFIX=/opt/occt OCCT_LINK=static \+ FCL_PREFIX=/opt/fcl LIBCCD_PREFIX=/opt/fcl EIGEN_PREFIX=/usr OCTOMAP_PREFIX=/usr \+ DRACO_PREFIX=/opt/draco++COPY . /src+WORKDIR /src++# TypeScript: the same install the production image runs (see /Dockerfile), then+# both server apps. The ERP build also generates the MCP tool manifest.+RUN corepack enable && pnpm --version+RUN pnpm install --frozen-lockfile+RUN pnpm run build:erp && pnpm run build:mes++# Rust: the native libraries arrive here, after the JavaScript steps, so their+# stages compile alongside them. A dev build keeps debug info for the auditor.+COPY --from=rust /usr/local/rustup /usr/local/rustup+COPY --from=rust /usr/local/cargo /usr/local/cargo+COPY --from=occt /opt/occt /opt/occt+COPY --from=fcl /opt/fcl /opt/fcl+COPY --from=draco /opt/draco /opt/draco+RUN cargo fetch --locked && cargo build --workspace --all-targets --locked++# Tests run offline. A failure is reported, never fatal.+RUN timeout 1200 pnpm run test || echo "WARNING: unit tests reported failures"+RUN timeout 900 cargo test --workspace --locked --offline || echo "WARNING: cargo tests reported failures"diff --git a/.oss-scanner/Dockerfile.dockerignore b/.oss-scanner/Dockerfile.dockerignorenew file mode 100644index 0000000000..26cfc120fa--- /dev/null+++ b/.oss-scanner/Dockerfile.dockerignore@@ -0,0 +1,19 @@+# The root .dockerignore is written for the slim production images and leaves out+# sources the scanner should see. BuildKit reads this file instead for+# .oss-scanner/Dockerfile.+node_modules+**/node_modules+.turbo+**/.turbo+**/target+**/build+**/.react-router+**/.next+.env+.env.*+**/.env+**/.env.*+!**/.env.example+**/.envrc+**/secrets/+**/*.secretdiff --git a/.oss-scanner/threat_model.md b/.oss-scanner/threat_model.mdnew file mode 100644index 0000000000..4a10fcaa83--- /dev/null+++ b/.oss-scanner/threat_model.md@@ -0,0 +1,56 @@+# Carbon threat model++## What Carbon is and where untrusted input enters++Carbon is a multi-tenant manufacturing ERP (`apps/erp`) and shop-floor MES (`apps/mes`): React Router v7 server apps on Supabase (Postgres with row-level security, Auth, Storage), with background jobs on Inngest (`packages/jobs`). Many companies share one database. Every business table carries `companyId`, and RLS policies plus server-side checks keep each company's data apart.++Treat all of these as untrusted:++- **Authenticated users of another company.** Any signed-in user is untrusted with respect to every company they do not belong to, and to permissions their role lacks inside their own company (`requirePermissions`, `packages/auth`).+- **Login and session flows**: `apps/erp/app/routes/_public+` (login, magic link, MFA, invite, callback, refresh-session, unlock).+- **The public API and MCP server**: `apps/erp/app/routes/api+/v1+` (API-key authenticated, `api+/v1+/lib/authenticate.server.ts`), `api+/mcp+`, and the OAuth authorization server for MCP clients (`_oauth+`, `.well-known` routes).+- **Inbound webhooks**, each meant to verify its sender: `api+/webhook.*` (Stripe, Stripe Connect, Xero, QuickBooks, Ramp, Rillet, Jira, Linear, Onshape, Paperless Parts), `api+/integrations.slack.*`, and the Inngest endpoint `api+/inngest.ts`.+- **OAuth callbacks** for integrations (`api+/integrations.*.oauth.ts`): the `state` parameter and the code exchange.+- **Unauthenticated share pages** that read with elevated privileges: `routes/share+/*` (quotes, customer portal, RFQs, supplier quotes, SCARs, training) and token downloads (`routes/download.$token.tsx`). The URL token or id is the only credential.+- **The Onshape panel** (`routes/onshape+`): the one route that may be framed cross-site; it authenticates with its own bearer panel session, not the cookie.+- **File uploads and previews**: images, PDFs, CAD files and CSV imports (`packages/files`, `routes/file+`). The preview proxy authorizes by `companyId` in the storage path.+- **CAD files in the assembler** (`apps/assembler`, `crates/*`, Rust): an internal HTTP service. Every `/v1/*` route requires a bearer key (`ASSEMBLER_SERVICE_API_KEY`) unless `ASSEMBLER_DEV_MODE=true`, which is for local development only; `/health` is public, and `/events` is mounted only on AWS Lambda, where only an IAM-signed invoke reaches it. It downloads a user-uploaded STEP or GLB from a URL, parses it with OpenCASCADE through `cxx` bridges (`crates/occt-bridge`), converts, plans, optimizes or renders it, and uploads the result. The file content is fully attacker-controlled; the URLs come from Carbon but are checked by the service (`apps/assembler/src/http.rs`, `source.rs`).+- **Code a company writes**: configuration rules run in a QuickJS WebAssembly sandbox (`packages/database/src/configuration-rule.ts`), and workflow automations run conditions and actions (`packages/ee/src/workflows`, `packages/jobs/src/workflows`).+- **Text people type** that is later rendered (notes, rich text via tiptap, document templates, emails, PDFs).++## Components that matter most / least++Most important:+- Tenant isolation: RLS policies in `packages/database/supabase/migrations`, and every server path that uses the service-role client (`getCarbonServiceRole`, `asSystem`) where RLS does not apply. A query on the service role that is not scoped by `companyId` is the classic Carbon bug.+- Authentication and authorization: `packages/auth`, the API-key path, MCP and OAuth, MFA enforcement, invite and session handling.+- Share pages, token downloads and the storage preview proxy.+- Webhook signature checks and OAuth `state` handling.+- The configuration-rule sandbox and workflow execution.+- Accounting postings and payments (`apps/erp/app/modules/accounting`, `invoicing`): a bug that lets a user post or alter another company's ledger matters even without data theft.+- The assembler's parsers and native boundary: the `cxx` bridges into OpenCASCADE, FCL and Draco (`crates/occt-bridge`, `crates/collision`, `crates/draco-bridge`), GLB and meshopt decoding and the PNG encoder (`crates/thumbnail`, `crates/optimize`), and the source-URL checks and auth in `apps/assembler/src`.++Less important, still in scope: the academy app (`apps/academy`), the starter example (`apps/starter`), docs (`docs/`), and bugs inside OpenCASCADE, FCL or Draco themselves (report them, but say they are upstream).++Out of scope: `contrib/` (examples and deploy recipes), `.ai/` and `.claude/` (developer notes), generated files (`packages/database/src/types.ts`, swagger output), and local dev tooling (`packages/dev`).++## How to exercise it++- Unit tests: `pnpm run test` (Vitest through Turborepo), or one package: `pnpm --filter @carbon/auth test`, `pnpm --filter erp test`.+- Typecheck one package: `pnpm exec turbo run typecheck --filter=<package>`. A whole-repo typecheck runs out of memory.+- The database tests in `packages/database/supabase/tests` (pgTAP) need a running Supabase stack, which this image does not have. Read the RLS policies in the migrations directly, and read every migration that touches a table's policies: Postgres keeps each policy until a later migration drops or alters it by name, and permissive policies on one table combine with OR, so an older policy can still grant access.+- Route handlers are plain `loader`/`action` functions and can be read and tested without a server.+- Rust: the workspace is already built (dev profile, debug info) against static OpenCASCADE, FCL and Draco. Run `cargo test --workspace --offline`, or one crate: `cargo test -p converter --offline`. `crates/occt-bridge` has `write_test_step` for generating STEP fixtures; `cargo run -p thumbnail --example render -- in.glb out.png` renders a GLB. The service itself needs Redis (`REDIS_URL`), which this image does not run; call the crate functions directly instead.++## How we rate severity++- **Critical**: reading or writing another company's data; authentication bypass; taking over another user's account; remote code execution on the server, including through a crafted CAD file reaching memory corruption in the assembler; escaping the configuration-rule sandbox.+- **High**: privilege escalation inside a company (a role acting beyond its permissions, including reaching an admin-only action); a webhook or OAuth callback accepted without valid verification; a share or download token that can be guessed or reused beyond its intent; stored XSS that runs in another user's session in the ERP or MES; memory-safety bugs in the assembler (out-of-bounds read or write, use-after-free across a `cxx` bridge) without a demonstrated exploit; SSRF from the assembler's source or callback URLs that reaches internal services or returns their responses; calling the assembler without its bearer key.+- **Medium**: reflected XSS, CSRF on a state-changing action, SSRF limited to blind fetching, information disclosure inside the user's own company that their role should not see, open redirects that carry a token; a crafted CAD file that crashes the assembler or holds its memory admission so other companies' jobs stall.+- **Low**: denial of service that needs an authenticated user, missing security headers, verbose errors; a CAD file that is merely slow to convert within the service's limits.+- A finding that needs an attacker to hold the service-role key, database superuser access or a compromised deploy environment is out of scope: those are already full access. Application code that uses the service-role client (`getCarbonServiceRole`, `asSystem`) is in scope: a route that lets an ordinary user reach another company's rows through it is a critical tenant-isolation bug.++## Anything to leave alone++- Commercial features under `packages/ee` and `*.ee.*` files are in scope for security bugs; licence gating (plan or entitlement checks) is a business control, not a security boundary.+- Self-hosted defaults in `contrib/deploying` and `.env.example` files are examples, not deployments.+- Prefer a reproducer as a Vitest test or a short request sequence, with a patch that keeps the `companyId` scoping explicit.