Skip to content

Fix regex validation for connection string in MCP client form #165

@coderabbitai

Description

@coderabbitai

Issue Description

The regex pattern for validating connection strings in the MCP client form component has incorrect anchoring that allows invalid URLs to pass validation.

Location

File: ui/components/config/mcp-client-form.tsx
Lines: 107-111

Problem

The current regex pattern /^(http:\/\/|https:\/\/|env\.[A-Z_]+$)/ only anchors the third alternative (env\.[A-Z_]+$). The first two alternatives (http:\/\/ and https:\/\/) are not properly anchored, allowing trailing characters to be accepted.

This means URLs like http://garbage or https://anythingelse would incorrectly pass validation.

Current Code

Validator.pattern(
  form.connection_string || '',
  /^(http:\/\/|https:\/\/|env\.[A-Z_]+$)/,
  'Connection URL must start with http://, https://, or be an environment variable (env.VAR_NAME)',
),

Suggested Fix

Validator.pattern(
  form.connection_string || '',
  /^(?:http:\/\/|https:\/\/|env\.[A-Z_]+)$/,
  'Connection URL must start with http://, https://, or be an environment variable (env.VAR_NAME)',
),

Changes Made

  1. Convert capturing group to non-capturing group: (?:...)
  2. Move the end-of-string anchor $ outside the group to apply to all alternatives

References

Impact

This is a validation bug that could allow malformed URLs to be accepted during MCP client configuration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions