-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: disallow localhost webhooks (#368)
* fix: disallow localhost webhooks * allow http but disallow localhost
- Loading branch information
Showing
3 changed files
with
51 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { isLocalhost } from "../utils/url"; | ||
|
||
describe("isLocalhost function", () => { | ||
test("should return true for localhost URL", () => { | ||
const localhostUrl = "http://localhost:3000/path"; | ||
expect(isLocalhost(localhostUrl)).toBe(true); | ||
}); | ||
|
||
test("should return true for 127.0.0.1 URL", () => { | ||
const ipUrl = "http://127.0.0.1:8080/path"; | ||
expect(isLocalhost(ipUrl)).toBe(true); | ||
}); | ||
|
||
test("should return false for external URL", () => { | ||
const externalUrl = "http://example.com/path"; | ||
expect(isLocalhost(externalUrl)).toBe(false); | ||
}); | ||
|
||
test("should return false for invalid URL", () => { | ||
const invalidUrl = "not_a_url"; | ||
expect(isLocalhost(invalidUrl)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const isLocalhost = (url: string) => { | ||
try { | ||
const parsed = new URL(url); | ||
return parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1"; | ||
} catch (err) { | ||
return false; | ||
} | ||
}; |