Skip to content

Commit 5ed6f37

Browse files
committed
refactor: remove unused outbound axios selector
1 parent 2a3ed86 commit 5ed6f37

3 files changed

Lines changed: 1 addition & 62 deletions

File tree

packages/service/common/api/axios.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import { ProxyAgent, type ProxyAgentOptions } from 'proxy-agent';
1212
import { getProxyForUrl } from 'proxy-from-env';
1313
import { isDevEnv } from '@fastgpt/global/common/system/constants';
1414
import { isInternalAddress, isInternalResolvedIP, PRIVATE_URL_TEXT } from '../system/utils';
15-
import { isAbsoluteUrl } from '../security/network';
16-
import { SERVICE_LOCAL_HOST } from '../system/tools';
1715

1816
/**
1917
* 给 shared axios 实例添加 SSRF 防护。
@@ -412,32 +410,3 @@ export function createProxyAxios(config?: AxiosRequestConfig, ssrfCheck = true)
412410
/** @see https://github.com/axios/axios/issues/4531 */
413411
export const axios = createProxyAxios();
414412
export const axiosWithoutSSRF = createProxyAxios(undefined, false);
415-
416-
/**
417-
* 内部相对路径请求专用的 axios 实例:
418-
* - baseURL 固定为本机 NextJS API
419-
* - 不带 SSRF 拦截器(本机调用必然解析到 localhost,装拦截会把所有合法请求拦死)
420-
* - 不复用 safe axios 的 ProxyAgent,保证内部回环不会被外部代理转走
421-
*
422-
* 仅在 url 是相对路径时使用;绝对 URL 必须走 safe `axios`。
423-
*/
424-
const internalAxios: AxiosInstance = _.create({
425-
baseURL: `http://${SERVICE_LOCAL_HOST}`
426-
});
427-
428-
/**
429-
* 根据 URL 类型自动选择合适的 axios 实例,避免每个调用点重复
430-
* `isAbsoluteUrl ? safe : raw` 三元。
431-
*
432-
* - 绝对 URL(`http(s)://...` 或 `//...`)→ safe `axios`(SSRF 拦截,拒绝内网/metadata)
433-
* - 相对路径(`/api/...` 等)→ `internalAxios`(本机 baseURL,可信内部 API)
434-
*
435-
* 用法:
436-
* ```ts
437-
* const client = pickOutboundAxios(url);
438-
* const res = await client.get(url, { responseType: 'arraybuffer' });
439-
* ```
440-
*/
441-
export const pickOutboundAxios = (url: string): AxiosInstance => {
442-
return isAbsoluteUrl(url) ? axios : internalAxios;
443-
};

packages/service/test/common/api/axios.test.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -545,33 +545,4 @@ describe('axios.ts', () => {
545545
expect(adapter).not.toHaveBeenCalled();
546546
});
547547
});
548-
549-
describe('pickOutboundAxios', () => {
550-
it.each([
551-
'http://example.com',
552-
'https://example.com/path',
553-
'http://169.254.169.254/latest/meta-data/',
554-
'//attacker.example/probe' // protocol-relative 也按绝对处理
555-
])('绝对 URL %j 返回 safe axios 实例', async (url) => {
556-
const { axios, pickOutboundAxios } = await import('../../../common/api/axios');
557-
expect(pickOutboundAxios(url)).toBe(axios);
558-
});
559-
560-
it.each(['/api/foo', 'api/foo', '/support/outLink/feishu/abc'])(
561-
'相对路径 %j 返回内部 axios(baseURL 固定到本机)',
562-
async (url) => {
563-
const { axios, pickOutboundAxios } = await import('../../../common/api/axios');
564-
const client = pickOutboundAxios(url);
565-
expect(client).not.toBe(axios);
566-
expect(client.defaults.baseURL).toMatch(/^http:\/\//);
567-
}
568-
);
569-
570-
it('多次调用同一类型的 URL,内部 client 应被复用(避免每次新建实例)', async () => {
571-
const { pickOutboundAxios } = await import('../../../common/api/axios');
572-
const a = pickOutboundAxios('/api/a');
573-
const b = pickOutboundAxios('/api/b');
574-
expect(a).toBe(b);
575-
});
576-
});
577548
});

packages/service/test/core/workflow/dispatch/ai/agent/index.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ vi.mock('@fastgpt/service/common/api/axios', async (importOriginal) => {
105105

106106
return {
107107
...original,
108-
axios: mockClient,
109-
pickOutboundAxios: () => mockClient
108+
axios: mockClient
110109
};
111110
});
112111

0 commit comments

Comments
 (0)