Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Warn for certain symbols in database passwords (#33210)

Joshen Lima71bab0f1c29
diff --git a/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.constants.ts b/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.constants.ts
index c4be80a973e..323ee0082d6 100644
--- a/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.constants.ts
+++ b/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.constants.ts
@@ -252,3 +252,5 @@ export const COUNTRY_LAT_LON = {
ZM: { lat: -15, lon: 30 },
ZW: { lat: -20, lon: 30 },
}
+
+export const SPECIAL_CHARS_REGEX = /^[^@:\/]*$/
diff --git a/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.test.ts b/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.test.ts
new file mode 100644
index 00000000000..289c0475604
--- /dev/null
+++ b/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.test.ts
@@ -0,0 +1,10 @@
+import { expect, test } from 'vitest'
+import { SPECIAL_CHARS_REGEX } from './ProjectCreation.constants'
+
+test('Regex test to surface if password contains @, : or /', () => {
+ expect(!'teststring'.match(SPECIAL_CHARS_REGEX)).toEqual(false)
+ expect(!'test@string'.match(SPECIAL_CHARS_REGEX)).toEqual(true)
+ expect(!'te:ststring'.match(SPECIAL_CHARS_REGEX)).toEqual(true)
+ expect(!`tests/tring`.match(SPECIAL_CHARS_REGEX)).toEqual(true)
+ expect(!'!#$%^&*()'.match(SPECIAL_CHARS_REGEX)).toEqual(false)
+})
diff --git a/apps/studio/components/interfaces/ProjectCreation/SpecialSymbolsCallout.tsx b/apps/studio/components/interfaces/ProjectCreation/SpecialSymbolsCallout.tsx
new file mode 100644
index 00000000000..eb75fb4fe87
--- /dev/null
+++ b/apps/studio/components/interfaces/ProjectCreation/SpecialSymbolsCallout.tsx
@@ -0,0 +1,13 @@
+import { InlineLink } from 'components/ui/InlineLink'
+
+export const SpecialSymbolsCallout = () => {
+ return (
+ <p className="mb-2">
+ Note: If using the Postgres connection string, you will need to{' '}
+ <InlineLink href="https://supabase.com/docs/guides/database/postgres/roles#special-symbols-in-passwords">
+ percent-encode
+ </InlineLink>{' '}
+ the password
+ </p>
+ )
+}
diff --git a/apps/studio/pages/new/[slug].tsx b/apps/studio/pages/new/[slug].tsx
index 815788324bf..ab20c910827 100644
--- a/apps/studio/pages/new/[slug].tsx
+++ b/apps/studio/pages/new/[slug].tsx
@@ -22,8 +22,10 @@ import {
PostgresVersionSelector,
extractPostgresVersionDetails,
} from 'components/interfaces/ProjectCreation/PostgresVersionSelector'
+import { SPECIAL_CHARS_REGEX } from 'components/interfaces/ProjectCreation/ProjectCreation.constants'
import { RegionSelector } from 'components/interfaces/ProjectCreation/RegionSelector'
import { SecurityOptions } from 'components/interfaces/ProjectCreation/SecurityOptions'
+import { SpecialSymbolsCallout } from 'components/interfaces/ProjectCreation/SpecialSymbolsCallout'
import { WizardLayoutWithoutAuth } from 'components/layouts/WizardLayout'
import DisabledWarningDueToIncident from 'components/ui/DisabledWarningDueToIncident'
import Panel from 'components/ui/Panel'
@@ -119,9 +121,7 @@ const FormSchema = z.object({
}),
dbPassStrength: z.number(),
dbPass: z
- .string({
- required_error: 'Please enter a database password.',
- })
+ .string({ required_error: 'Please enter a database password.' })
.min(1, 'Password is required.'),
instanceSize: z.string(),
dataApi: z.boolean(),
@@ -781,41 +781,49 @@ const Wizard: NextPageWithLayout = () => {
<FormField_Shadcn_
control={form.control}
name="dbPass"
- render={({ field }) => (
- <FormItemLayout
- label="Database Password"
- layout="horizontal"
- description={
- <PasswordStrengthBar
- passwordStrengthScore={form.getValues('dbPassStrength')}
- password={field.value}
- passwordStrengthMessage={passwordStrengthMessage}
- generateStrongPassword={generatePassword}
- />
- }
- >
- <FormControl_Shadcn_>
- <Input
- copy={field.value.length > 0}
- type="password"
- placeholder="Type in a strong password"
- {...field}
- autoComplete="off"
- onChange={async (event) => {
- field.onChange(event)
- form.trigger('dbPassStrength')
- const value = event.target.value
- if (event.target.value === '') {
- await form.setValue('dbPassStrength', 0)
- await form.trigger('dbPass')
- } else {
- await delayedCheckPasswordStrength(value)
- }
- }}
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
+ render={({ field }) => {
+ const hasSpecialCharacters =
+ field.value.length > 0 && !field.value.match(SPECIAL_CHARS_REGEX)
+
+ return (
+ <FormItemLayout
+ label="Database Password"
+ layout="horizontal"
+ description={
+ <>
+ {hasSpecialCharacters && <SpecialSymbolsCallout />}
+ <PasswordStrengthBar
+ passwordStrengthScore={form.getValues('dbPassStrength')}
+ password={field.value}
+ passwordStrengthMessage={passwordStrengthMessage}
+ generateStrongPassword={generatePassword}
+ />
+ </>
+ }
+ >
+ <FormControl_Shadcn_>
+ <Input
+ copy={field.value.length > 0}
+ type="password"
+ placeholder="Type in a strong password"
+ {...field}
+ autoComplete="off"
+ onChange={async (event) => {
+ field.onChange(event)
+ form.trigger('dbPassStrength')
+ const value = event.target.value
+ if (event.target.value === '') {
+ await form.setValue('dbPassStrength', 0)
+ await form.trigger('dbPass')
+ } else {
+ await delayedCheckPasswordStrength(value)
+ }
+ }}
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )
+ }}
/>
</Panel.Content>
diff --git a/apps/studio/pages/new/v2/[slug].tsx b/apps/studio/pages/new/v2/[slug].tsx
index 68a344d7ff3..85820e04dc9 100644
--- a/apps/studio/pages/new/v2/[slug].tsx
+++ b/apps/studio/pages/new/v2/[slug].tsx
@@ -14,6 +14,7 @@ import { toast } from 'sonner'
import { z } from 'zod'
import { PopoverSeparator } from '@ui/components/shadcn/ui/popover'
+import { TelemetryActions } from 'common/telemetry-constants'
import {
FreeProjectLimitWarning,
NotOrganizationOwnerWarning,
@@ -24,10 +25,12 @@ import {
PostgresVersionSelector,
extractPostgresVersionDetails,
} from 'components/interfaces/ProjectCreation/PostgresVersionSelector'
+import { SPECIAL_CHARS_REGEX } from 'components/interfaces/ProjectCreation/ProjectCreation.constants'
import { ProjectVisual } from 'components/interfaces/ProjectCreation/ProjectVisual'
import { RegionSelector } from 'components/interfaces/ProjectCreation/RegionSelector'
import { SchemaGenerator } from 'components/interfaces/ProjectCreation/SchemaGenerator'
import { SecurityOptions } from 'components/interfaces/ProjectCreation/SecurityOptions'
+import { SpecialSymbolsCallout } from 'components/interfaces/ProjectCreation/SpecialSymbolsCallout'
import { FeedbackDropdown } from 'components/layouts/ProjectLayout/LayoutHeader/FeedbackDropdown'
import HelpPopover from 'components/layouts/ProjectLayout/LayoutHeader/HelpPopover'
import DisabledWarningDueToIncident from 'components/ui/DisabledWarningDueToIncident'
@@ -61,7 +64,6 @@ import {
PROJECT_STATUS,
PROVIDERS,
} from 'lib/constants'
-import { TelemetryActions } from 'common/telemetry-constants'
import passwordStrength from 'lib/password-strength'
import { generateStrongPassword } from 'lib/project'
import type { CloudProvider } from 'shared-data'
@@ -128,9 +130,7 @@ const FormSchema = z.object({
}),
dbPassStrength: z.number(),
dbPass: z
- .string({
- required_error: 'Please enter a database password.',
- })
+ .string({ required_error: 'Please enter a database password.' })
.min(1, 'Password is required.'),
instanceSize: z.string(),
dataApi: z.boolean(),
@@ -160,7 +160,6 @@ const WizardForm = () => {
const [showVisual, setShowVisual] = useState(false)
const [step, setStep] = useState(1)
- const [aiDescription, setAiDescription] = useState('')
const [formTitle, setFormTitle] = useState('Create a new project')
const [formDescription, setFormDescription] = useState(
'Get started by choosing how you want to create your project'
@@ -534,7 +533,6 @@ const WizardForm = () => {
}
}}
onSubmit={(value) => {
- setAiDescription(value)
setFormTitle('Create a project')
setFormDescription(
'We have generated a starting schema for you based on your description'
@@ -716,40 +714,51 @@ const WizardForm = () => {
<FormField_Shadcn_
control={form.control}
name="dbPass"
- render={({ field }) => (
- <FormItemLayout
- label="Database Password"
- description={
- <PasswordStrengthBar
- passwordStrengthScore={form.getValues('dbPassStrength')}
- password={field.value}
- passwordStrengthMessage={passwordStrengthMessage}
- generateStrongPassword={generatePassword}
- />
- }
- >
- <FormControl_Shadcn_>
- <Input
- copy={field.value.length > 0}
- type="password"
- placeholder="Type in a strong password"
- {...field}
- autoComplete="off"
- onChange={async (event) => {
- field.onChange(event)
- form.trigger('dbPassStrength')
- const value = event.target.value
- if (event.target.value === '') {
- await form.setValue('dbPassStrength', 0)
- await form.trigger('dbPass')
- } else {
- await delayedCheckPasswordStrength(value)
- }
- }}
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
+ render={({ field }) => {
+ const hasSpecialCharacters =
+ field.value.length > 0 &&
+ !field.value.match(SPECIAL_CHARS_REGEX)
+
+ return (
+ <FormItemLayout
+ label="Database Password"
+ description={
+ <>
+ {hasSpecialCharacters && <SpecialSymbolsCallout />}
+ <PasswordStrengthBar
+ passwordStrengthScore={form.getValues(
+ 'dbPassStrength'
+ )}
+ password={field.value}
+ passwordStrengthMessage={passwordStrengthMessage}
+ generateStrongPassword={generatePassword}
+ />
+ </>
+ }
+ >
+ <FormControl_Shadcn_>
+ <Input
+ copy={field.value.length > 0}
+ type="password"
+ placeholder="Type in a strong password"
+ {...field}
+ autoComplete="off"
+ onChange={async (event) => {
+ field.onChange(event)
+ form.trigger('dbPassStrength')
+ const value = event.target.value
+ if (event.target.value === '') {
+ await form.setValue('dbPassStrength', 0)
+ await form.trigger('dbPass')
+ } else {
+ await delayedCheckPasswordStrength(value)
+ }
+ }}
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )
+ }}
/>
</div>
<div className="py-5 border-t border-b">
@@ -1168,9 +1177,13 @@ const WizardForm = () => {
form="project-create-form"
htmlType="submit"
size="large"
- loading={isCreatingNewProject}
- disabled={isCreatingNewProject || projectCreateBlocked}
className="w-full"
+ loading={isCreatingNewProject}
+ disabled={
+ !canCreateProject ||
+ isCreatingNewProject ||
+ projectCreateBlocked
+ }
>
{isCreatingNewProject ? 'Creating project...' : 'Create project'}
</Button>
@@ -1238,13 +1251,9 @@ const instanceLabel = (instance: string | undefined): string => {
}
const Wizard: NextPageWithLayout = () => {
- const { slug, projectName } = useParams()
-
- const { data: organizations, isSuccess: isOrganizationsSuccess } = useOrganizationsQuery()
- const currentOrg = organizations?.find((o: any) => o.slug === slug)
-
- const { data: membersExceededLimit, isLoading: isLoadingFreeProjectLimitCheck } =
- useFreeProjectLimitCheckQuery({ slug })
+ const { slug } = useParams()
+ const { isSuccess: isOrganizationsSuccess } = useOrganizationsQuery()
+ const { isLoading: isLoadingFreeProjectLimitCheck } = useFreeProjectLimitCheckQuery({ slug })
if (!isOrganizationsSuccess || isLoadingFreeProjectLimitCheck) return null