Skip to content

🐛 fix(proxy): forward the original versioned path on the hijack upstream leg - #203

Merged
scttbnsn merged 3 commits into
dev/v1.6from
fix/v1.6-hijack-libpod-path
Aug 8, 2026
Merged

scttbnsn merged 3 commits into
dev/v1.6from
fix/v1.6-hijack-libpod-path

Conversation

@scttbnsn

@scttbnsn scttbnsn commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Root cause

internal/proxy/hijack.go's writeHijackUpstreamRequest built the outbound attach/exec-start request from the filter-normalized (version-stripped) path, the same form internal/filter uses for rule matching, instead of the client's original request path. That's harmless against dockerd (accepts bare unversioned paths), but real Podman requires the version prefix (/v5.x.y/libpod/...) on every libpod route except the bare _ping. A hijacked POST /libpod/exec/{id}/start proxied through sockguard therefore 404ed against a real Podman daemon even when policy allowed it. The non-hijack reverse-proxy path (proxy.go's Rewrite, which only touches Scheme/Host and leaves Path untouched) never had this bug — the hijack path was the sole inconsistency.

Fix

newUpstreamHijackRequest now takes the literal wire path; the production caller (writeHijackUpstreamRequest) passes r.URL.Path directly. The normalized/stripped path is still used for endpoint matching (isHijackEndpointNormalized) and logging — unchanged.

