Skip to content

🔒 security(filter): close case-varied JSON key bypass class + timeout parity - #134

Merged
scttbnsn merged 2 commits into
dev/v1.5from
security/v1.5-case-variant-bypass
Jul 11, 2026
Merged

scttbnsn merged 2 commits into
dev/v1.5from
security/v1.5-case-variant-bypass

Conversation

@scttbnsn

@scttbnsn scttbnsn commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

What

The v1.5 rc-blocker bundle surfaced by an adversarial correctness+completeness review of everything v1.5 touches. Two independent workflow passes each caught a real defect that per-PR review and CodeRabbit missed; a third pass returned GO.

🔒 Case-varied JSON key bypass class (the main event)

Docker decodes create/update body keys case-insensitively and, on duplicate case-variant keys, honors the last after re-encode. Go's json.Marshal emits map keys sorted, so a client's lowercase "image"/"hostconfig" sorts after — and overrides — the canonical key. Sockguard inspects via a case-insensitive struct decode, but several paths then re-marshal the body through a map whose re-sort moves a shadow key into the winning position, so the daemon acts on a value the filter never saw.

Pre-existing instances, all now closed fail-closed:

Path Impact Since
ownership label stamp forged com.sockguard.owner wins → owner-identity spoof v1.0
cross-owner namespace check shadow "hostconfig"/"networkmode" hides a container:<ref> join v1.5 (new check)
image-trust digest pin shadow "image" survives cosign, daemon pulls unverified image v1.1.0
whole-body reorder shadow "hostconfig"/nested "privileged" flips any already-cleared decision v1.0/v1.1

Fix: RejectDuplicateCaseVariantJSONKeys — recursively reject (400/403) any body with two strings.EqualFold keys, wired into all three re-marshal sites before they re-encode. A single lowercase variant is still collapsed to canonical so legit lowercased fields stay inspected/pinned. Docker's case-sensitive data maps (Labels, Sysctls, Volumes, EndpointsConfig, network/IPAM Options, LogConfig.Config, …) are exempt at their own keys but the walk still descends through them, so a struct nested inside a data map (an EndpointSettings, an IPAMConfig array element) keeps its fold check — no false positive on valid case-varying map keys, no bypass.

Also closes a verify→pull TOCTOU fail-open edge: if a cosign-verified image can't be digest-pinned, the request is now denied rather than forwarded with the unpinned tag.

🐛 Upstream-timeout follow/stream parity

The long-lived-request classifier matched only 1/true/0/false, but dockerd's httputils.BoolValue treats everything except ""/0/no/false/none as true. So logs?follow=yes streams forever at the daemon yet got cut off with a spurious 504 under the new 60s default, and stats?stream=no was wrongly exempted. Both now use daemon-accurate BoolValue/BoolValueOrDefault, and plugin pull/push/upgrade join the long-lived exemptions.

📝 Doc parity

Unlabeled-target namespace wording (config comment + configuration.mdx), tri-tool bundled-presets anchor (15 → 17), website v1.5 milestone bullet for allow_host_cgroupns.

Testing

  • All new behavior covered by Codex-authored regression tests: RejectDuplicateCaseVariantJSONKeys (31 exemption cases incl. per-field positive + sibling-guard + the two nested-struct guards proving IPAM.Config/EndpointsConfig values are still fold-checked), ownership middleware end-to-end, image-trust regressions, timeout follow/stream + plugin exemptions.
  • go test ./... green, golangci-lint 0 issues, full pre-push suite green (incl. go-fuzz, govulncheck).

Notes

The label-spoof (v1.0), image-trust (v1.1.0), and whole-body-reorder bypasses are live in released v1.4.x. Flagging for a possible v1.4.2 security backport decision separate from this v1.5 work.

