forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-https-proxy-request-invalid-credentials.mjs
More file actions
56 lines (52 loc) · 1.94 KB
/
Copy pathtest-https-proxy-request-invalid-credentials.mjs
File metadata and controls
56 lines (52 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// This tests that HTTPS proxy URLs with invalid credentials (containing \r or \n characters)
// are rejected with an appropriate error.
import * as common from '../common/index.mjs';
import assert from 'node:assert';
if (!common.hasCrypto) {
common.skip('missing crypto');
}
// https must be dynamically imported so that builds without crypto support
// can skip it.
const { default: https } = await import('node:https');
const testCases = [
{
name: 'carriage return in username (HTTPS)',
proxyUrl: 'https://user\r:pass@proxy.example.com:8080',
expectedError: { code: 'ERR_PROXY_INVALID_CONFIG', message: /Invalid proxy URL/ },
},
{
name: 'newline in username (HTTPS)',
proxyUrl: 'https://user\n:pass@proxy.example.com:8080',
expectedError: { code: 'ERR_PROXY_INVALID_CONFIG', message: /Invalid proxy URL/ },
},
{
name: 'carriage return in password (HTTPS)',
proxyUrl: 'https://user:pass\r@proxy.example.com:8080',
expectedError: { code: 'ERR_PROXY_INVALID_CONFIG', message: /Invalid proxy URL/ },
},
{
name: 'newline in password (HTTPS)',
proxyUrl: 'https://user:pass\n@proxy.example.com:8080',
expectedError: { code: 'ERR_PROXY_INVALID_CONFIG', message: /Invalid proxy URL/ },
},
{
name: 'CRLF injection attempt in username (HTTPS)',
proxyUrl: 'https://user\r\nHost: example.com:pass@proxy.example.com:8080',
expectedError: { code: 'ERR_PROXY_INVALID_CONFIG', message: /Invalid proxy URL/ },
},
{
name: 'CRLF injection attempt in password (HTTPS)',
proxyUrl: 'https://user:pass\r\nHost: example.com@proxy.example.com:8080',
expectedError: { code: 'ERR_PROXY_INVALID_CONFIG', message: /Invalid proxy URL/ },
},
];
for (const testCase of testCases) {
// Test that creating an agent with invalid proxy credentials throws an error
assert.throws(() => {
new https.Agent({
proxyEnv: {
HTTPS_PROXY: testCase.proxyUrl,
},
});
}, testCase.expectedError);
}