Skip to content

refactor(security): ipaddr-free @sim/security/hostnames sub-export (removes urls.ts loopback dup)#5787

Merged
waleedlatif1 merged 1 commit into
staging-v4from
feat/security-hostnames-subexport
Jul 21, 2026
Merged

refactor(security): ipaddr-free @sim/security/hostnames sub-export (removes urls.ts loopback dup)#5787
waleedlatif1 merged 1 commit into
staging-v4from
feat/security-hostnames-subexport

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

What

Follow-up to #5784 (the SSRF hardening PR, now merged). Completes the @sim/security/ssrf consolidation by splitting the pure host helpers into an ipaddr-free sub-export so the last duplicate can be removed.

unwrapIpv6Brackets + isLoopbackHostname never touch ipaddr.js, but they lived in @sim/security/ssrf whose top line is import * as ipaddr from 'ipaddr.js'. That's why apps/sim/lib/core/utils/urls.ts — which is pulled into client bundles — kept its own copy of isLoopbackHostname (importing the ssrf one would have dragged ipaddr.js into the browser).

Change

  • New @sim/security/hostnames — pure, zero-dependency: unwrapIpv6Brackets, isLoopbackHostname.
  • ssrf.ts imports unwrapIpv6Brackets from it and re-exports both, so every existing @sim/security/ssrf consumer (desktop + server) is unchanged.
  • urls.ts drops its local LOCALHOST_HOSTNAMES set + isLoopbackHostname, and its three client importers (hooks/queries/mcp, mcp/oauth/probe, mcp/oauth/url-validation) now use the single shared definition — no ipaddr.js in the client bundle.
  • Tests for the pure helpers moved to hostnames.test.ts.

Behavior is equivalent for every reachable url.hostname input (bracketed IPv6 [::1] → stripped ::1; localhost/127.0.0.1 unchanged) — verified by direct execution.

Testing

@sim/security 106 · affected sim suites (urls + mcp/oauth) 45 · type-check (security + full apps/sim) · check:boundaries · check:utils · check:api-validation:strict · Biome — all green.

…r-free)

unwrapIpv6Brackets + isLoopbackHostname move to a new ipaddr-free sub-export so
client code can share them without pulling ipaddr.js into the browser bundle.
ssrf.ts re-exports both, so its server/desktop consumers are unchanged. This
eliminates the duplicate isLoopbackHostname in apps/sim/lib/core/utils/urls.ts:
urls.ts and its three client importers (mcp queries, oauth probe, oauth
url-validation) now use the single shared definition.
@waleedlatif1
waleedlatif1 requested a review from a team as a code owner July 21, 2026 00:34
@vercel

vercel Bot commented Jul 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 21, 2026 12:34am

Request Review

@cursor

cursor Bot commented Jul 21, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Refactor with equivalent exact-match loopback behavior; no auth or SSRF logic changes beyond import paths.

Overview
Introduces @sim/security/hostnames as an ipaddr-free export for unwrapIpv6Brackets and isLoopbackHostname, so client code can share one loopback definition without pulling ipaddr.js into the browser (which blocked importing these from @sim/security/ssrf).

apps/sim drops the duplicate LOCALHOST_HOSTNAMES / isLoopbackHostname in urls.ts and switches urls.ts, MCP hooks, and MCP OAuth helpers to import from @sim/security/hostnames. @sim/security/ssrf now imports unwrapIpv6Brackets from hostnames and re-exports both helpers so existing @sim/security/ssrf consumers stay unchanged.

Unit tests for the pure helpers move from ssrf.test.ts to hostnames.test.ts.

Reviewed by Cursor Bugbot for commit 32bb5b3. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR moves pure hostname checks into an ipaddr.js-free security subpath. The main changes are:

  • Adds @sim/security/hostnames with loopback and IPv6 helpers.
  • Keeps existing SSRF imports working through re-exports.
  • Moves browser-facing callers to the dependency-free subpath.
  • Removes the duplicate URL helper and moves its focused tests.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
packages/security/src/hostnames.ts Adds dependency-free hostname helpers with behavior matching the previous implementations.
packages/security/src/ssrf.ts Uses the extracted IPv6 helper internally and preserves the existing public API through re-exports.
packages/security/package.json Exposes the new hostname module using the package's established subpath export pattern.
apps/sim/lib/core/utils/urls.ts Removes the duplicate loopback implementation and delegates URL checks to the shared helper.
apps/sim/hooks/queries/mcp.ts Moves the client-facing loopback check to the dependency-free security subpath.
apps/sim/lib/mcp/oauth/probe.ts Uses the shared hostname helper without changing OAuth probe behavior.
apps/sim/lib/mcp/oauth/url-validation.ts Uses the shared helper while preserving insecure URL validation behavior.
packages/security/src/hostnames.test.ts Covers canonical loopback hosts, bracketed IPv6 input, and negative cases.

Reviews (1): Last reviewed commit: "refactor: split pure host helpers into @..." | Re-trigger Greptile

@waleedlatif1
waleedlatif1 merged commit 7430094 into staging-v4 Jul 21, 2026
5 checks passed
@waleedlatif1
waleedlatif1 deleted the feat/security-hostnames-subexport branch July 21, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant