Repository navigation
server: forward non-prefixed /broker/ paths without a redirect - #203
Merged
Merged
Conversation
ServeMux answers a path with "//", "/./" or "/../" with a 301 to the cleaned path. The Location is relative, and the relay dispatcher cannot follow a relative redirect, so each such call failed after the dispatcher retried every client. snyk-broker forwards the path as it is, so the failures started only after a tenant moved to grpc-tunnel. Send these paths directly to broker dispatch so the agent gets the path as the caller sent it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No test covered HttpAdapter path forwarding. Put the new test in http_test.go and reuse the existing harness instead of new setup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shawnburke
enabled auto-merge (squash)
November 22, 2026 08:17
ashiramin
approved these changes
Nov 22, 2026
engrams-agent Bot
pushed a commit
that referenced
this pull request
Nov 23, 2026
HttpAdapter.ServeHTTP had its own copy of the unclean-path check from #203. It now uses Wrap in front of its own ServeMux, the same as cmd/main.go does for the outer one, so the check is in one place. Wrap calls handleBrokerDispatch directly, so ServeHTTP and Wrap do not call each other. The test now sends each path through both entry points: the adapter directly, and an outer ServeMux as in cmd/main.go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shawnburke
added a commit
that referenced
this pull request
Nov 23, 2026
* server: bypass path cleaning in the outer HTTP mux too #203 kept the adapter's own ServeMux from redirecting unclean /broker/ paths. But cmd/main.go mounts the adapter on a second ServeMux, which cleans the path and sends the relative 301 first, so the adapter never saw these requests and the dispatcher still failed on them. Add HttpAdapter.Wrap, which sends unclean /broker/ paths directly to the adapter, and use it in front of the outer mux. The test now goes through an outer mux, the same as production. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: relay paths that are not clean, end to end Add a shared relay scenario that requests //file and /./file through the real tunnel server image, agent and origin. On main the outer ServeMux in cmd/main.go sends a relative 301 and the scenario fails. With HttpAdapter.Wrap the origin serves the file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: expect the agent to reject unclean paths, not the origin to serve them Both agents' accept filters reject a path that is not normalized: the grpc-tunnel agent with 400 "path is not normalized", snyk-broker with 401 "blocked". The scenario now checks that such a path reaches the agent and gets that 4xx, and that the ingress does not answer with a redirect. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * server: route the adapter's own mux through Wrap too HttpAdapter.ServeHTTP had its own copy of the unclean-path check from #203. It now uses Wrap in front of its own ServeMux, the same as cmd/main.go does for the outer one, so the check is in one place. Wrap calls handleBrokerDispatch directly, so ServeHTTP and Wrap do not call each other. The test now sends each path through both entry points: the adapter directly, and an outer ServeMux as in cmd/main.go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * server: serve all adapter routes in Wrap, without a ServeMux Wrap had to find paths that are not clean and send them past each ServeMux that routed to the adapter. Now no ServeMux routes the adapter's paths. Wrap matches connection-status and /broker/ dispatch on the path as it was sent, and sends all other requests to next. ServeHTTP is Wrap in front of a 404, and cmd/main.go no longer registers the adapter's paths on its mux. isCleanPath is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * server: explain why ServeHTTP wraps a 404 handler Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * server: match connection-status paths with one regex connectionStatusToken now uses a regex for /connection-status/{token} and /broker/connection-status/{token}, instead of hand-written prefix cuts. Wrap checks the method. TestConnectionStatusToken covers both forms and the paths that must not match. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: shawnburke <shawnburke@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After a tenant moved from snyk-broker to grpc-tunnel, the relay dispatcher logged this warning for some GitHub requests:
The cause is the
http.ServeMuxinHttpAdapter. ServeMux cleans the request path. If a path has//,/./or/../(for example/broker/<token>/repos/o/r/contents//Jenkinsfile), ServeMux does not call the handler. It sends a301with a relativeLocationthat holds the cleaned path. The dispatcher's redirect code cannot parse a relative URL, so the call fails. The broker is healthy, so the dispatcher tries every client again, and each request makes about 20 attempts before it fails.snyk-broker forwards the path as it is, so this did not happen before the switch.
Fix
HttpAdapter.ServeHTTPnow sends a/broker/path that is not clean directly tohandleBrokerDispatch. The agent gets the path as the caller sent it, the same as with snyk-broker.isCleanPathuses the same rule as ServeMux (path.Clean, with a trailing slash kept). Clean paths still go through the mux, so connection-status routing does not change.Tests
http_test.gochecks that clean,//,/./,/../and query paths get to the agent unchanged. It reusesfailureHarness. Before this change, no test coveredHttpAdapterpath forwarding.CI on this branch runs
make -C server test.A separate change in the relay-dispatcher (brain-backend) will make it resolve relative
Locationheaders, as defense in depth.🤖 Generated with Claude Code