Skip to content

Commit 1f6ebf2

Browse files
fix(mosaic): render the sign-in action blocked link only for https URLs
1 parent 1c692ba commit 1f6ebf2

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎packages/mosaic/src/features/sign-in/__tests__/sign-in.utils.test.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, it } from 'vitest';
22

33
import type { SignInStep } from '../sign-in.types';
4-
import { stepKey } from '../sign-in.utils';
4+
import { httpsUrl, stepKey } from '../sign-in.utils';
55

66
describe('stepKey', () => {
77
it('keys each step by its kind and the variant that changes its copy', () => {
@@ -30,3 +30,14 @@ describe('stepKey', () => {
3030
expect(steps.map(([step]) => stepKey(step))).toEqual(steps.map(([, key]) => key));
3131
});
3232
});
33+
34+
describe('httpsUrl', () => {
35+
it('keeps an https link and drops any other scheme or an unparsable value', () => {
36+
expect(httpsUrl('https://acme.com/support')).toBe('https://acme.com/support');
37+
expect(httpsUrl('javascript:alert(1)')).toBeUndefined();
38+
expect(httpsUrl('http://acme.com/support')).toBeUndefined();
39+
expect(httpsUrl('data:text/html,hi')).toBeUndefined();
40+
expect(httpsUrl('/support')).toBeUndefined();
41+
expect(httpsUrl(undefined)).toBeUndefined();
42+
});
43+
});

‎packages/mosaic/src/features/sign-in/sign-in.utils.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,14 @@ export function stepKey(step: SignInStep): string {
1515
return `${step.kind}:${step.purpose}`;
1616
}
1717
}
18+
19+
export function httpsUrl(url: string | undefined): string | undefined {
20+
if (!url) {
21+
return undefined;
22+
}
23+
try {
24+
return new URL(url).protocol === 'https:' ? url : undefined;
25+
} catch {
26+
return undefined;
27+
}
28+
}

‎packages/mosaic/src/features/sign-in/steps/sign-in-action-blocked.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import { InputGroup } from '../../../components/input-group';
55
import { Link } from '../../../components/link';
66
import { useMessages } from '../../../localization';
77
import type { SignInActionBlockedDetails } from '../sign-in.types';
8+
import { httpsUrl } from '../sign-in.utils';
89

910
interface SignInActionBlockedProps {
1011
details?: SignInActionBlockedDetails;
1112
}
1213

1314
export function SignInActionBlocked({ details }: SignInActionBlockedProps) {
1415
const m = useMessages('signIn').actionBlocked;
15-
const href = details?.linkUrl;
16+
const href = httpsUrl(details?.linkUrl);
1617

1718
return (
1819
<>

0 commit comments

Comments
 (0)