Skip to content

The open alternative to Salesforce, designed for AI.

Prevent stale credentials in IMAP input (#27048)

BOHEUS1576c484f232
diff --git a/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsConnectionForm.tsx b/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsConnectionForm.tsx
index 281e38c6829..2c04ed48229 100644
--- a/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsConnectionForm.tsx
+++ b/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsConnectionForm.tsx
@@ -157,6 +157,7 @@ export const SettingsAccountsConnectionForm = ({
render={({ field, fieldState }) => (
<SettingsTextInput
instanceId="imap-username-connection-form"
+ ignorePasswordManagers
label={t`IMAP Username (Optional)`}
placeholder={t`john.doe`}
type="text"
@@ -254,6 +255,7 @@ export const SettingsAccountsConnectionForm = ({
render={({ field, fieldState }) => (
<SettingsTextInput
instanceId="smtp-username-connection-form"
+ ignorePasswordManagers
label={t`SMTP Username`}
placeholder={t`john.doe`}
type="text"
@@ -350,6 +352,7 @@ export const SettingsAccountsConnectionForm = ({
render={({ field, fieldState }) => (
<SettingsTextInput
instanceId="caldav-username-connection-form"
+ ignorePasswordManagers
label={t`CalDAV Username`}
placeholder={t`john.doe`}
required={false}
diff --git a/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsPasswordController.tsx b/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsPasswordController.tsx
index 463e399eeaa..bd7d762384b 100644
--- a/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsPasswordController.tsx
+++ b/packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsPasswordController.tsx
@@ -47,6 +47,8 @@ export const SettingsAccountsPasswordController = ({
label={label}
placeholder={disabled ? MASKED_PASSWORD_PLACEHOLDER : ''}
type={disabled ? 'text' : 'password'}
+ autoComplete="new-password"
+ ignorePasswordManagers
value={field.value || ''}
onChange={field.onChange}
error={fieldState.error?.message}
diff --git a/packages/twenty-front/src/modules/settings/accounts/components/__tests__/SettingsAccountsConnectionForm.test.tsx b/packages/twenty-front/src/modules/settings/accounts/components/__tests__/SettingsAccountsConnectionForm.test.tsx
new file mode 100644
index 00000000000..8ce39fe9103
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/accounts/components/__tests__/SettingsAccountsConnectionForm.test.tsx
@@ -0,0 +1,87 @@
+import { i18n } from '@lingui/core';
+import { I18nProvider } from '@lingui/react';
+import { render, screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { createStore, Provider } from 'jotai';
+import { useForm } from 'react-hook-form';
+import { type AccountType } from 'twenty-shared/constants';
+
+import { SettingsAccountsConnectionForm } from '@/settings/accounts/components/SettingsAccountsConnectionForm';
+import { PASSWORD_MANAGER_IGNORE_ATTRIBUTES } from '@/ui/input/constants/PasswordManagerIgnoreAttributes';
+import { type ConnectionFormData } from '@/settings/accounts/hooks/useImapSmtpCaldavConnectionForm';
+
+type ConnectionFormWrapperProps = {
+ existingProtocols?: AccountType[];
+};
+
+const ConnectionFormWrapper = ({
+ existingProtocols,
+}: ConnectionFormWrapperProps) => {
+ const { control } = useForm<ConnectionFormData>();
+
+ return (
+ <SettingsAccountsConnectionForm
+ control={control}
+ isEditing={existingProtocols !== undefined}
+ existingProtocols={existingProtocols}
+ />
+ );
+};
+
+const renderConnectionForm = (existingProtocols?: AccountType[]) =>
+ render(
+ <Provider store={createStore()}>
+ <I18nProvider i18n={i18n}>
+ <ConnectionFormWrapper existingProtocols={existingProtocols} />
+ </I18nProvider>
+ </Provider>,
+ );
+
+it('opts every password out of saved-login autofill when creating an account', () => {
+ renderConnectionForm();
+
+ for (const protocol of ['IMAP', 'SMTP', 'CalDAV']) {
+ expect(screen.getByLabelText(`${protocol} Password`)).toHaveAttribute(
+ 'autocomplete',
+ 'new-password',
+ );
+ }
+});
+
+const expectPasswordManagersIgnored = (input: HTMLElement) => {
+ for (const [attribute, value] of Object.entries(
+ PASSWORD_MANAGER_IGNORE_ATTRIBUTES,
+ )) {
+ expect(input).toHaveAttribute(attribute, String(value));
+ }
+};
+
+it('opts every credential field out of third-party password managers', () => {
+ renderConnectionForm();
+
+ for (const label of [
+ 'IMAP Username (Optional)',
+ 'IMAP Password',
+ 'SMTP Username',
+ 'SMTP Password',
+ 'CalDAV Username',
+ 'CalDAV Password',
+ ]) {
+ expectPasswordManagersIgnored(screen.getByLabelText(label));
+ }
+});
+
+it('keeps saved-login autofill out of an unlocked password when editing an account', async () => {
+ renderConnectionForm(['IMAP']);
+
+ await userEvent.click(
+ screen.getByRole('button', { name: 'Change password' }),
+ );
+
+ const imapPassword = screen.getByLabelText('IMAP Password');
+
+ expect(imapPassword).toBeEnabled();
+ expect(imapPassword).toHaveAttribute('type', 'password');
+ expect(imapPassword).toHaveAttribute('autocomplete', 'new-password');
+ expectPasswordManagersIgnored(imapPassword);
+});
diff --git a/packages/twenty-front/src/modules/settings/accounts/hooks/useConnectedImapSmtpCaldavAccount.ts b/packages/twenty-front/src/modules/settings/accounts/hooks/useConnectedImapSmtpCaldavAccount.ts
index 61e933983ba..2d480401d2a 100644
--- a/packages/twenty-front/src/modules/settings/accounts/hooks/useConnectedImapSmtpCaldavAccount.ts
+++ b/packages/twenty-front/src/modules/settings/accounts/hooks/useConnectedImapSmtpCaldavAccount.ts
@@ -15,6 +15,7 @@ export const useConnectedImapSmtpCaldavAccount = (
{
variables: { id: connectedAccountId ?? '' },
skip: !connectedAccountId,
+ fetchPolicy: 'network-only',
},
);
diff --git a/packages/twenty-front/src/modules/ui/input/components/TextInput.tsx b/packages/twenty-front/src/modules/ui/input/components/TextInput.tsx
index 5874b64eb45..7772dfd5a51 100644
--- a/packages/twenty-front/src/modules/ui/input/components/TextInput.tsx
+++ b/packages/twenty-front/src/modules/ui/input/components/TextInput.tsx
@@ -17,6 +17,7 @@ import { Field } from 'twenty-ui/primitives/input';
import { useTheme, themeCssVariables } from 'twenty-ui/theme';
import { useCombinedRefs } from '~/hooks/useCombinedRefs';
import { turnIntoEmptyStringIfWhitespacesOnly } from '~/utils/string/turnIntoEmptyStringIfWhitespacesOnly';
+import { PASSWORD_MANAGER_IGNORE_ATTRIBUTES } from '@/ui/input/constants/PasswordManagerIgnoreAttributes';
const StyledContainer = styled.div<Pick<TextInputComponentProps, 'fullWidth'>>`
box-sizing: border-box;
display: inline-flex;
@@ -259,6 +260,7 @@ export type TextInputComponentProps = Omit<
rightAdornment?: string;
leftAdornment?: string;
textClickOutsideId?: string;
+ ignorePasswordManagers?: boolean;
};
type TextInputWithAutoGrowWrapperProps = TextInputComponentProps;
@@ -300,6 +302,7 @@ const TextInputComponent = forwardRef<
rightAdornment,
leftAdornment,
textClickOutsideId,
+ ignorePasswordManagers = false,
},
ref,
) => {
@@ -362,6 +365,9 @@ const TextInputComponent = forwardRef<
width={width}
data-testid={dataTestId}
autoComplete={autoComplete ?? 'off'}
+ // oxlint-disable-next-line react/jsx-props-no-spreading
+ {...(ignorePasswordManagers &&
+ PASSWORD_MANAGER_IGNORE_ATTRIBUTES)}
ref={combinedRef}
tabIndex={tabIndex ?? 0}
onFocus={handleFocus}
diff --git a/packages/twenty-front/src/modules/ui/input/constants/PasswordManagerIgnoreAttributes.ts b/packages/twenty-front/src/modules/ui/input/constants/PasswordManagerIgnoreAttributes.ts
new file mode 100644
index 00000000000..4bd5df56208
--- /dev/null
+++ b/packages/twenty-front/src/modules/ui/input/constants/PasswordManagerIgnoreAttributes.ts
@@ -0,0 +1,7 @@
+// Third-party password managers ignore the autocomplete attribute and only honor their own opt-outs
+export const PASSWORD_MANAGER_IGNORE_ATTRIBUTES = {
+ 'data-1p-ignore': true,
+ 'data-lpignore': 'true',
+ 'data-bwignore': true,
+ 'data-form-type': 'other',
+} as const;