# Security Audit — hivegrid-cloud Date: 2026-07-04 Method: 10 parallel security finders (multi-agent) + adversarial per-finding verification. Scope: full monorepo (apps/web, apps/api, apps/worker, apps/mcp, packages/*), with extra scrutiny on the freshly built MCP endpoint. Result: 15 raw findings -> **11 confirmed** (3 high, 3 medium, 5 low), 4 false positives filtered out, 0 need manual review. ## Remediation status (2026-07-04) All 11 confirmed findings fixed on branch `akeshan/security-audit-fixes`. Each fix has tests and passed the repo pre-commit gates (test-density, eslint-baseline, secrets, lint-staged) and the relevant app typecheck. Not yet merged/deployed — see the deploy prerequisite below. - **XSS — icon sanitization** (`b1760f5be`): route KB category (list + top-articles) and onboarding step icons through `sanitizeIconSvg()` instead of a bare `.replace(" stored verbatim (`KnowledgeBaseService.server.ts`) -> rendered via `dangerouslySetInnerHTML` with `item.icon.replace(" unauthenticated `/docs/:lang` route -> executes in every anonymous visitor's browser. **Exploit scenario** A KB editor stores ``. The `/docs` loader has no auth guard, so any anonymous visitor loading the page executes the payload in the app origin. Fixed by `sanitizeIconSvg()`, which strips script/foreignObject/event-handler vectors — the same sanitizer the sibling renderers already use. ## 2. [High] MCP rate limit bypassed via JSON-RPC batching - **Category:** Rate-limiting / DoS | **Verdict:** confirmed | **Fix effort:** moderate | **Finder confidence:** high - **Location:** `apps/mcp/src/rate-limit.ts:34`, `apps/mcp/src/transport.ts`, `apps/mcp/src/auth.ts` - **Data flow:** `checkMcpRateLimit` consumed one token per HTTP request, but the Streamable-HTTP SDK dispatches every element of a JSON-RPC array body -> one authenticated POST carrying N `tools/call` messages ran all N handlers (incl. write tools) for one token. **Exploit scenario** An attacker with one valid MCP token sends a single POST with ~11,000 `tools/call` messages (fits in the 1 MB body cap), executing them all — mass writes / DB DoS within the tenant — while spending one of the 1,000/h key and 10,000/h tenant tokens. Fixed by counting operations, rejecting batches over 50, and charging one token per operation. ## 3. [High] MFA/TOTP brute-force via spoofed X-Forwarded-For - **Category:** Auth / rate-limiting | **Verdict:** confirmed | **Fix effort:** moderate | **Finder confidence:** high - **Location:** `apps/web/app/utils/auth/mfa/challenge-rate-limit.server.ts:39` - **Data flow:** MFA throttle keyed on `${userId}:${ip}` where `ip` = leftmost (client-controlled) `X-Forwarded-For` -> attacker rotates the header per guess -> a fresh 5/5min bucket every time -> the 429 never fires. **Exploit scenario** An attacker holding the victim's password (thus a pending-MFA session) sends TOTP guesses with a random `X-Forwarded-For` per request, defeating the only anti-brute-force control on the 6-digit code — a full 2FA bypass. Fixed with an authoritative per-user limiter (keyed on `userId` alone, 15/15min) plus a trusted-header per-IP component. ## 4. [Medium] Stored XSS via KB icon on public `/docs` (KbCategoriesTopArticles) - **Category:** Stored XSS | **Verdict:** confirmed | **Fix effort:** low | **Finder confidence:** high - **Location:** `apps/web/app/modules/knowledgeBase/components/categories/KbCategoriesTopArticles.tsx:23` - **Data flow:** Same defect as #1; injection is gated behind `admin.kb.*` (platform operator), so severity is medium, but the payload still executes for every anonymous `/docs` visitor. Fixed by `sanitizeIconSvg()`. ## 5. [Medium] MCP OAuth path does not reject deactivated tenants - **Category:** Broken access control | **Verdict:** confirmed | **Fix effort:** low | **Finder confidence:** high - **Location:** `apps/mcp/src/auth.ts:38`, `apps/web/app/services/mcp/oauth.server.ts` (refresh grant) - **Data flow:** The API-key branch rejects `tenant.deactivatedReason`; the OAuth access branch and the refresh grant never checked tenant status -> a suspended tenant keeps MCP read+write access, and the rotating refresh token extends it indefinitely. **Exploit scenario** Operations suspends a tenant for abuse/non-payment; its MCP client keeps reading CRM data and mutating projects/leads via still-valid OAuth tokens. Fixed by checking `deactivatedReason` in both the OAuth access branch and `exchangeRefreshToken`. ## 6. [Medium] SSRF DNS-rebinding TOCTOU in the outbound-HTTP guard - **Category:** SSRF | **Verdict:** confirmed | **Fix effort:** moderate | **Finder confidence:** high - **Location:** `packages/foundation/src/outbound-http.ts:35` - **Data flow:** The guard resolves the hostname and checks the addresses against the blocklist, but `fetch(url)` re-resolves DNS independently at connect time -> a low-TTL hostname answers a public IP to the guard and an internal one (10.42.0.4 mesh, 169.254.169.254 metadata) to the connect. **Exploit scenario** An authenticated user submits a workflow HTTP block / webhook URL (`WorkflowBlockService.ts`, `apps/worker/src/handlers.ts`) whose hostname rebinds to an internal mesh IP; the auth-less mesh services (Meili, ClamAV, Loki, nsfw) are then reachable server-side. Fixed by pinning the connection to the validated IP via an undici dispatcher `lookup` (TLS SNI stays the hostname), re-pinned per redirect hop. ## 7. [Low] Hardcoded fallback HMAC secrets for MCP OAuth / API keys - **Category:** Secrets / weak default | **Verdict:** confirmed | **Fix effort:** low | **Finder confidence:** high - **Location:** `apps/mcp/src/config.ts` (guard), `packages/db/src/mcp-oauth.server.ts:6` - **Data flow:** MCP OAuth token / legacy API-key hashing fall back to public source-code constants when the hash secrets are unset; the MCP runtime config read them as optional and booted silently on the fallback. **Exploit scenario** A prod MCP deploy missing the secrets hashes tokens with a source-known key, making stored hashes portable across any default-keyed deployment (defense-in-depth loss; DB-write compromise could then mint valid tokens). Fixed by failing closed in production. See the deploy prerequisite above. ## 8. [Low] Stored XSS via onboarding step icon - **Category:** Stored XSS | **Verdict:** confirmed | **Fix effort:** low | **Finder confidence:** high - **Location:** `apps/web/app/modules/onboarding/blocks/OnboardingVariantModal.tsx:136` - **Data flow:** Same missing-sanitization pattern as #1; injection required the former host super-admin onboarding builder (`admin.onboarding.update`) and the payload executed for all tenants' end users. Fixed by `sanitizeIconSvg()` before the admin builder was removed from the default admin surface. ## 9. [Low] Login leaks existence of magic-link-only accounts - **Category:** Auth / account enumeration | **Verdict:** confirmed | **Fix effort:** low | **Finder confidence:** high - **Location:** `apps/web/app/modules/users/services/AuthService.ts:250` - **Data flow:** Passwordless (`passwordHash === null`) accounts short-circuited with a distinct body (`requiresMagicLink`) before `verifyPassword` and skipped `recordFailedLogin` -> content + timing side-channel distinguishing invited accounts. **Exploit scenario** An attacker POSTs `/login` with a target email; a `requiresMagicLink` response (or a faster reply) marks it as a registered passwordless account. Fixed by falling through to the same dummy-hash comparison and generic invalid-credentials response as an unknown email; the magic-link hint moved to the forgot-password flow (`e083a183c`). ## 10. [Low] MCP endpoint has no pre-authentication rate limit - **Category:** Rate-limiting / DoS | **Verdict:** confirmed | **Fix effort:** low | **Finder confidence:** high - **Location:** `apps/mcp/src/auth.ts:38`, `apps/mcp/src/rate-limit.ts` - **Data flow:** The limiter was only reached after a token resolved, so requests with an invalid/absent token were never throttled yet still forced `findActiveMcpOAuthAccessToken` + `findLegacyApiKeyByKey` lookups. **Exploit scenario** An unauthenticated attacker floods the MCP root with junk bearer tokens, forcing DB token lookups (partly on the primary DB) with no throttle. Fixed with a per-IP fixed-window shield (300/min, trusted IP) before the token lookups. ## 11. [Low] Public form per-IP rate limit bypassable via spoofed X-Forwarded-For - **Category:** Rate-limiting / injection | **Verdict:** confirmed | **Fix effort:** low | **Finder confidence:** high - **Location:** `apps/web/app/routes/api.leads.capture.tsx:80`, `apps/web/app/routes/api.embed.forms.$formKey.submit.tsx:166` - **Data flow:** The lead-capture and embed-form endpoints key the per-IP limiter on the leftmost `X-Forwarded-For` -> a scripted attacker rotates the header to flood `InboxLead` / form submissions. **Exploit scenario** An attacker sets an allowlisted `Origin` and a unique `X-Forwarded-For` per POST, bypassing the per-IP cap to spam the tenant's inbox. Fixed by deriving the IP from a trusted proxy header. --- ## False positives filtered out (4) - **MCP read tools bypass RBAC** (reported twice): `tenantHasMcpModule` requires `app.settings.roles.set` for every MCP request -> only an RBAC-admin-equivalent user can reach the tools, so no privilege boundary is crossed. - **Raw internal error messages to the MCP client**: every attacker-controllable failure is pre-guarded into a controlled `McpHttpError`; the residual leak is fault-only (DB outage), not attacker-drivable on demand. - **URL uploads buffer the remote body with no size cap**: `storageService.ts:96` early-returns http URLs unless a caller passes `replace: true`, and no production caller does -> unreachable dead code. ## Verification (local, green) `apps/mcp/src/{transport,config,rate-limit}.test.ts` · `apps/web/app/utils/auth/mfa/challenge-rate-limit.server.test.ts` · `AuthService.passwordless.test.ts` · `AuthService.mfaLoginGate.test.ts` · `apps/web/app/utils/server/IpUtils.test.ts` · `apps/web/app/services/auth/auth-rate-limit.server.test.ts` · `apps/api/src/auth/login-rate-limit.test.ts` · `packages/foundation/src/outbound-http.test.ts` · `apps/worker/src/handlers.test.ts`. Known Windows environmentals (not regressions): the full `apps/web` vitest suite fails on Node 22.15 at `new Request(...URLSearchParams)` (undici) — affects e.g. `registerFromRequest` and the forgot-password **action** tests, not the changed component/limiter/login paths.