Changelog

  • 🔒 Security: Reject duplicate case-variant JSON keys across container-create and ownership middleware mutation/remarshal paths to prevent ownership/namespace/image-trust reorder bypasses; added fail-closed recursive detection via RejectDuplicateCaseVariantJSONKeys while preserving Docker’s case-sensitive map keys only for the intended map-typed fields.
  • 🔒 Security: In image-trust enforce mode, deny verified images when the verified digest cannot be converted into a pinned reference.
  • 🔒 Security: Deny namespace-sharing joins for HostConfig.UTSMode (including container:<ref>) when restrict_namespace_sharing / ownership cross-owner sharing applies; added UTSMode coverage to ownership + namespace-sharing gates.
  • 🔧 Changed: Harden Docker Image rewriting for container-create and Swarm service payloads: fail-closed normalization to a single canonical Image key, collapse lowercase variants, and reject duplicate case-variant Image keys; preserve unrelated JSON fields.
  • 🔧 Changed: Align proxied long-lived request classification with Docker daemon query boolean parsing for follow/stream in logs/stats.
  • ✨ Added: Treat plugin registry operations as long-lived timeout-exempt: POST /plugins/pull, POST /plugins/*/push, and POST /plugins/*/upgrade.
  • 🔧 Changed: Clarify ownership.allow_cross_owner_namespace_sharing default behavior for unlabeled container:<ref> targets in docs/config and update related content.
  • ✨ Added: Regression + fuzz coverage for duplicate case-variant key rejection (including seeds for exempt data maps and nested arrays) and for the tightened image pinning/rewriting and namespace-sharing behavior.

Concerns / issues to address

  • Verify Docker “case-sensitive map” exemptions remain limited strictly to the intended map-typed keys and do not unintentionally allow other sibling case-variant key conflicts.
  • Confirm plugin long-lived matching cannot misclassify unintended plugin routes (path normalization and suffix/prefix handling).
  • Review JSON rewriting to ensure no assumptions about JSON key ordering/formatting outside what the updated tests assert.

… parity

Rc-blocker bundle surfaced by the v1.5 correctness+completeness review — a
recurring class where Docker decodes body keys case-insensitively (last
duplicate wins) but sockguard re-marshals some bodies through a map that
json.Marshal re-sorts, letting a shadow lowercase key win at the daemon a value
the struct-decode filter never saw.

- 🔒 security(filter,ownership): RejectDuplicateCaseVariantJSONKeys — reject
  fail-closed (400/403) any create/update body with duplicate case-variant JSON
  keys on every mutate-and-re-marshal path (owner-label stamp, image-digest pin,
  whole-body reorder). Closes owner-label spoofing (pre-existing since v1.0),
  cross-owner namespace hiding (v1.5-new check), and the cosign image-trust
  digest-pin bypass on containers/create + services/create,update (since v1.1.0).
  Case-insensitive collapse of a single lowercase variant keeps a legitimately
  lowercased field inspected and pinned.
- 🔒 security(filter): exempt Docker's case-sensitive data-map fields (Labels,
  Annotations, Sysctls, Volumes, ExposedPorts, PortBindings, network/IPAM
  Options, DriverOpts/Opts, LogConfig.Config, EndpointsConfig, IPAM aux
  addresses) from the duplicate-key check at their own keys, while still
  descending through them so a struct nested inside a data map (EndpointSettings,
  an IPAMConfig array element) keeps its fold check — no false-positive on valid
  case-varying map keys, no bypass.
- 🔒 security(filter): deny rather than forward when a cosign-verified image
  cannot be digest-pinned (PinnedReference error), closing the verify→pull
  TOCTOU fail-open edge in the container and service image-trust paths.
- 🐛 fix(proxy): parse ?follow=/?stream= with daemon-accurate BoolValue
  semantics (only ""/0/no/false/none are false; stream defaults true when
  absent), and add plugin pull/push/upgrade to the long-lived upstream-timeout
  exemptions — prevents a spurious 504 on follow=yes and a wrongly-exempted
  stream=no now that the deadline defaults on.
- 📝 docs: correct the unlabeled-target namespace wording (config comment +
  configuration.mdx — an unlabeled target is treated as untrusted and denied),
  fix the tri-tool bundled-presets anchor (15 → 17), and add the
  allow_host_cgroupns bullet to the website v1.5 milestone.
