Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: isSafeUrl utility",
"packageName": "@fluentui/react-charting",
"email": "vgenaev@gmail.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: isSafeUrl utility",
"packageName": "@fluentui/react-charts",
"email": "vgenaev@gmail.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1564,8 +1564,16 @@ describe('isSafeUrl', () => {
expect(utils.isSafeUrl('file:///etc/passwd')).toBe(false);
});

test('Should block ftp: protocol', () => {
expect(utils.isSafeUrl('ftp://example.com/file')).toBe(false);
test('Should allow ftp: protocol', () => {
expect(utils.isSafeUrl('ftp://example.com/file')).toBe(true);
});

test('Should allow mailto: protocol', () => {
expect(utils.isSafeUrl('mailto:user@example.com')).toBe(true);
});

test('Should allow tel: protocol', () => {
expect(utils.isSafeUrl('tel:+1234567890')).toBe(true);
});

test('Should block custom: protocol', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2557,7 +2557,7 @@ const truncateTextToFitWidth = (text: string, maxWidth: number, measure: (s: str

export function isSafeUrl(href: string): boolean {
if (/^[a-z][a-z0-9+.-]*:/i.test(href)) {
return /^https?:/i.test(href);
return /^(https?|mailto|tel|ftp):/i.test(href);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1569,8 +1569,16 @@ describe('isSafeUrl', () => {
expect(utils.isSafeUrl('file:///etc/passwd')).toBe(false);
});

test('Should block ftp: protocol', () => {
expect(utils.isSafeUrl('ftp://example.com/file')).toBe(false);
test('Should allow ftp: protocol', () => {
expect(utils.isSafeUrl('ftp://example.com/file')).toBe(true);
});

test('Should allow mailto: protocol', () => {
expect(utils.isSafeUrl('mailto:user@example.com')).toBe(true);
});

test('Should allow tel: protocol', () => {
expect(utils.isSafeUrl('tel:+1234567890')).toBe(true);
});

test('Should block custom: protocol', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2713,7 +2713,7 @@ const truncateTextToFitWidth = (text: string, maxWidth: number, measure: (s: str

export function isSafeUrl(href: string): boolean {
if (/^[a-z][a-z0-9+.-]*:/i.test(href)) {
return /^https?:/i.test(href);
return /^(https?|mailto|tel|ftp):/i.test(href);
}
return true;
}
Loading