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(sec): disregard protocol-relative URL to remediate SSRF (axios#6539)
* fix(sec): disregard protocol-relative URL to remediate SSRF Signed-off-by: hainenber <[email protected]> * feat(test/unit/regression): add regression test to ensure SNYK-JS-AXIOS-7361793 fixed in future version Signed-off-by: hainenber <[email protected]> * chore: add EoF newline + comments Signed-off-by: hainenber <[email protected]> * chore: fix eslint issues Signed-off-by: hainenber <[email protected]> * Update SNYK-JS-AXIOS-7361793.js Co-authored-by: tom-reinders <[email protected]> --------- Signed-off-by: hainenber <[email protected]> Co-authored-by: tom-reinders <[email protected]>
- Loading branch information
1 parent
c6cce43
commit 07a661a
Showing
3 changed files
with
49 additions
and
4 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
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,45 @@ | ||
// https://security.snyk.io/vuln/SNYK-JS-AXIOS-7361793 | ||
// https://github.com/axios/axios/issues/6463 | ||
|
||
import axios from '../../../index.js'; | ||
import http from 'http'; | ||
import assert from 'assert'; | ||
|
||
const GOOD_PORT = 4666; | ||
const BAD_PORT = 4667; | ||
|
||
describe('Server-Side Request Forgery (SSRF)', () => { | ||
let goodServer, badServer; | ||
|
||
beforeEach(() => { | ||
goodServer = http.createServer(function (req, res) { | ||
res.write('good'); | ||
res.end(); | ||
}).listen(GOOD_PORT); | ||
badServer = http.createServer(function (req, res) { | ||
res.write('bad'); | ||
res.end(); | ||
}).listen(BAD_PORT); | ||
}) | ||
|
||
afterEach(() => { | ||
goodServer.close(); | ||
badServer.close(); | ||
}); | ||
|
||
it('should not fetch bad server', async () => { | ||
const ssrfAxios = axios.create({ | ||
baseURL: 'http://localhost:' + String(GOOD_PORT), | ||
}); | ||
|
||
// Good payload would be `userId = '12345'` | ||
// Malicious payload is as below. | ||
const userId = '/localhost:' + String(BAD_PORT); | ||
|
||
const response = await ssrfAxios.get(`/${userId}`); | ||
assert.strictEqual(response.data, 'good'); | ||
assert.strictEqual(response.config.baseURL, 'http://localhost:' + String(GOOD_PORT)); | ||
assert.strictEqual(response.config.url, '//localhost:' + String(BAD_PORT)); | ||
assert.strictEqual(response.request.res.responseUrl, 'http://localhost:' + String(GOOD_PORT) + '/localhost:' + String(BAD_PORT)); | ||
}); | ||
}); |