Skip to content

Commit 025cd49

Browse files
committed
fix: disregard protocol-relative URL to remediate SSRF, axios#6539
1 parent 050182e commit 025cd49

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/core/src/utils/isAbsoluteUrl.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ describe('utils::isAbsoluteUrl', () => {
1313
expect(isAbsoluteUrl('!valid://example.com/')).toBe(false);
1414
});
1515

16-
it('should return true if URL is protocol-relative', () => {
17-
expect(isAbsoluteUrl('//example.com/')).toBe(true);
16+
it('should return false if URL is protocol-relative', () => {
17+
expect(isAbsoluteUrl('//example.com/')).toBe(false);
1818
});
1919

2020
it('should return false if URL is relative', () => {
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
export const isAbsoluteUrl = (url: string) => {
2+
// A URL is considered absolute if it begins with "<scheme>://".
3+
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
4+
// by any combination of letters, digits, plus, period, or hyphen.
25
// eslint-disable-next-line regexp/no-unused-capturing-group
3-
return /^([a-z][\d+.a-z-]*:)?\/\//i.test(url);
6+
return /^([a-z][\d+.a-z-]*:)\/\//i.test(url);
47
};

0 commit comments

Comments
 (0)