mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 04:21:24 +00:00
fix: expand SSRF guard coverage
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import type { GuardedFetchResult } from "../../infra/net/fetch-guard.js";
|
||||
import type { LookupFn, SsrFPolicy } from "../../infra/net/ssrf.js";
|
||||
import { fetchWithSsrFGuard } from "../../infra/net/fetch-guard.js";
|
||||
|
||||
const MAX_ERROR_CHARS = 300;
|
||||
|
||||
export function normalizeBaseUrl(baseUrl: string | undefined, fallback: string): string {
|
||||
@@ -20,6 +24,28 @@ export async function fetchWithTimeout(
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchWithTimeoutGuarded(
|
||||
url: string,
|
||||
init: RequestInit,
|
||||
timeoutMs: number,
|
||||
fetchFn: typeof fetch,
|
||||
options?: {
|
||||
ssrfPolicy?: SsrFPolicy;
|
||||
lookupFn?: LookupFn;
|
||||
pinDns?: boolean;
|
||||
},
|
||||
): Promise<GuardedFetchResult> {
|
||||
return await fetchWithSsrFGuard({
|
||||
url,
|
||||
fetchImpl: fetchFn,
|
||||
init,
|
||||
timeoutMs,
|
||||
policy: options?.ssrfPolicy,
|
||||
lookupFn: options?.lookupFn,
|
||||
pinDns: options?.pinDns,
|
||||
});
|
||||
}
|
||||
|
||||
export async function readErrorResponse(res: Response): Promise<string | undefined> {
|
||||
try {
|
||||
const text = await res.text();
|
||||
|
||||
Reference in New Issue
Block a user