@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0daa2bd7-7380-4f8b-a058-bd458dafccd9

📥 Commits

Reviewing files that changed from the base of the PR and between 0ccf829 and 4b28026.

⛔ Files ignored due to path filters (1)
  • CHANGELOG.md is excluded by !CHANGELOG.md
📒 Files selected for processing (4)
  • app/internal/filter/container_create.go
  • app/internal/filter/container_create_test.go
  • app/internal/ownership/middleware.go
  • app/internal/ownership/middleware_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • app/internal/ownership/middleware.go
  • app/internal/filter/container_create.go
  • app/internal/filter/container_create_test.go
  • app/internal/ownership/middleware_test.go

📝 Walkthrough

Walkthrough

The pull request hardens Docker request handling across image trust, JSON rewriting, ownership middleware, and upstream timeout classification. Container and service image rewrites reject ambiguous case-variant keys and require successful digest pinning. Ownership processing normalizes case-insensitive namespace fields while rejecting duplicate variants. Docker-compatible query parsing and plugin endpoint exemptions update long-lived request detection. Configuration comments, documentation, a README link, and the roadmap were also updated.

Possibly related PRs

  • CodesWhat/sockguard#130: Modifies container-create cross-owner namespace-sharing enforcement in the ownership middleware.
🚥 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 security/v1.5-case-variant-bypass

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

@vercel

vercel Bot commented Jul 11, 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, Comment Jul 11, 2026 2:57am

@scttbnsn

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/internal/filter/container_create_test.go (1)

2154-2350: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a fuzz target for the JSON key validator.

RejectDuplicateCaseVariantJSONKeys is security-sensitive parsing; guidelines call for fuzzing filter/config parsing. A FuzzRejectDuplicateCaseVariantJSONKeys (stdlib, no deps) would exercise nesting/casing edge cases the table can't enumerate.

func FuzzRejectDuplicateCaseVariantJSONKeys(f *testing.F) {
	f.Add(`{"HostConfig":{"a":1},"hostconfig":{"b":2}}`)
	f.Add(`{"Labels":{"Foo":"1","foo":"2"}}`)
	f.Fuzz(func(t *testing.T, body string) {
		_ = RejectDuplicateCaseVariantJSONKeys([]byte(body)) // must not panic
	})
}

As per coding guidelines: "Use fuzz tests for filter matching and config parsing."

