Skip to content

The open alternative to Salesforce, designed for AI.

fix(front): open field links with noopener to prevent reverse tabnabbing (#26643)

Aditya Mishra709045e76e80
diff --git a/packages/twenty-front/.oxlintrc.json b/packages/twenty-front/.oxlintrc.json
index bafe1b2bac2..640fc43acda 100644
--- a/packages/twenty-front/.oxlintrc.json
+++ b/packages/twenty-front/.oxlintrc.json
@@ -124,6 +124,7 @@
"twenty/no-state-useref": "error",
"twenty/component-props-naming": "error",
"twenty/no-navigate-prefer-link": "error",
+ "twenty/no-window-open": "error",
"twenty/no-jotai-store-in-selector": "error",
"twenty/no-direct-atom-family-in-selector": "error",
"twenty/folder-structure": "error",
@@ -161,6 +162,15 @@
"react/jsx-props-no-spreading": "off"
}
},
+ {
+ "files": [
+ "src/utils/openUrlInNewTab.ts",
+ "src/modules/domain-manager/hooks/useRedirect.ts"
+ ],
+ "rules": {
+ "twenty/no-window-open": "off"
+ }
+ },
{
"files": ["**/constants/*.ts", "**/*.constants.ts"],
"rules": {
diff --git a/packages/twenty-front/src/modules/activities/emails/hooks/useOpenEmailInAppOrFallback.ts b/packages/twenty-front/src/modules/activities/emails/hooks/useOpenEmailInAppOrFallback.ts
index db5057870cc..cd59c0e4998 100644
--- a/packages/twenty-front/src/modules/activities/emails/hooks/useOpenEmailInAppOrFallback.ts
+++ b/packages/twenty-front/src/modules/activities/emails/hooks/useOpenEmailInAppOrFallback.ts
@@ -3,6 +3,7 @@ import { useCallback } from 'react';
import { useFirstConnectedAccount } from '@/activities/emails/hooks/useFirstConnectedAccount';
import { useOpenComposeEmailInSidePanel } from '@/side-panel/hooks/useOpenComposeEmailInSidePanel';
import { isDefined } from 'twenty-shared/utils';
+import { openUrlInNewTab } from '~/utils/openUrlInNewTab';
type UseOpenEmailInAppOrFallbackOptions = {
skip?: boolean;
@@ -29,7 +30,7 @@ export const useOpenEmailInAppOrFallback = (
return;
}
- window.open(`mailto:${email}`, '_blank');
+ openUrlInNewTab(`mailto:${email}`);
},
[connectedAccountId, openComposeEmailInSidePanel],
);
diff --git a/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx b/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx
index bc997e973c7..14748863e8f 100644
--- a/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx
+++ b/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx
@@ -24,6 +24,7 @@ import { useTheme, themeCssVariables } from 'twenty-ui/theme';
import { PermissionFlagType } from '~/generated-metadata/graphql';
import { formatToHumanReadableDate } from '~/utils/date-utils';
import { getFileNameAndExtension } from '~/utils/file/getFileNameAndExtension';
+import { openUrlInNewTab } from '~/utils/openUrlInNewTab';
const StyledLeftContent = styled.div`
align-items: center;
@@ -168,7 +169,7 @@ export const AttachmentRow = ({
return;
}
- window.open(safeFileUrl, '_blank', 'noopener,noreferrer');
+ openUrlInNewTab(safeFileUrl);
};
const handleFileLinkClick = (event: React.MouseEvent<HTMLAnchorElement>) => {
diff --git a/packages/twenty-front/src/modules/advanced-text-editor/components/LinkBubbleMenu.tsx b/packages/twenty-front/src/modules/advanced-text-editor/components/LinkBubbleMenu.tsx
index bb061f85838..df42d695ef3 100644
--- a/packages/twenty-front/src/modules/advanced-text-editor/components/LinkBubbleMenu.tsx
+++ b/packages/twenty-front/src/modules/advanced-text-editor/components/LinkBubbleMenu.tsx
@@ -8,6 +8,7 @@ import { type Editor } from '@tiptap/core';
import { BubbleMenu } from '@tiptap/react/menus';
import { IconExternalLink, IconLinkOff } from 'twenty-ui/icon';
import { getSafeUrl } from 'twenty-shared/utils';
+import { openUrlInNewTab } from '~/utils/openUrlInNewTab';
type LinkBubbleMenuProps = {
editor: Editor;
@@ -32,7 +33,7 @@ export const LinkBubbleMenu = ({ editor }: LinkBubbleMenuProps) => {
const safeHref = getSafeUrl(state.linkHref);
if (safeHref) {
- window.open(safeHref, '_blank', 'noopener,noreferrer');
+ openUrlInNewTab(safeHref);
}
},
},
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatApiKeyNotConfiguredMessage.tsx b/packages/twenty-front/src/modules/ai/components/AiChatApiKeyNotConfiguredMessage.tsx
index 9fc67c3ff54..77afd97c1b4 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatApiKeyNotConfiguredMessage.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatApiKeyNotConfiguredMessage.tsx
@@ -6,6 +6,7 @@ import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomState
import { t } from '@lingui/core/macro';
import { DOCUMENTATION_PATHS } from 'twenty-shared/constants';
import { IconExternalLink } from 'twenty-ui/icon';
+import { openUrlInNewTab } from '~/utils/openUrlInNewTab';
export const AiChatApiKeyNotConfiguredMessage = () => {
const currentWorkspaceMember = useAtomStateValue(currentWorkspaceMemberState);
@@ -15,7 +16,7 @@ export const AiChatApiKeyNotConfiguredMessage = () => {
locale: currentWorkspaceMember?.locale,
path: DOCUMENTATION_PATHS.DEVELOPERS_SELF_HOST_CAPABILITIES_SETUP,
});
- window.open(docsUrl, '_blank', 'noopener,noreferrer');
+ openUrlInNewTab(docsUrl);
};
return (
diff --git a/packages/twenty-front/src/modules/auth/sign-in-up/components/EmailVerificationSent.tsx b/packages/twenty-front/src/modules/auth/sign-in-up/components/EmailVerificationSent.tsx
index 4a7d296c37b..fdc031616bc 100644
--- a/packages/twenty-front/src/modules/auth/sign-in-up/components/EmailVerificationSent.tsx
+++ b/packages/twenty-front/src/modules/auth/sign-in-up/components/EmailVerificationSent.tsx
@@ -14,6 +14,7 @@ import { t } from '@lingui/core/macro';
import { MainButton } from 'twenty-ui/components/input';
import { IconGmail, IconMail, IconMailX, IconMicrosoft } from 'twenty-ui/icon';
import { themeCssVariables } from 'twenty-ui/theme';
+import { openUrlInNewTab } from '~/utils/openUrlInNewTab';
const StyledContainer = styled.div`
align-items: center;
@@ -95,14 +96,14 @@ export const EmailVerificationSent = ({
const gmailUrl = email
? `https://mail.google.com/mail/u/${email}/`
: 'https://mail.google.com/';
- window.open(gmailUrl, '_blank');
+ openUrlInNewTab(gmailUrl);
};
const handleOpenOutlook = () => {
const outlookUrl = email
? `https://outlook.live.com/mail/${email}/`
: 'https://outlook.live.com/';
- window.open(outlookUrl, '_blank');
+ openUrlInNewTab(outlookUrl);
};
const handleChangeEmail = () => {
diff --git a/packages/twenty-front/src/modules/information-banner/components/maintenance/InformationBannerMaintenance.tsx b/packages/twenty-front/src/modules/information-banner/components/maintenance/InformationBannerMaintenance.tsx
index be7d3b42c44..7695f616655 100644
--- a/packages/twenty-front/src/modules/information-banner/components/maintenance/InformationBannerMaintenance.tsx
+++ b/packages/twenty-front/src/modules/information-banner/components/maintenance/InformationBannerMaintenance.tsx
@@ -8,6 +8,7 @@ import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomState
import { t } from '@lingui/core/macro';
import { getSafeUrl, isDefined } from 'twenty-shared/utils';
import { IconExternalLink } from 'twenty-ui/icon';
+import { openUrlInNewTab } from '~/utils/openUrlInNewTab';
const formatMaintenanceDateTime = (
isoString: string,
@@ -59,7 +60,7 @@ export const InformationBannerMaintenance = () => {
buttonIcon={isDefined(maintenanceLink) ? IconExternalLink : undefined}
buttonOnClick={
isDefined(maintenanceLink)
- ? () => window.open(maintenanceLink, '_blank', 'noopener,noreferrer')
+ ? () => openUrlInNewTab(maintenanceLink)
: undefined
}
onClose={dismissBanner}
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/common/hooks/useNavigateToNavigationMenuItemLink.ts b/packages/twenty-front/src/modules/navigation-menu-item/common/hooks/useNavigateToNavigationMenuItemLink.ts
index 2fd26052072..e464432209d 100644
--- a/packages/twenty-front/src/modules/navigation-menu-item/common/hooks/useNavigateToNavigationMenuItemLink.ts
+++ b/packages/twenty-front/src/modules/navigation-menu-item/common/hooks/useNavigateToNavigationMenuItemLink.ts
@@ -1,12 +1,13 @@
import { useNavigate } from 'react-router-dom';
import { isAbsoluteUrl } from 'twenty-shared/utils';
+import { openUrlInNewTab } from '~/utils/openUrlInNewTab';
export const useNavigateToNavigationMenuItemLink = () => {
const navigate = useNavigate();
const navigateToNavigationMenuItemLink = (link: string) => {
if (isAbsoluteUrl(link)) {
- window.open(link, '_blank', 'noopener,noreferrer');
+ openUrlInNewTab(link);
return;
}
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/hooks/useGetSecondaryFieldButton.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/hooks/useGetSecondaryFieldButton.ts
index c906f811a9d..87979a0a24e 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/hooks/useGetSecondaryFieldButton.ts
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/hooks/useGetSecondaryFieldButton.ts
@@ -15,6 +15,7 @@ import { FieldMetadataSettingsOnClickAction } from 'twenty-shared/types';
import { ensureAbsoluteUrl, isDefined } from 'twenty-shared/utils';
import { IconArrowUpRight, IconCopy, IconMail } from 'twenty-ui/icon';
import { useCopyToClipboard } from '~/hooks/useCopyToClipboard';
+import { openUrlInNewTab } from '~/utils/openUrlInNewTab';
export const useGetSecondaryFieldButton = () => {
const { fieldDefinition, recordId } = useContext(FieldContext);
@@ -62,7 +63,7 @@ export const useGetSecondaryFieldButton = () => {
fieldValue as FieldPhonesValue;
const phoneNumber = `${primaryPhoneCallingCode}${primaryPhoneNumber}`;
openLinkOnClick = () => {
- window.open(`tel:${phoneNumber}`, '_blank');
+ openUrlInNewTab(`tel:${phoneNumber}`);
};
copyOnClick = () => {
copyToClipboard(phoneNumber, t`Phone number copied to clipboard`);
@@ -72,7 +73,7 @@ export const useGetSecondaryFieldButton = () => {
if (isFieldEmails(fieldDefinition)) {
const email = (fieldValue as FieldEmailsValue).primaryEmail ?? '';
openLinkOnClick = () => {
- window.open(`mailto:${email}`, '_blank');
+ openUrlInNewTab(`mailto:${email}`);
};
copyOnClick = () => {
copyToClipboard(email, t`Email copied to clipboard`);
@@ -85,7 +86,7 @@ export const useGetSecondaryFieldButton = () => {
if (isFieldLinks(fieldDefinition)) {
const url = (fieldValue as FieldLinksValue).primaryLinkUrl ?? '';
openLinkOnClick = () => {
- window.open(ensureAbsoluteUrl(url), '_blank');
+ openUrlInNewTab(ensureAbsoluteUrl(url));
};
copyOnClick = () => {
copyToClipboard(url, t`Link copied to clipboard`);
diff --git a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingCreditsSection.tsx b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingCreditsSection.tsx
index d9213c703af..3dea0ed8ed9 100644
--- a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingCreditsSection.tsx
+++ b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingCreditsSection.tsx
@@ -37,6 +37,7 @@ import {
PermissionFlagType,
SubscriptionStatus,
} from '~/generated-metadata/graphql';
+import { openUrlInNewTab } from '~/utils/openUrlInNewTab';
const MIN_VISIBLE_EMPTY_CREDIT_PROGRESS_PERCENTAGE = 4;
@@ -314,13 +315,7 @@ export const SettingsBillingCreditsSection = ({
<Button
startIcon={<IconExternalLink />}
size="sm"
- onClick={() =>
- window.open(
- creditsDocumentationUrl,
- '_blank',
- 'noopener,noreferrer',
- )
- }
+ onClick={() => openUrlInNewTab(creditsDocumentationUrl)}
variant="outline"
>{t`How credits work`}</Button>
</StyledCreditUsageFooterActions>
diff --git a/packages/twenty-front/src/modules/settings/enterprise/components/EnterprisePlanModal.tsx b/packages/twenty-front/src/modules/settings/enterprise/components/EnterprisePlanModal.tsx
index 8bb58bea8d2..a0151582d27 100644
--- a/packages/twenty-front/src/modules/settings/enterprise/components/EnterprisePlanModal.tsx
+++ b/packages/twenty-front/src/modules/settings/enterprise/components/EnterprisePlanModal.tsx
@@ -16,6 +16,7 @@ import { Radio, RadioGroup } from 'twenty-ui/primitives/input';
import { Dialog } from 'twenty-ui/primitives/surfaces';
import { themeCssVariables } from 'twenty-ui/theme';
import { getErrorMessageFromApolloError } from '~/utils/get-error-message-from-apollo-error.util';
+import { openUrlInNewTab } from '~/utils/openUrlInNewTab';
const StyledCheckoutButton = styled(MainButton)`
width: 200px;
@@ -131,7 +132,7 @@ export const EnterprisePlanModal = () => {
const checkoutUrl = data?.enterpriseCheckoutSession;
if (checkoutUrl !== null && checkoutUrl !== undefined) {
- window.open(checkoutUrl, '_blank', 'noopener');
+ openUrlInNewTab(checkoutUrl);
closeDialog(ENTERPRISE_PLAN_MODAL_ID);
} else {
enqueueToast({
diff --git a/packages/twenty-front/src/modules/settings/hooks/useSettingsNavigationItems.tsx b/packages/twenty-front/src/modules/settings/hooks/useSettingsNavigationItems.tsx
index 590c61b2079..c713806dbb0 100644
--- a/packages/twenty-front/src/modules/settings/hooks/useSettingsNavigationItems.tsx
+++ b/packages/twenty-front/src/modules/settings/hooks/useSettingsNavigationItems.tsx
@@ -34,6 +34,7 @@ import {
IconUsers,
} from 'twenty-ui/icon';
import { PermissionFlagType } from '~/generated-metadata/graphql';
+import { openUrlInNewTab } from '~/utils/openUrlInNewTab';
export type SettingsNavigationSection = {
label: string;
@@ -204,9 +205,8 @@ const useSettingsNavigationItems = (): SettingsNavigationSection[] => {
{
label: t`Documentation`,
onClick: () =>
- window.open(
+ openUrlInNewTab(
getDocumentationUrl({ locale: currentWorkspaceMember?.locale }),
- '_blank',
),
Icon: IconHelpCircle,
},
diff --git a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerItem.tsx b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerItem.tsx
index 81c4e190d61..de073906349 100644
--- a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerItem.tsx
+++ b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerItem.tsx
@@ -25,6 +25,7 @@ import {
OverflowingTextWithTooltip,
} from 'twenty-ui/primitives/typography';
import { MOBILE_VIEWPORT, useTheme, themeCssVariables } from 'twenty-ui/theme';
+import { openUrlInNewTab } from '~/utils/openUrlInNewTab';
const DEFAULT_INDENTATION_LEVEL = 1;
type StyledItemProps = Pick<
@@ -254,7 +255,7 @@ export const NavigationDrawerItem = ({
const handleExternalLinkClick = () => {
handleMobileNavigation();
if (isDefined(to)) {
- window.open(to, '_blank', 'noopener,noreferrer');
+ openUrlInNewTab(to);
}
};
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormBuilder.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormBuilder.tsx
index 8277c5d319b..57335aafde0 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormBuilder.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormBuilder.tsx
@@ -36,6 +36,7 @@ import {
import { useTheme, themeCssVariables } from 'twenty-ui/theme';
import { useDebouncedCallback } from 'use-debounce';
import { v4 } from 'uuid';
+import { openUrlInNewTab } from '~/utils/openUrlInNewTab';
export type WorkflowEditActionFormBuilderProps = {
triggerType: WorkflowTriggerType | undefined;
@@ -280,10 +281,8 @@ export const WorkflowEditActionFormBuilder = ({
<Callout.Action
type="button"
onClick={() =>
- window.open(
+ openUrlInNewTab(
'https://docs.twenty.com/user-guide/workflows/capabilities/workflow-actions#form',
- '_blank',
- 'noopener,noreferrer',
)
}
>{t`Learn more`}</Callout.Action>
diff --git a/packages/twenty-front/src/pages/settings/applications/components/SettingsClaimApplicationSection.tsx b/packages/twenty-front/src/pages/settings/applications/components/SettingsClaimApplicationSection.tsx
index 5afc675c599..ca4c5ea0cf7 100644
--- a/packages/twenty-front/src/pages/settings/applications/components/SettingsClaimApplicationSection.tsx
+++ b/packages/twenty-front/src/pages/settings/applications/components/SettingsClaimApplicationSection.tsx
@@ -29,6 +29,7 @@ import {
SyncMarketplaceCatalogDocument,
} from '~/generated-metadata/graphql';
import { getClaimErrorContent } from '~/pages/settings/applications/utils/getClaimErrorContent';
+import { openUrlInNewTab } from '~/utils/openUrlInNewTab';
export const CLAIM_ERROR_CODE_SEARCH_PARAM = 'claimErrorCode';
@@ -234,12 +235,11 @@ export const SettingsClaimApplicationSection = () => {
<Callout.Action
type="button"
onClick={() =>
- window.open(
+ openUrlInNewTab(
getDocumentationUrl({
locale: currentWorkspaceMember?.locale,
path: claimError.docPath,
}),
- '_blank',
)
}
>{t`Read documentation`}</Callout.Action>
diff --git a/packages/twenty-front/src/pages/settings/applications/tabs/SettingsApplicationsDeveloperTab.tsx b/packages/twenty-front/src/pages/settings/applications/tabs/SettingsApplicationsDeveloperTab.tsx
index 9ca7eaac529..5f9e3961094 100644
--- a/packages/twenty-front/src/pages/settings/applications/tabs/SettingsApplicationsDeveloperTab.tsx
+++ b/packages/twenty-front/src/pages/settings/applications/tabs/SettingsApplicationsDeveloperTab.tsx
@@ -29,6 +29,7 @@ import {
SettingsApplicationTableRow,
} from '~/pages/settings/applications/components/SettingsApplicationTableRow';
import { SettingsClaimApplicationSection } from '~/pages/settings/applications/components/SettingsClaimApplicationSection';
+import { openUrlInNewTab } from '~/utils/openUrlInNewTab';
const StyledButtonContainer = styled.div`
display: flex;
@@ -105,12 +106,11 @@ export const SettingsApplicationsDeveloperTab = () => {
startIcon={<IconArrowUpRight />}
size="sm"
onClick={() =>
- window.open(
+ openUrlInNewTab(
getDocumentationUrl({
locale: currentWorkspaceMember?.locale,
path: '/developers/extend/apps/getting-started',
}),
- '_blank',
)
}
variant="outline"
diff --git a/packages/twenty-front/src/pages/settings/communications/SettingsWorkspaceCommunicationGroupChannelDetail.tsx b/packages/twenty-front/src/pages/settings/communications/SettingsWorkspaceCommunicationGroupChannelDetail.tsx
index a4e1ec3caee..12cd7a800c2 100644
--- a/packages/twenty-front/src/pages/settings/communications/SettingsWorkspaceCommunicationGroupChannelDetail.tsx
+++ b/packages/twenty-front/src/pages/settings/communications/SettingsWorkspaceCommunicationGroupChannelDetail.tsx
@@ -41,6 +41,7 @@ import { useNavigateSettings } from '~/hooks/useNavigateSettings';
import { NotFound } from '~/pages/not-found/NotFound';
import channelSetupCoverDark from '~/pages/settings/communications/assets/channel-setup-cover-dark.png';
import channelSetupCoverLight from '~/pages/settings/communications/assets/channel-setup-cover-light.png';
+import { openUrlInNewTab } from '~/utils/openUrlInNewTab';
const DELETE_EMAIL_GROUP_MODAL_ID = 'delete-email-group-channel-modal';
@@ -192,12 +193,11 @@ export const SettingsWorkspaceCommunicationGroupChannelDetail = () => {
size="sm"
endIcon={<IconArrowUpRight />}
onClick={() =>
- window.open(
+ openUrlInNewTab(
getDocumentationUrl({
locale: currentWorkspaceMember?.locale,
path: '/user-guide/calendar-emails/how-tos/forward-a-shared-inbox-from-any-mail-provider',
}),
- '_blank',
)
}
>{t`Read documentation`}</Button>
diff --git a/packages/twenty-front/src/pages/settings/enterprise/SettingsEnterprise.tsx b/packages/twenty-front/src/pages/settings/enterprise/SettingsEnterprise.tsx
index 88e56c7b07c..e0a40b3f776 100644
--- a/packages/twenty-front/src/pages/settings/enterprise/SettingsEnterprise.tsx
+++ b/packages/twenty-front/src/pages/settings/enterprise/SettingsEnterprise.tsx
@@ -45,6 +45,7 @@ import {
import { Button } from 'twenty-ui/primitives/input';
import { themeCssVariables } from 'twenty-ui/theme';
import { isGraphqlErrorOfType } from '~/utils/is-graphql-error-of-type.util';
+import { openUrlInNewTab } from '~/utils/openUrlInNewTab';
const RELEASE_ENTERPRISE_BINDING_CONFIRMATION_MODAL_ID =
'release-enterprise-binding-confirmation-modal';
@@ -341,7 +342,7 @@ export const SettingsEnterprise = ({
const portalUrl = data?.enterprisePortalSession;
if (portalUrl !== null && portalUrl !== undefined) {
- window.open(portalUrl, '_blank', 'noopener');
+ openUrlInNewTab(portalUrl);
} else {
enqueueToast({
variant: 'error',
diff --git a/packages/twenty-front/src/utils/openUrlInNewTab.ts b/packages/twenty-front/src/utils/openUrlInNewTab.ts
new file mode 100644
index 00000000000..41f5d7b0b27
--- /dev/null
+++ b/packages/twenty-front/src/utils/openUrlInNewTab.ts
@@ -0,0 +1,3 @@
+export const openUrlInNewTab = (url: string) => {
+ window.open(url, '_blank', 'noopener,noreferrer');
+};
diff --git a/packages/twenty-oxlint-rules/oxlint-plugin.ts b/packages/twenty-oxlint-rules/oxlint-plugin.ts
index 14f8ed61263..3e55a80682f 100644
--- a/packages/twenty-oxlint-rules/oxlint-plugin.ts
+++ b/packages/twenty-oxlint-rules/oxlint-plugin.ts
@@ -80,6 +80,10 @@ import {
rule as noStorybookA11yDisable,
RULE_NAME as noStorybookA11yDisableName,
} from './rules/no-storybook-a11y-disable';
+import {
+ rule as noWindowOpen,
+ RULE_NAME as noWindowOpenName,
+} from './rules/no-window-open';
import {
rule as preferWorkspaceScopedRepository,
RULE_NAME as preferWorkspaceScopedRepositoryName,
@@ -129,6 +133,7 @@ export default definePlugin({
[noRuntimeImportFromUpgradeCommandName]: noRuntimeImportFromUpgradeCommand,
[noStateUserefName]: noStateUseref,
[noStorybookA11yDisableName]: noStorybookA11yDisable,
+ [noWindowOpenName]: noWindowOpen,
[preferWorkspaceScopedRepositoryName]: preferWorkspaceScopedRepository,
[restApiMethodsShouldBeGuardedName]: restApiMethodsShouldBeGuarded,
[sortCssPropertiesAlphabeticallyName]: sortCssPropertiesAlphabetically,
diff --git a/packages/twenty-oxlint-rules/rules/no-window-open.spec.ts b/packages/twenty-oxlint-rules/rules/no-window-open.spec.ts
new file mode 100644
index 00000000000..10c7db4eff3
--- /dev/null
+++ b/packages/twenty-oxlint-rules/rules/no-window-open.spec.ts
@@ -0,0 +1,33 @@
+import { RuleTester } from 'oxlint/plugins-dev';
+
+import { rule, RULE_NAME } from './no-window-open';
+
+const ruleTester = new RuleTester();
+
+ruleTester.run(RULE_NAME, rule, {
+ valid: [
+ {
+ code: 'openUrlInNewTab(url);',
+ },
+ {
+ code: 'popup.open(url);',
+ },
+ {
+ code: 'const open = () => {}; open(url);',
+ },
+ ],
+ invalid: [
+ {
+ code: "window.open(url, '_blank');",
+ errors: [{ messageId: 'noWindowOpen' }],
+ },
+ {
+ code: "window.open(url, '_blank', 'noopener,noreferrer');",
+ errors: [{ messageId: 'noWindowOpen' }],
+ },
+ {
+ code: "window['open'](url);",
+ errors: [{ messageId: 'noWindowOpen' }],
+ },
+ ],
+});
diff --git a/packages/twenty-oxlint-rules/rules/no-window-open.ts b/packages/twenty-oxlint-rules/rules/no-window-open.ts
new file mode 100644
index 00000000000..eb6bfa2f317
--- /dev/null
+++ b/packages/twenty-oxlint-rules/rules/no-window-open.ts
@@ -0,0 +1,36 @@
+import { defineRule } from '@oxlint/plugins';
+
+export const RULE_NAME = 'no-window-open';
+
+const isWindowOpenCallee = (callee: any): boolean =>
+ callee.type === 'MemberExpression' &&
+ callee.object.type === 'Identifier' &&
+ callee.object.name === 'window' &&
+ ((!callee.computed &&
+ callee.property.type === 'Identifier' &&
+ callee.property.name === 'open') ||
+ (callee.computed &&
+ callee.property.type === 'Literal' &&
+ callee.property.value === 'open'));
+
+export const rule = defineRule({
+ meta: {
+ type: 'problem',
+ docs: {
+ description:
+ 'Disallow window.open() so new tabs are always opened without access to the Twenty tab.',
+ },
+ messages: {
+ noWindowOpen:
+ "Use openUrlInNewTab from '~/utils/openUrlInNewTab' instead of window.open(): it sets noopener and noreferrer so the opened page cannot navigate the Twenty tab.",
+ },
+ schema: [],
+ },
+ create: (context) => ({
+ CallExpression: (node: any) => {
+ if (isWindowOpenCallee(node.callee)) {
+ context.report({ node, messageId: 'noWindowOpen' });
+ }
+ },
+ }),
+});