From 7004707c4180b416341863bd86913fe4fc2f1df1 Mon Sep 17 00:00:00 2001 From: Antonin Bas Date: Fri, 23 Aug 2024 05:23:14 -0700 Subject: [PATCH] fix(adapter): fix undefined reference to hasBrowserEnv (#6572) --- lib/adapters/http.js | 2 +- test/unit/regression/SNYK-JS-AXIOS-7361793.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/adapters/http.js b/lib/adapters/http.js index d5ad9d1f37..366cadc8b0 100755 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -229,7 +229,7 @@ export default isHttpAdapterSupported && function httpAdapter(config) { // Parse url const fullPath = buildFullPath(config.baseURL, config.url); - const parsed = new URL(fullPath, utils.hasBrowserEnv ? platform.origin : undefined); + const parsed = new URL(fullPath, platform.hasBrowserEnv ? platform.origin : undefined); const protocol = parsed.protocol || supportedProtocols[0]; if (protocol === 'data:') { diff --git a/test/unit/regression/SNYK-JS-AXIOS-7361793.js b/test/unit/regression/SNYK-JS-AXIOS-7361793.js index 2d8b20565e..ec7e54e703 100644 --- a/test/unit/regression/SNYK-JS-AXIOS-7361793.js +++ b/test/unit/regression/SNYK-JS-AXIOS-7361793.js @@ -4,7 +4,6 @@ import axios from '../../../index.js'; import http from 'http'; import assert from 'assert'; -import utils from '../../../lib/utils.js'; import platform from '../../../lib/platform/index.js'; @@ -52,17 +51,18 @@ describe('Server-Side Request Forgery (SSRF)', () => { let hasBrowserEnv, origin; before(() => { - hasBrowserEnv = utils.hasBrowserEnv; + assert.ok(platform.hasBrowserEnv !== undefined); + hasBrowserEnv = platform.hasBrowserEnv; origin = platform.origin; - utils.hasBrowserEnv = true; + platform.hasBrowserEnv = true; platform.origin = 'http://localhost:' + String(GOOD_PORT); }); after(() => { - utils.hasBrowserEnv = hasBrowserEnv; + platform.hasBrowserEnv = hasBrowserEnv; platform.origin = origin; }); it('should fetch in client-side mode', async () => { - utils.hasBrowserEnv = true; + platform.hasBrowserEnv = true; const ssrfAxios = axios.create({ baseURL: 'http://localhost:' + String(GOOD_PORT), });