Skip to content

Commit 58816ea

Browse files
committed
fix: update as per cubic
1 parent c539370 commit 58816ea

4 files changed

Lines changed: 52 additions & 3 deletions

File tree

lib/core/AxiosError.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function redactConfig(config, redactKeys) {
5656
return source;
5757
}
5858

59-
result = {};
59+
result = Object.create(null);
6060
for (const [key, value] of Object.entries(source)) {
6161
const reducedValue = lowerKeys.has(key.toLowerCase()) ? REDACTED : visit(value);
6262
if (!utils.isUndefined(reducedValue)) {

lib/helpers/shouldBypassProxy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ const parseNoProxyEntry = (entry) => {
9393
// (Node's URL parser normalises that to `[::ffff:c0a8:105]`), and vice-versa,
9494
// allowing the proxy-bypass policy to be circumvented by using the alternate
9595
// representation. Returns the input unchanged when not IPv4-mapped.
96-
const IPV4_MAPPED_DOTTED_RE = /^(?:::|(?:0{1,4}:){5})ffff:(\d+\.\d+\.\d+\.\d+)$/i;
97-
const IPV4_MAPPED_HEX_RE = /^(?:::|(?:0{1,4}:){5})ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i;
96+
const IPV4_MAPPED_DOTTED_RE = /^(?:::|(?:0{1,4}:){1,4}:|(?:0{1,4}:){5})ffff:(\d+\.\d+\.\d+\.\d+)$/i;
97+
const IPV4_MAPPED_HEX_RE = /^(?:::|(?:0{1,4}:){1,4}:|(?:0{1,4}:){5})ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i;
9898

9999
const unmapIPv4MappedIPv6 = (host) => {
100100
if (typeof host !== 'string' || host.indexOf(':') === -1) return host;

tests/unit/core/AxiosError.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,22 @@ describe('core::AxiosError', () => {
316316
}
317317
});
318318

319+
it('copies __proto__ as data without changing the redaction output prototype', () => {
320+
const config = { redact: ['password'] };
321+
Object.defineProperty(config, '__proto__', {
322+
value: { password: 'secret' },
323+
enumerable: true,
324+
configurable: true,
325+
});
326+
327+
const error = new AxiosError('Boom', 'ECODE', config);
328+
const json = error.toJSON();
329+
330+
expect(Object.getPrototypeOf(json.config)).toBe(null);
331+
expect(Object.prototype.hasOwnProperty.call(json.config, '__proto__')).toBe(true);
332+
expect(json.config.__proto__.password).toBe('[REDACTED ****]');
333+
});
334+
319335
it('does not mutate the original config or AxiosHeaders', () => {
320336
const headers = new AxiosHeaders();
321337
headers.set('Authorization', 'Bearer abc');

tests/unit/helpers/shouldBypassProxy.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,39 @@ describe('helpers::shouldBypassProxy', () => {
211211
expect(shouldBypassProxy('http://[::ffff:10.0.0.1]/')).toBe(true);
212212
});
213213

214+
it('should treat compressed zero-prefix IPv4-mapped IPv6 dotted forms as equivalent', () => {
215+
for (const entry of [
216+
'0::ffff:192.168.1.5',
217+
'0:0::ffff:192.168.1.5',
218+
'0:0:0::ffff:192.168.1.5',
219+
'0:0:0:0::ffff:192.168.1.5',
220+
]) {
221+
setNoProxy(entry);
222+
223+
expect(shouldBypassProxy('http://192.168.1.5/')).toBe(true);
224+
}
225+
});
226+
227+
it('should treat compressed zero-prefix IPv4-mapped IPv6 hex forms as equivalent', () => {
228+
for (const entry of [
229+
'0::ffff:c0a8:105',
230+
'0:0::ffff:c0a8:105',
231+
'0:0:0::ffff:c0a8:105',
232+
'0:0:0:0::ffff:c0a8:105',
233+
]) {
234+
setNoProxy(entry);
235+
236+
expect(shouldBypassProxy('http://192.168.1.5/')).toBe(true);
237+
}
238+
});
239+
240+
it('should support compressed bracketed IPv4-mapped IPv6 entries with explicit ports', () => {
241+
setNoProxy('[0:0::ffff:192.168.1.5]:8080');
242+
243+
expect(shouldBypassProxy('http://192.168.1.5:8080/')).toBe(true);
244+
expect(shouldBypassProxy('http://192.168.1.5:9090/')).toBe(false);
245+
});
246+
214247
it('should NOT cross-match unrelated addresses', () => {
215248
setNoProxy('192.168.1.5');
216249

0 commit comments

Comments
 (0)