stacklok / stacklok/toolhive

Strip endpointPrefix from request paths in transparent proxy

Open
#3,372 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug go proxy
Dominant language
Go
Stars
2.2k
Forks
300
Avg merge
1d 15h
Merged PRs (30d)
184

Description

Problem

The transparent proxy currently rewrites SSE endpoint URLs in responses to include the configured endpointPrefix, but it doesn't strip the prefix from incoming request paths before forwarding to the backend MCP server.

This causes issues in two scenarios:

  1. Direct client access: When a client makes a request directly to the proxy with the prefix (e.g., /playwright/sse), the proxy forwards it as-is to the backend, which expects /sse without the prefix.

  2. Ingress without prefix stripping: When an ingress controller doesn't strip the prefix before forwarding, the backend receives requests with the prefix that it doesn't expect.

Current Behavior
  • SSE response URLs are rewritten with prefix: /sse/playwright/sse
  • Request paths are forwarded as-is: /playwright/sse → backend receives /playwright/sse
Expected Behavior
  • If ingress already stripped the prefix (detected via X-Forwarded-Prefix header), proxy should not strip again
  • If ingress didn't strip OR client makes direct request, proxy should strip the prefix before forwarding
  • Backend should always receive paths without the prefix: /playwright/sse/sse

Solution

Implement prefix stripping in the proxy's Director function that:

  • Strips endpointPrefix from request paths when present at the start
  • Detects if ingress already stripped via X-Forwarded-Prefix header (when trustProxyHeaders is enabled)
  • Handles edge cases like prefix appearing later in path (e.g., /abc/abc/sse with prefix /abc/abc/sse)

Related

  • Affects: SSE transport with endpointPrefix configuration
  • Related to: Ingress path-based routing scenarios
  • Implementation: pkg/transport/proxy/transparent/transparent_proxy.go

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pkg/transport/proxy/transparent/transparent_proxy.go at the proxy's Director function and trace how endpointPrefix and X-Forwarded-Prefix are handled. Verify direct and ingress-forwarded requests, including repeated prefixes such as /abc/abc/sse; done means the backend receives paths without an unstripped prefix while already-stripped requests remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.