Skip to content

Commit 39c7515

Browse files
committed
fix(mcp): carry redirect mode from a Request input in liftFetchArgs
liftFetchArgs copied method/headers/body/signal from a Request but omitted redirect, so a Request({ redirect: 'manual' }) on the pinned path defaulted to 'follow' and was transparently followed. Copy input.redirect (explicit init still wins). Adds a Request-input redirect-mode test.
1 parent 80b5d08 commit 39c7515

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

apps/sim/lib/core/security/input-validation.server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,9 @@ async function liftFetchArgs(
909909
headers: input.headers,
910910
body: bodyAllowed ? await input.clone().arrayBuffer() : undefined,
911911
signal: input.signal,
912+
// Carry the Request's redirect mode so the pinned fetch honors `manual`/`error`
913+
// instead of defaulting a `Request({ redirect: 'manual' })` to `follow`.
914+
redirect: input.redirect,
912915
...init,
913916
},
914917
}

apps/sim/lib/core/security/pinned-fetch.server.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ describe('createPinnedFetch', () => {
124124
expect(response.headers.get('location')).toBe('https://login.example.com/')
125125
})
126126

127+
it('honors redirect mode carried on a Request input (not just init)', async () => {
128+
mockUndiciRequest.mockResolvedValueOnce(
129+
undiciReply(302, { location: 'https://login.example.com/' }, byteStream(''))
130+
)
131+
const pinned = createPinnedFetch('203.0.113.10')
132+
133+
const response = await pinned(new Request('https://mcp.example.com/', { redirect: 'manual' }))
134+
135+
expect(mockUndiciRequest).toHaveBeenCalledTimes(1)
136+
expect(response.status).toBe(302)
137+
})
138+
127139
it('follows redirects by default and DROPS headers on a cross-origin hop (no api-key leak)', async () => {
128140
mockUndiciRequest
129141
.mockResolvedValueOnce(

0 commit comments

Comments
 (0)