Skip to content

Commit

Permalink
Treat mailto: protocol as special
Browse files Browse the repository at this point in the history
Remove "mailto:" from the list of valid protocols,
because it can be unsafe to click on mailto links.

Instead, provide a special "emailAccepted" when we
know that the link is coming from a safe source,
like our code.
  • Loading branch information
csillag committed Feb 21, 2024
1 parent 7034e31 commit 2a22b11
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions .changelog/1285.trivial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Various small cleanups
3 changes: 2 additions & 1 deletion src/app/components/Snapshots/SnapshotCardExternalLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type SnapshotCardExternalLinkProps = {
label?: string
title: string
url?: string
emailAccepted?: boolean
}

export const SnapshotCardExternalLink: FC<SnapshotCardExternalLinkProps> = ({
Expand All @@ -40,7 +41,7 @@ export const SnapshotCardExternalLink: FC<SnapshotCardExternalLinkProps> = ({
>
{description}
</Typography>
{url && hasValidProtocol(url) && (
{url && (hasValidProtocol(url) || url.startsWith('mailto:')) && (
<Button href={url} target="_blank" rel="noopener noreferrer" color="secondary" variant="outlined">
{label}
</Button>
Expand Down
1 change: 1 addition & 0 deletions src/app/pages/ParatimeDashboardPage/TestnetFaucet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const TestnetFaucet: FC<TestnetFaucetProps> = ({ network, layer, ticker }
label={t('testnetFaucet.request')}
title={t('testnetFaucet.header')}
url={link}
emailAccepted={true}
/>
) : null
}
4 changes: 3 additions & 1 deletion src/app/pages/ValidatorDetailsPage/ExternalLinkCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { SnapshotCardExternalLink } from 'app/components/Snapshots/SnapshotCardE

type ExternalLinkCardProps = {
link?: string
emailAccepted?: boolean
}

export const ExternalLinkCard: FC<ExternalLinkCardProps> = ({ link }) => {
export const ExternalLinkCard: FC<ExternalLinkCardProps> = ({ link, emailAccepted }) => {
const { t } = useTranslation()

return (
Expand All @@ -15,6 +16,7 @@ export const ExternalLinkCard: FC<ExternalLinkCardProps> = ({ link }) => {
label={link}
title={t('validator.externalLink')}
url={link}
emailAccepted={emailAccepted}
/>
)
}
2 changes: 1 addition & 1 deletion src/app/utils/url.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const validProtocols = ['http:', 'https:', 'ftp:', 'ipfs:', 'data:', 'mailto:']
const validProtocols = ['http:', 'https:', 'ftp:', 'ipfs:', 'data:']

export const hasValidProtocol = (url: string | undefined): boolean => {
if (!url) {
Expand Down

0 comments on commit 2a22b11

Please sign in to comment.