🤖 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/filter/container_create_test.go` around lines 2154 - 2350, Add a
standard-library fuzz test named FuzzRejectDuplicateCaseVariantJSONKeys
alongside TestRejectDuplicateCaseVariantJSONKeys. Seed it with representative
duplicate struct-field and case-sensitive data-object JSON inputs, then fuzz
arbitrary body strings and call RejectDuplicateCaseVariantJSONKeys without
asserting validity; the target must complete without panicking.

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.

Inline comments:
In `@app/internal/ownership/middleware.go`:
- Around line 365-407: Add "UTSMode" to the namespaceModeFields collection so
containerCreateNamespaceRefs also examines UTS namespace-sharing targets and
applies the existing cross-owner validation.

---

Nitpick comments:
In `@app/internal/filter/container_create_test.go`:
- Around line 2154-2350: Add a standard-library fuzz test named
FuzzRejectDuplicateCaseVariantJSONKeys alongside
TestRejectDuplicateCaseVariantJSONKeys. Seed it with representative duplicate
struct-field and case-sensitive data-object JSON inputs, then fuzz arbitrary
body strings and call RejectDuplicateCaseVariantJSONKeys without asserting
validity; the target must complete without panicking.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 24f51443-d146-4fae-a15d-a66d4e545330

📥 Commits

Reviewing files that changed from the base of the PR and between e7ae38f and 0ccf829.

⛔ Files ignored due to path filters (1)
  • CHANGELOG.md is excluded by !CHANGELOG.md
📒 Files selected for processing (12)
  • app/internal/config/config.go
  • app/internal/filter/container_create.go
  • app/internal/filter/container_create_test.go
  • app/internal/filter/service.go
  • app/internal/filter/service_test.go
  • app/internal/ownership/middleware.go
  • app/internal/ownership/middleware_test.go
  • app/internal/proxy/timeout.go
  • app/internal/proxy/timeout_test.go
  • docs/content/docs/configuration.mdx
  • examples/compose/tri-tool/README.md
  • website/src/lib/site-content.ts

Comment thread app/internal/ownership/middleware.go Resolved
Addresses CodeRabbit review on #134. HostConfig.UTSMode also honors the
container:<name|id> form (moby's UTSMode has an IsContainer/Container form), so
it belongs in the same namespace-sharing checks as NetworkMode/PidMode/IpcMode.
It was missing from both, letting a UTS-namespace join slip past.

- 🔒 security(ownership): add UTSMode to namespaceModeFields so the cross-owner
  container:<ref> check (ownership.owner deployments) resolves and denies a
  foreign-owner UTS-namespace join.
- 🔒 security(filter): add UTSMode to denyNamespaceSharingReason so the opt-in
  restrict_namespace_sharing gate scopes UTS container:<ref> joins too, and
  correct the stale comment that claimed Docker has no container: form for UTS.
- 🧪 test: cross-owner UTS deny (exact + lowercase-key) in ownership, UTSMode
  rows in the restrict_namespace_sharing matrix, and a FuzzRejectDuplicate
  CaseVariantJSONKeys stdlib fuzz target for the security-sensitive body walker.
- 📝 docs(changelog): note UTSMode in the namespace-sharing bullets.
@scttbnsn

Copy link
Copy Markdown
Contributor Author

Both addressed in 4b28026:

  • UTSMode — good catch, it does honor container:<ref> (moby's UTSMode has an IsContainer/Container form). Added it to namespaceModeFields (cross-owner check) and to denyNamespaceSharingReason (the restrict_namespace_sharing gate), which had a stale comment claiming Docker has no container: form for UTS. Cross-owner UTS deny tests (exact + lowercase-key) and restrict-matrix UTS rows added.
  • Fuzz target — added FuzzRejectDuplicateCaseVariantJSONKeys next to the table test, seeded with the struct-dup / exempt-map / nested-struct-array cases. Ran ~334k execs, no crashers.

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
git log --oneline -5
git show 4b28026 --stat || true
echo "---UTSMode---"
rg -n "UTSMode" app/internal/ownership/middleware.go app/internal/ownership/middleware_test.go
echo "---namespaceModeFields---"
rg -n "namespaceModeFields" -A10 app/internal/ownership/middleware.go | head -60
echo "---denyNamespaceSharingReason---"
rg -n "denyNamespaceSharingReason" -A40 app/internal/filter -R 2>/dev/null | head -100
echo "---Fuzz target---"
rg -n "FuzzRejectDuplicateCaseVariantJSONKeys" -A30 app/internal/filter/container_create_test.go

Length of output: 5703


🏁 Script executed:

#!/bin/bash
set -euo pipefail
rg -n "denyNamespaceSharingReason" -A40 app/internal/filter/*.go | head -80
echo "---fuzz---"
rg -n "FuzzRejectDuplicateCaseVariantJSONKeys" -A30 app/internal/filter/container_create_test.go
echo "---CHANGELOG---"
git show 4b28026 -- CHANGELOG.md

Length of output: 20234


@scttbnsn Confirmed both fixes in 4b28026:

  • UTSMode now in namespaceModeFields (middleware.go:370) and denyNamespaceSharingReason (container_create.go:783-796), stale no-container-form comment corrected. Cross-owner exact/lowercase-key tests and restrict-matrix rows present.
  • FuzzRejectDuplicateCaseVariantJSONKeys seeded with struct-dup, exempt-map, nested-array cases at container_create_test.go:2354.

No gaps in this diff. Triggering full review pass.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

This branch was successfully deployed

1 active deployment
Preview — 4b280264 Deployed Jul 11, 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