fix: route slack media auth fetch through runtime · openclaw/openclaw@b9a0795
steipete
·
2026-04-24
·
via Recent Commits to openclaw:main
File tree
extensions/slack/src/monitor
| Original file line number | Diff line number | Diff line change |
|---|
@@ -95,15 +95,20 @@ function createSlackMediaFetch(): FetchLike {
|
95 | 95 | }; |
96 | 96 | } |
97 | 97 | |
| 98 | +function resolveSlackFetchForRuntime(): typeof fetch { |
| 99 | +return isMockedFetch(globalThis.fetch) ? globalThis.fetch : fetchWithRuntimeDispatcher; |
| 100 | +} |
| 101 | + |
98 | 102 | /** |
99 | 103 | * Fetches a URL with Authorization header while keeping same-origin redirects |
100 | 104 | * authenticated and dropping auth once the redirect crosses origins. |
101 | 105 | */ |
102 | 106 | export async function fetchWithSlackAuth(url: string, token: string): Promise<Response> { |
103 | 107 | const parsed = assertSlackFileUrl(url); |
104 | 108 | const authHeaders = createSlackAuthHeaders(token); |
| 109 | +const fetchImpl = resolveSlackFetchForRuntime(); |
105 | 110 | |
106 | | -const initialRes = await fetch(parsed.href, { |
| 111 | +const initialRes = await fetchImpl(parsed.href, { |
107 | 112 | headers: authHeaders, |
108 | 113 | redirect: "manual", |
109 | 114 | }); |
@@ -122,12 +127,12 @@ export async function fetchWithSlackAuth(url: string, token: string): Promise<Re
|
122 | 127 | return initialRes; |
123 | 128 | } |
124 | 129 | if (resolvedUrl.origin === parsed.origin) { |
125 | | -return fetch(resolvedUrl.toString(), { |
| 130 | +return fetchImpl(resolvedUrl.toString(), { |
126 | 131 | headers: authHeaders, |
127 | 132 | redirect: "follow", |
128 | 133 | }); |
129 | 134 | } |
130 | | -return fetch(resolvedUrl.toString(), { redirect: "follow" }); |
| 135 | +return fetchImpl(resolvedUrl.toString(), { redirect: "follow" }); |
131 | 136 | } |
132 | 137 | |
133 | 138 | const SLACK_MEDIA_SSRF_POLICY = { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。