Connection String Input

Masks a database URL's password and reads back the host, user and TLS mode the driver will actually use, so it doesn't fail or connect insecurely.

StopsDatabase URL leaks or skips TLS

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/connection-string-input.json

The files land in your project. They're yours to edit.

Usage

connection-string-input-usage.tsx
import { ConnectionStringInput } from "@/components/ui/connection-string-input"

return <ConnectionStringInput environment="production" defaultValue={'DATABASE_URL="postgres://app:Tr0ub4dor@3#x@db.prod.example.com:5432/shop"'} />

What it catches

  • Unencoded @, #, / or % in the password, naming the host a strict parser would use
  • Missing, weak or misspelled sslmode, and sslrootcert=system with a weaker mode
  • localhost in production and a port that belongs to another database
  • redis:// and MongoDB URLs without TLS (including mongodb+srv with tls=false)
  • Quotes or KEY= pasted from a .env file

Props

ConnectionStringInput props
PropTypeDefault
value

Controlled connection URL.

string—
defaultValue

Initial connection URL when uncontrolled.

string""
onValueChange

Called with the text on every edit or fix.

(value: string) => void—
environment

Where this URL will be used. Production turns localhost and missing TLS into problems.

DbEnvironment"production"
label

Visible label; shorthand for `messages.label`.

string—
messages

Every visible string. `{host}`, `{chars}`, `{mode}` and the other placeholders are filled in.

Partial<ConnectionStringInputMessages>—
name

Form field name. The real (unmasked) URL is submitted through a hidden input, since the visible one is masked when blurred.

string—

* required. Also accepts the native props of <input> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Visible <label>; aria-invalid and aria-describedby to a role="status" summary
  • Readback is a section labelled by its heading
  • Copy-masked button announces "Copied" in an aria-live="polite" span
  • After a fix, focus moves to the next fix or back to the field

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

This is a UX guard rail. Enforce on the server: Keep connection strings in a secrets manager and enforce TLS on the database server itself.

  • Parses the URL text; it doesn't try to connect or check credentials
  • Covers PostgreSQL (libpq), MySQL, MongoDB and Redis URL forms; other drivers may parse differently
  • Masking is visual: the full password is still in the value you receive

Rules

Rules last verified:

Informational. Checked libpq sslmode values (prefer is the default) and that sslrootcert=system requires verify-full. MongoDB, MySQL and Redis conventions were not re-checked. Copied components don't update themselves, so re-check after rule changes (see updating a component).

What it stops

Database URL leaks or skips TLS

Also known as

database url · DATABASE_URL · postgres uri · mongodb+srv · redis url · dsn · sslmode · connection string

Field type

Dependencies

Pairs well with