Skip to content

improvement(chat): deployed chat no longer uses subdomains, uses sim.ai/chat/[identifier]#1474

Merged
waleedlatif1 merged 8 commits into
stagingfrom
sim-49
Sep 28, 2025
Merged

improvement(chat): deployed chat no longer uses subdomains, uses sim.ai/chat/[identifier]#1474
waleedlatif1 merged 8 commits into
stagingfrom
sim-49

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • deployed chat no longer uses subdomains, uses sim.ai/chat/[identifier]
  • existing chat (e.g. x.sim.ai) now are available at sim.ai/chat/x and all future chats will use the new notation
  • this prevents subdomains of our app being used for chat deploys, posed vuln

Type of Change

  • New feature

Testing

Tested manually.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel Bot commented Sep 27, 2025

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

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Sep 28, 2025 0:32am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 28, 2025 0:32am

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Summary

This PR successfully migrates chat deployments from subdomain-based URLs (x.sim.ai) to path-based URLs (sim.ai/chat/x), addressing a significant security vulnerability where subdomains could be abused.

Key Changes:

  • Database migration renames subdomain column to identifier with proper indexing
  • API endpoints updated to use path-based routing with /chat/[identifier] structure
  • URL generation logic changed from ${identifier}.sim.ai to sim.ai/chat/${identifier}
  • Proper validation maintains regex pattern /^[a-z0-9-]+$/ for identifiers
  • Authentication and CORS handling preserved for new path structure
  • UI components updated to display new URL format correctly

Security Improvements:

  • Eliminates subdomain abuse potential on sim.ai domain
  • Maintains all existing authentication mechanisms (public, password, email)
  • Preserves CSRF protection and validation patterns

Testing & Validation:

  • Comprehensive test coverage maintained for API routes
  • Identifier validation ensures backward compatibility
  • Database migration properly handles existing deployments

The implementation is thorough and maintains feature parity while significantly improving security posture.

Confidence Score: 4/5

  • This PR is safe to merge with one minor cookie domain configuration issue to address
  • Score reflects comprehensive implementation with proper database migration, validation, and security improvements, but includes one logic issue with cookie domain settings that should be reviewed
  • Pay close attention to apps/sim/app/api/chat/utils.ts for cookie domain configuration with path-based routing

Important Files Changed

File Analysis

Filename        Score        Overview
apps/sim/app/api/chat/route.ts 4/5 Chat creation API updated to use path-based URLs instead of subdomains, includes proper validation and identifier uniqueness checks
apps/sim/app/api/chat/[identifier]/route.ts 4/5 Chat execution API using path-based identifier with proper authentication and CORS handling
packages/db/schema.ts 5/5 Database schema updated with identifier column and unique index, removing subdomain references
packages/db/migrations/0094_perpetual_the_watchers.sql 5/5 Database migration renames subdomain to identifier and updates index accordingly
apps/sim/app/api/chat/utils.ts 3/5 Critical chat utility functions with complex authentication and workflow execution logic - extensive but potential edge case handling needed

Sequence Diagram

sequenceDiagram
    participant User as User
    participant UI as Deploy Modal UI
    participant API as Chat API (/api/chat)
    participant Validate as Validate API
    participant DB as Database
    participant Workflow as Workflow Engine
    
    Note over User,Workflow: New Path-Based Chat Deployment Flow
    
    User->>UI: Configure chat deployment
    UI->>Validate: GET /api/chat/validate?identifier=myChat
    Validate->>DB: Check if identifier exists
    DB-->>Validate: Return availability
    Validate-->>UI: {available: true/false}
    
    alt identifier available
        User->>UI: Submit deployment
        UI->>API: POST /api/chat
        Note over API: Validates identifier with regex: /^[a-z0-9-]+$/
        API->>DB: Check workflow access & deployment status
        DB-->>API: Return workflow info
        API->>DB: INSERT new chat with identifier
        DB-->>API: Return chat record
        Note over API: Generate URL: sim.ai/chat/{identifier}
        API-->>UI: {id, chatUrl: "https://sim.ai/chat/myChat"}
        UI-->>User: Display success with new URL format
    end
    
    Note over User,Workflow: Chat Access Flow (Previously: subdomain.sim.ai)
    User->>Workflow: GET sim.ai/chat/myChat
    Workflow->>API: POST /api/chat/myChat
    API->>DB: Find chat by identifier
    DB-->>API: Return chat config
    alt authentication required
        API-->>Workflow: {error: "auth_required_password"}
        Workflow-->>User: Show auth form
        User->>Workflow: Submit credentials
        Workflow->>API: POST with auth data
        API->>API: Validate credentials
        API-->>Workflow: Set auth cookie & continue
    end
    API->>Workflow: Execute workflow with input
    Workflow-->>User: Stream response
Loading

36 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread apps/sim/app/api/chat/utils.ts Outdated
@vercel vercel Bot temporarily deployed to Preview – docs September 28, 2025 00:29 Inactive
@waleedlatif1 waleedlatif1 merged commit dd1985c into staging Sep 28, 2025
9 of 10 checks passed
@waleedlatif1 waleedlatif1 deleted the sim-49 branch September 28, 2025 00:32
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