forked from axios/axios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix to prevent XSS, throw an error when the URL contains a JS script (a…
…xios#2464) * Fixes issue where XSS scripts attacks were possible via the URL * Fix error * Move throwing error up * Add specs and make regex cover more xss cases
- Loading branch information
1 parent
ee60ee3
commit 29da6b2
Showing
4 changed files
with
33 additions
and
6 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = function isValidXss(requestURL) { | ||
var regex = RegExp('<script+.*>+.*<\/script>'); | ||
return regex.test(requestURL); | ||
var xssRegex = /(\b)(on\S+)(\s*)=|javascript|(<\s*)(\/*)script/gi; | ||
return xssRegex.test(requestURL); | ||
}; |
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,24 @@ | ||
var isValidXss = require('../../../lib/helpers/isValidXss'); | ||
|
||
describe('helpers::isValidXss', function () { | ||
it('should detect script tags', function () { | ||
expect(isValidXss("<script/xss>alert('blah')</script/xss>")).toBe(true); | ||
expect(isValidXss("<SCRIPT>alert('getting your password')</SCRIPT>")).toBe(true); | ||
expect(isValidXss("<script src='http://xssinjections.com/inject.js'>xss</script>")).toBe(true); | ||
expect(isValidXss("<img src='/' onerror='javascript:alert('xss')'>xss</script>")).toBe(true); | ||
expect(isValidXss("<script>console.log('XSS')</script>")).toBe(true); | ||
expect(isValidXss("onerror=alert('XSS')")).toBe(true); | ||
expect(isValidXss("<a onclick='alert('XSS')'>Click Me</a>")).toBe(true); | ||
}); | ||
|
||
it('should not detect non script tags', function() { | ||
expect(isValidXss("<safe> tags")).toBe(false); | ||
expect(isValidXss("<safetag>")).toBe(false); | ||
expect(isValidXss(">>> safe <<<")).toBe(false); | ||
expect(isValidXss("<<< safe >>>")).toBe(false); | ||
expect(isValidXss("my script rules")).toBe(false); | ||
expect(isValidXss("<a notonlistener='nomatch'>")).toBe(false); | ||
expect(isValidXss("<h2>MyTitle</h2>")).toBe(false); | ||
expect(isValidXss("<img src='#'/>")).toBe(false); | ||
}) | ||
}); |