Skip to content

server: wrap outer mux, clean up wrapper, add E2E validation test - #204

Merged
shawnburke merged 7 commits into
mainfrom
fix/outer-mux-unclean-paths
Nov 23, 2026
Merged

shawnburke merged 7 commits into
mainfrom
fix/outer-mux-unclean-paths

Conversation

@shawnburke

@shawnburke shawnburke commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

#203 did not stop the failures. The relay dispatcher still logs IllegalArgumentException: Expected URL scheme 'http' or 'https' but no scheme was found for /broke... for paths such as /broker/<token>/repos/o/r/contents//Jenkinsfile.

#203 made HttpAdapter.ServeHTTP bypass the adapter's own ServeMux for paths that are not clean. But cmd/main.go mounts the adapter on a second, outer ServeMux:

httpMux.Handle("/broker/", httpAdapter)
httpServer := &http.Server{Handler: httpMux}

The outer mux cleans the path and sends the relative 301 first, so the adapter never sees these requests. The test in #203 called the adapter directly, so it did not catch this.

Fix

No ServeMux routes the adapter's paths now, so nothing cleans them.

  • HttpAdapter.Wrap(next) serves all of the adapter's routes, and sends all other requests to next. It matches the path as it was sent:
    • GET /connection-status/{token} and GET /broker/connection-status/{token}: connection status
    • /broker/{token}/{path...}: tunnel dispatch
  • HttpAdapter.ServeHTTP is Wrap in front of a 404. The adapter has no internal ServeMux.
  • main.go no longer registers /broker/ and /connection-status/ on its mux. It uses httpAdapter.Wrap(httpMux) as the server handler.
  • connectionStatusToken extracts the token with one regex, ^(?:/broker)?/connection-status/([^/]+)$, and getConnectionStatus gets the token as an argument. A ServeMux cannot do this extraction, because it cleans the path first. TestConnectionStatusToken covers the paths that must and must not match.
  • TestBrokerDispatch_ForwardsPathAsSent sends each path through both entry points: the adapter directly, and Wrap in front of a ServeMux, as in main.go.

One small behavior change: a non-GET request to the root /connection-status/{token} now gets 404 instead of 405. The dispatcher sends only GET there.

End-to-end test

agent/test/relay/relay_scenarios.sh has a new shared scenario, scenario_unclean_path_reaches_agent. It sends .../contents//Jenkinsfile and .../contents/./Jenkinsfile through the real tunnel server image (the real main.go wiring), agent, and origin. It runs against both transports.

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. So the scenario checks that the request reaches the agent and gets that 4xx, and that the ingress does not answer with a redirect.

Branch gRPC relay e2e snyk-broker relay e2e
main + scenario only (run) fail pass
this PR pass pass

CI on this branch runs make -C server test.

🤖 Generated with Claude Code

shawnburke and others added 3 commits November 23, 2026 00:18
#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>
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>
…ve 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>
@shawnburke
shawnburke requested a review from ashiramin November 23, 2026 01:34
@shawnburke
shawnburke marked this pull request as draft November 23, 2026 01:35
shawnburke and others added 3 commits November 23, 2026 01:36
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>
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>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shawnburke shawnburke changed the title server: bypass path cleaning in the outer HTTP mux too server: wrap outer mux, clean up wrapper, add E2E validation test Nov 23, 2026
Comment thread server/adapters/http.go Outdated
if r.Method != http.MethodGet && r.Method != http.MethodHead {
return "", false
}
for _, prefix := range []string{"/connection-status/", "/broker/connection-status/"} {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't like that we are hand-extracting this when the prior code did r.PathValue("token"), which i understood came from the Mux. Can we reuse a more generic approach can we use a mux under the covers just for path extraction rather than trying to parse the strings?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in de5455b. A ServeMux cannot do the extraction here: it cleans the path and sends the 301 before any handler runs, and it has no setting to turn that off. So connectionStatusToken now uses one regex, ^(?:/broker)?/connection-status/([^/]+)$. TestConnectionStatusToken checks both forms, hashed and raw tokens, and the paths that must not match (no token, extra segments, //, other prefixes, and dispatch paths).

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>
@shawnburke
shawnburke marked this pull request as ready for review November 23, 2026 02:00
@shawnburke
shawnburke enabled auto-merge (squash) November 23, 2026 02:01
@shawnburke
shawnburke merged commit d4600e8 into main Nov 23, 2026
26 checks passed
@shawnburke
shawnburke deleted the fix/outer-mux-unclean-paths branch November 23, 2026 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants