|
| 1 | +// https://security.snyk.io/vuln/SNYK-JS-AXIOS-7361793 |
| 2 | +// https://github.com/axios/axios/issues/6463 |
| 3 | + |
| 4 | +import axios from '../../../index.js'; |
| 5 | +import http from 'http'; |
| 6 | +import assert from 'assert'; |
| 7 | + |
| 8 | +const GOOD_PORT = 4666; |
| 9 | +const BAD_PORT = 4667; |
| 10 | + |
| 11 | +describe('Server-Side Request Forgery (SSRF)', () => { |
| 12 | + let goodServer, badServer; |
| 13 | + |
| 14 | + beforeEach(() => { |
| 15 | + goodServer = http.createServer(function (req, res) { |
| 16 | + res.write('good'); |
| 17 | + res.end(); |
| 18 | + }).listen(GOOD_PORT); |
| 19 | + badServer = http.createServer(function (req, res) { |
| 20 | + res.write('bad'); |
| 21 | + res.end(); |
| 22 | + }).listen(BAD_PORT); |
| 23 | + }) |
| 24 | + |
| 25 | + afterEach(() => { |
| 26 | + goodServer.close(); |
| 27 | + badServer.close(); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should not fetch bad server', async () => { |
| 31 | + const ssrfAxios = axios.create({ |
| 32 | + baseURL: 'http://localhost:' + String(GOOD_PORT), |
| 33 | + }); |
| 34 | + |
| 35 | + // Good payload would be `userId = '12345'` |
| 36 | + // Malicious payload is as below. |
| 37 | + const userId = '/localhost:' + String(BAD_PORT); |
| 38 | + |
| 39 | + const response = await ssrfAxios.get(`/${userId}`); |
| 40 | + assert.strictEqual(response.data, 'good'); |
| 41 | + assert.strictEqual(response.config.baseURL, 'http://localhost:' + String(GOOD_PORT)); |
| 42 | + assert.strictEqual(response.config.url, '//localhost:' + String(BAD_PORT)); |
| 43 | + assert.strictEqual(response.request.res.responseUrl, 'http://localhost:' + String(GOOD_PORT) + '/localhost:' + String(BAD_PORT)); |
| 44 | + }); |
| 45 | +}); |
0 commit comments