2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-15 11:59:42 +03:00

Fix to prevent XSS, throw an error when the URL contains a JS script (#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
This commit is contained in:
Yasu Flores
2019-10-16 03:53:10 -07:00
committed by Felipe Martins
parent ee60ee368e
commit 29da6b24db
4 changed files with 33 additions and 6 deletions
+3 -2
View File
@@ -9,7 +9,8 @@ describe('helpers::isURLSameOrigin', function () {
expect(isURLSameOrigin('https://github.com/axios/axios')).toEqual(false);
});
it('should detect xss', function () {
expect(isURLSameOrigin('https://github.com/axios/axios?<script>alert("hello")</script>')).toEqual(false)
it('should detect XSS scripts on a same origin request', function () {
expect(() => { isURLSameOrigin('https://github.com/axios/axios?<script>alert("hello")</script>'); })
.toThrowError(Error, 'URL contains XSS injection attempt')
})
});
+24
View File
@@ -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);
})
});