Tests

  • New regression test: TestHandleHijack_LibpodExecStartPreservesVersionPrefix (app/internal/proxy/hijack_libpod_test.go) reproduces the path mangle directly — confirmed failing before the fix (404), passing after.
  • Two existing tests pinned the old buggy behavior and are updated to assert the fixed contract: TestHandleHijack_PreservesOriginalRequestPathUpstream (renamed from ...RebuildsUpstreamRequestTargetFromNormalizedPath, hijack_test.go) and TestFullProxyChainHijackIntegration (internal/cmd/serve_chain_test.go).
  • New podmanintegration-tagged acceptance test: TestLibpodExecStartEndToEndHijackAgainstRealPodman (app/integration/podman_libpod_integration_test.go) drives a real create → exec-create → exec-start round trip through the hijack path against a live Podman daemon (Podman 6.0.2 client / Libpod 5.8.1 server, verified locally against a real podman machine) — closing the gap PR 🧪 test(integration): Podman rootful+rootless CI integration for libpod surface (#148) #192 had to leave open, and matching the issue's suggested acceptance criterion. Verified this test fails with status = 404 against the pre-fix code and passes after.

Verification

  • go test -race -count=1 ./... — all packages pass.
  • go test -tags podmanintegration ./integration/... — full libpod integration suite passes against a real Podman daemon.
  • golangci-lint run — clean.
  • Full pre-push gate (goreleaser snapshot, go-lint, go-test, govulncheck, go-fuzz, lockfile-dedupe, knip, biome, ts-test, build) — all green.
  • CHANGELOG.md entry added; the resolved "Known Limitations" note in docs/content/docs/podman.mdx removed.

Fixes #194

Changelog

  • 🐛 Fixed hijacked requests to preserve the client’s original versioned path when forwarding to upstream.
  • ✨ Added regression coverage for versioned libpod exec-start requests.
  • ✨ Added a real Podman end-to-end hijack integration test.
  • 🔧 Updated hijack tests for original-path forwarding.
  • 🗑️ Removed the resolved Podman limitation from the documentation.
  • 🔧 Added a changelog entry.

Concerns

  • Verify that the full pre-push gate includes the Podman integration test and race detection.
  • Confirm that original paths cannot bypass endpoint matching or default-deny socket access rules.

…eam leg

writeHijackUpstreamRequest built the outbound attach/exec-start request
from the filter-normalized (version-stripped) path instead of the
client's original path. dockerd tolerates a bare unversioned path, but
real Podman requires the version prefix (/v5.x.y/libpod/...) on every
libpod route but the bare _ping, so a hijacked POST
/libpod/exec/{id}/start proxied through sockguard 404ed against a real
daemon even when policy allowed it. The non-hijack reverse-proxy path
(proxy.go's Rewrite, which only touches Scheme/Host) never had this bug.

- newUpstreamHijackRequest now takes the wire path directly; the
  production caller passes r.URL.Path. The normalized path is still
  used for endpoint matching (isHijackEndpointNormalized) and logging.
- New internal/proxy/hijack_libpod_test.go regression test
  (TestHandleHijack_LibpodExecStartPreservesVersionPrefix) reproduces
  the mangle directly; two existing tests that pinned the old
  stripped-path behavior (hijack_test.go, internal/cmd/serve_chain_test.go)
  are updated to assert the fixed contract.
- New podmanintegration-tagged acceptance test
  (TestLibpodExecStartEndToEndHijackAgainstRealPodman) drives a real
  create -> exec-create -> exec-start round trip through the hijack
  path against a live Podman daemon, closing the gap PR #192 left open.
- Removes the now-resolved "Known Limitations" entry from the Podman
  guide and records the fix in CHANGELOG.md.

Fixes #194
@vercel

vercel Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sockguard-website Ready Ready Preview Aug 8, 2026 6:15pm

@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@scttbnsn, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 44 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d78b823b-9451-42f1-8dc0-f97da6f96bd8

📥 Commits

Reviewing files that changed from the base of the PR and between 35c4c29 and 337afb6.

📒 Files selected for processing (4)
  • app/integration/podman_libpod_integration_test.go
  • app/internal/proxy/hijack.go
  • app/internal/proxy/hijack_libpod_test.go
  • app/internal/proxy/hijack_test.go
📝 Walkthrough

Walkthrough

Hijack forwarding now sends the client’s original URL path, including API version prefixes, to the upstream. Normalized paths remain used for logging and errors. Regression tests cover path, query, host, and fallback behavior. A new integration test runs libpod exec-start against real Podman through the TCP proxy and validates the HTTP upgrade and echoed stdout frame.

Possibly related issues

Possibly related PRs

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/v1.6-hijack-libpod-path

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/internal/proxy/hijack.go (1)

479-498: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Preserve RawPath for upstream hijack requests.

writeHijackUpstreamRequest passes r.URL.Path, but r.URL.Path is decoded and the new URL has no RawPath. A request like %2F becomes / in the emitted request.

Set RawPath when path == r.URL.Path, and add a regression check on the forwarded request target.

Proposed fix
 func newUpstreamHijackRequest(r *http.Request, path string) *http.Request {
 	rawQuery := ""
+	rawPath := ""
 	if path == "" && r.URL != nil {
 		path = r.URL.Path
 	}
 	if r.URL != nil {
+		if path == r.URL.Path {
+			rawPath = r.URL.RawPath
+		}
 		rawQuery = r.URL.RawQuery
 	}

 	upstreamReq := &http.Request{
-		URL: &url.URL{Scheme: "http", Host: "docker", Path: path, RawQuery: rawQuery},
+		URL: &url.URL{Scheme: "http", Host: "docker", Path: path, RawPath: rawPath, RawQuery: rawQuery},
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/internal/proxy/hijack.go` around lines 479 - 498, Update
newUpstreamHijackRequest to preserve the original URL encoding by carrying
r.URL.RawPath into the constructed upstream URL when the supplied path equals
r.URL.Path; otherwise leave RawPath unset. Add a regression check around
writeHijackUpstreamRequest that verifies an encoded target such as %2F remains
encoded in the forwarded request.
🧹 Nitpick comments (2)
app/integration/podman_libpod_integration_test.go (1)

254-384: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Use a table-driven test structure.

Move the fixed scenario into a test-case table and run each case with t.Run. Keep the real Podman setup and raw TCP hijack assertion inside the subtest.

As per coding guidelines, “**/*_test.go: Write tests as table-driven tests using testing.T and httptest.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/integration/podman_libpod_integration_test.go` around lines 254 - 384,
Refactor TestLibpodExecStartEndToEndHijackAgainstRealPodman into a table-driven
test with a scenario table and t.Run subtests. Move the complete Podman setup,
exec-create flow, raw TCP hijack request, and echoed-output assertions inside
each subtest, preserving the existing behavior and cleanup.

Source: Coding guidelines

app/internal/proxy/hijack_libpod_test.go (1)

154-208: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use a table-driven test.

Convert this regression test to a test-case table. Keep the per-case request target, expected path, and expected query in the table. This makes additional Podman version-path cases local changes.

As per coding guidelines, “Write tests as table-driven tests using testing.T and httptest.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/internal/proxy/hijack_libpod_test.go` around lines 154 - 208, Convert
TestHandleHijack_LibpodExecStartPreservesVersionPrefix into a table-driven test
with cases containing the request target, expected forwarded path, and expected
query. Run each case with t.Run while preserving the existing hijack setup,
status, Host, URL, and raw forwarded-request assertions.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@app/internal/proxy/hijack.go`:
- Around line 479-498: Update newUpstreamHijackRequest to preserve the original
URL encoding by carrying r.URL.RawPath into the constructed upstream URL when
the supplied path equals r.URL.Path; otherwise leave RawPath unset. Add a
regression check around writeHijackUpstreamRequest that verifies an encoded
target such as %2F remains encoded in the forwarded request.

---

Nitpick comments:
In `@app/integration/podman_libpod_integration_test.go`:
- Around line 254-384: Refactor
TestLibpodExecStartEndToEndHijackAgainstRealPodman into a table-driven test with
a scenario table and t.Run subtests. Move the complete Podman setup, exec-create
flow, raw TCP hijack request, and echoed-output assertions inside each subtest,
preserving the existing behavior and cleanup.

In `@app/internal/proxy/hijack_libpod_test.go`:
- Around line 154-208: Convert
TestHandleHijack_LibpodExecStartPreservesVersionPrefix into a table-driven test
with cases containing the request target, expected forwarded path, and expected
query. Run each case with t.Run while preserving the existing hijack setup,
status, Host, URL, and raw forwarded-request assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 8fce1d65-5cd3-47cf-8cfb-ec15be051297

📥 Commits

Reviewing files that changed from the base of the PR and between a8360b4 and 35c4c29.

⛔ Files ignored due to path filters (1)
  • CHANGELOG.md is excluded by !CHANGELOG.md
📒 Files selected for processing (6)
  • app/integration/podman_libpod_integration_test.go
  • app/internal/cmd/serve_chain_test.go
  • app/internal/proxy/hijack.go
  • app/internal/proxy/hijack_libpod_test.go
  • app/internal/proxy/hijack_test.go
  • docs/content/docs/podman.mdx
💤 Files with no reviewable changes (1)
  • docs/content/docs/podman.mdx

newUpstreamHijackRequest built the outbound URL from r.URL.Path alone,
which is decoded (%2F becomes a literal /). With no RawPath set, a
url.URL re-derives EscapedPath() from the decoded Path, so an encoded
segment in a hijacked attach/exec-start target would collapse into a
different path on the wire than the client actually sent.

Now carries r.URL.RawPath into the constructed upstream URL whenever
path equals r.URL.Path (the production caller's case); left unset when
a caller substitutes a different path, since a stale RawPath wouldn't
describe it.

New tests: TestNewUpstreamHijackRequest_PreservesRawPathForEncodedSegments
and its negative counterpart (unit level), plus
TestHandleHijack_PreservesEncodedPathBytesUpstream, which checks the
actual forwarded bytes rather than just the parsed URL struct.

CodeRabbit review on #203.
Convert TestHandleHijack_LibpodExecStartPreservesVersionPrefix and
TestLibpodExecStartEndToEndHijackAgainstRealPodman to table-driven
tests per repo coding guidelines (t.Run subtests, case table for
what varies), matching the existing convention across the suite.

hijack_libpod_test.go gains a two-part Docker-style version prefix
case alongside the original three-part Podman semver case, plus a
case covering the RawPath/%2F fix from the preceding commit — an
encoded exec-ID segment must survive onto the wire unchanged.

podman_libpod_integration_test.go's acceptance test now runs the
full create -> exec-create -> exec-start round trip for two commands
(echo, with a trailing newline; printf, without), proving the
hijack frame decoding path for both shapes. Re-verified against a
real Podman machine (Podman 6.0.2 client / Libpod 5.8.1 server):
both subtests pass.

CodeRabbit review on #203.
@scttbnsn

scttbnsn commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Fixed — newUpstreamHijackRequest now carries r.URL.RawPath into the constructed upstream URL when path == r.URL.Path, so %2F etc. survive onto the wire instead of getting flattened. Added a unit test on the URL struct plus a wire-bytes check on the actual forwarded request. bd2cea9.

@scttbnsn

scttbnsn commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Done — hijack_libpod_test.go's TestHandleHijack_LibpodExecStartPreservesVersionPrefix is table-driven now, added a two-part version-prefix case and a %2F-encoding case (ties into the RawPath fix above). 337afb6.

@scttbnsn

scttbnsn commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Done — TestLibpodExecStartEndToEndHijackAgainstRealPodman is table-driven now (echo w/ trailing newline + printf w/o), setup/assertions moved inside the subtest. Re-ran it live against a real podman machine, both cases pass. 337afb6.

@scttbnsn
scttbnsn merged commit db8c738 into dev/v1.6 Aug 8, 2026
49 checks passed
@scttbnsn
scttbnsn deleted the fix/v1.6-hijack-libpod-path branch August 8, 2026 21:01

This branch was successfully deployed

1 active deployment
Preview — 337afb61 Deployed Aug 8, 2026 by vercel[bot]
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.

1 participant