-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added url-sanitization function (#110)
* feat: added url-sanitization function * chore: fixed regex const * chore: added constants and updated code * chore: added tests, fixed build issues * chore: removed modified dist files
- Loading branch information
1 parent
6b054d8
commit 6dfe213
Showing
4 changed files
with
97 additions
and
1 deletion.
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
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,31 @@ | ||
/* @flow */ | ||
|
||
import { sanitizeUrl } from "../../../src/util"; | ||
|
||
describe("sanitizeUrl", () => { | ||
it("should return about:blank for malicious URLs", () => { | ||
const testURL = | ||
'https://www.paypal.com/smart/checkout/venmo/popup?parentDomain=www.paypal.com&venmoWebEnabled=true&venmoWebUrl=javascript:alert(document["cookie"])//'; | ||
const sanitizedUrl = sanitizeUrl(testURL); | ||
|
||
if (sanitizedUrl !== "about:blank") { | ||
throw new Error( | ||
`Does not match. Original data:\n\n${testURL} | ||
\n\nSanitized:\n\n${"about:blank"}\n` | ||
); | ||
} | ||
}); | ||
|
||
it("should return original URL when URL is clean", () => { | ||
const testURL = | ||
"https://www.paypal.com/smart/checkout/venmo/popup?parentDomain=www.paypal.com&venmoWebEnabled=true&venmoWebUrl=www.venmo.com"; | ||
const sanitizedUrl = sanitizeUrl(testURL); | ||
|
||
if (sanitizedUrl !== testURL) { | ||
throw new Error( | ||
`Does not match. Original data:\n\n${testURL} | ||
\n\nSanitized:\n\n${sanitizedUrl}\n` | ||
); | ||
} | ||
}); | ||
}); |