From 5fe85b889cab62574ff7c94d9c0300ab110f0665 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Tue, 17 Nov 2026 01:38:53 +0000 Subject: [PATCH 1/4] fix(githttp): cut the unknown ref policy op that a push refusal quotes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The update hook refused a ref policy op that it does not know with `unknown policy op %q for `, which repeats the op whole on git's stderr, and git shows that line to the pusher. The op is text of the pusher's token and can be as long as an environment entry allows. The ref, commit and merge writes of the API already quote the same op with errtext.Quote (#902). The hook now quotes it with errtext.Quote too: an op over 256 bytes is cut and followed by its length. This is the server's own refusal text, not a pattern that reads git's stderr. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_ Change-Id: I67245cd17be12a5aaad3b4cf130c2f80326f8c8b Signed-off-by: Thomas Kosiewski --- internal/errtext/README.md | 1 + internal/githttp/hook.go | 7 +++-- internal/githttp/hook_unknown_op_test.go | 40 ++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 internal/githttp/hook_unknown_op_test.go diff --git a/internal/errtext/README.md b/internal/errtext/README.md index f7da8d68..cf47ff77 100644 --- a/internal/errtext/README.md +++ b/internal/errtext/README.md @@ -21,6 +21,7 @@ Bounds the request text that an error answer repeats, so that an answer stays sm - `api` quotes a ref policy op that a ref, commit or merge write does not know (`unknown policy op "x" for `) [../api/handlers_write_refs.go:wrefPolicyCheck] [../api/handlers_write_commit.go:wcCheckRefPolicy] [../api/handlers_write_merge.go:server.wmCheckRefPolicy] - `events` quotes a webhook URL or its host in a registration refusal, and cuts the parse error it adds after a URL that does not parse (`CheckRegistration`) [../events/guard.go:CheckRegistration] - `githttp` cuts the error text of the git and LFS routes [../githttp/server.go:httpError] [../githttp/lfs.go:lfsError] +- `githttp` quotes a ref policy op that the update hook does not know, in the refusal that git shows the pusher (`evalRefPolicy`) [../githttp/hook.go:evalRefPolicy] ## Verification - Run: `go test ./internal/errtext/... -tags=openstorage_viewcheck -count=1 -race -timeout=30m` diff --git a/internal/githttp/hook.go b/internal/githttp/hook.go index e613c14d..f8c22d21 100644 --- a/internal/githttp/hook.go +++ b/internal/githttp/hook.go @@ -24,6 +24,7 @@ import ( "github.com/coder/openstorage/internal/auth" "github.com/coder/openstorage/internal/blob" "github.com/coder/openstorage/internal/envconfig" + "github.com/coder/openstorage/internal/errtext" "github.com/coder/openstorage/internal/gitlimit" "github.com/coder/openstorage/internal/meta" "github.com/coder/openstorage/internal/ref" @@ -2426,8 +2427,10 @@ func evalRefPolicy(ctx context.Context, repo, refName, old, new string, fullEval needsSig = true } default: - // Unknown policy ops fail closed. - return refusef("unknown policy op %q for %s", op, refName) + // Unknown policy ops fail closed. The op is text of the + // pusher's token, as long as an environment entry allows, so + // the refusal quotes it cut (errtext.Quote), as the API does. + return refusef("unknown policy op %s for %s", errtext.Quote("", op), refName) } } if needsAncestry { diff --git a/internal/githttp/hook_unknown_op_test.go b/internal/githttp/hook_unknown_op_test.go new file mode 100644 index 00000000..6fabf65a --- /dev/null +++ b/internal/githttp/hook_unknown_op_test.go @@ -0,0 +1,40 @@ +package githttp + +import ( + "encoding/json" + "strings" + "testing" + + "github.com/coder/openstorage/internal/ref" +) + +// TestUnknownPolicyOpRefusalQuotedBounded: the update hook refuses a ref +// policy op that it does not know with a refusal that git shows the +// pusher, and quotes the op with errtext.Quote, so an op of any length +// makes a short line. The reservation classifier (fullEval off) gives the +// same refusal. +func TestUnknownPolicyOpRefusalQuotedBounded(t *testing.T) { + const refName = "refs/heads/main" + newSHA := strings.Repeat("a", 40) + for _, tc := range []struct{ name, op, quoted string }{ + {"a long op", strings.Repeat("<", 100_000), `"` + strings.Repeat("<", 256) + `…" (100000 bytes)`}, + {"a short op", "no-fly", `"no-fly"`}, + {"a short op with a quote", `no"fly`, `"no\"fly"`}, + } { + t.Run(tc.name, func(t *testing.T) { + claim, err := json.Marshal([][]any{{"*", []string{tc.op}}}) + if err != nil { + t.Fatal(err) + } + t.Setenv(EnvRefsPolicy, string(claim)) + t.Setenv(EnvOps, "") + want := "unknown policy op " + tc.quoted + " for " + refName + for _, fullEval := range []bool{true, false} { + err := evalRefPolicy(t.Context(), "repo", refName, ref.ZeroSHA, newSHA, fullEval) + if err == nil || err.Error() != want || !ShownToPusher(err) { + t.Fatalf("evalRefPolicy(fullEval=%v) = %.300v; want a refusal %.300q", fullEval, err, want) + } + } + }) + } +} From e5769b0fe4aab888c0a9089110401ac630943941 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Tue, 17 Nov 2026 01:47:41 +0000 Subject: [PATCH 2/4] chore: re-record the lane-schedule fingerprints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hook.go is covered code: evalRefPolicy quotes an unknown op with errtext.Quote. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_ Change-Id: I720e36ba852e4a43db4cc3be6ea393253143f485 Signed-off-by: Thomas Kosiewski --- .agents/skills/verify-lane-schedule/SKILL.md | 2 +- .agents/skills/verify-lane-schedule/model/fingerprints.txt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.agents/skills/verify-lane-schedule/SKILL.md b/.agents/skills/verify-lane-schedule/SKILL.md index ae63fe6d..c6bfc86c 100644 --- a/.agents/skills/verify-lane-schedule/SKILL.md +++ b/.agents/skills/verify-lane-schedule/SKILL.md @@ -226,7 +226,7 @@ With every fact TRUE in the code, setting each fact FALSE in the model alone fai ## Coverage record -Sync commit: `2e98dad6dd886941543d266b99fed69d8b34b17d` (the last commit at which someone confirmed that the model describes this code; only `check.sh --record` moves it). +Sync commit: `5fe85b889cab62574ff7c94d9c0300ab110f0665` (the last commit at which someone confirmed that the model describes this code; only `check.sh --record` moves it). Every declaration in these files is covered: diff --git a/.agents/skills/verify-lane-schedule/model/fingerprints.txt b/.agents/skills/verify-lane-schedule/model/fingerprints.txt index d11ce3d7..73dec12b 100644 --- a/.agents/skills/verify-lane-schedule/model/fingerprints.txt +++ b/.agents/skills/verify-lane-schedule/model/fingerprints.txt @@ -196,7 +196,7 @@ internal/githttp/hook.go:denyAuthorityDFConflict 3ad4a9b7cd317dbae7ebf368256b119 internal/githttp/hook.go:denyUnregisteredTargets 30226947720bb73dd56445e7227c26ae7647ccc04f4cfcaa61498129f47accca internal/githttp/hook.go:enforceRefPolicy 2cd2cf6aea243221e8fe27280a6333695d4455a0304e7f536f7e8729dbb17a4d internal/githttp/hook.go:enforceSyncClaimFence efb7b07e54bbb4008ac0cf53778c2ba690ad936051c103421aaf308b52e1cdf9 -internal/githttp/hook.go:evalRefPolicy b232fd0a747ced157cec1bc4588e53bc13c54a39ff829f45108ae62c9601b5c8 +internal/githttp/hook.go:evalRefPolicy fb4caa5bb76c4e050699f03b3790a91c1fb8191e09918134f2b73dc0a1ed7d8d internal/githttp/hook.go:gitRefSegmentValid be11ac7ba983b399f85ec59e9ac524d9d95329fe7c774f011934bf97b1b26cf7 internal/githttp/hook.go:gitRefusalProbe.reaches 938ddcf9757e6b985bb3662f50b9fba53f51125d2d343ee8e0fff13ad530c065 internal/githttp/hook.go:hiddenOnRemote 91f396bdce763dd700bf642823435bfc3cec17f641d83f07af33f96ceacbe254 @@ -211,6 +211,7 @@ internal/githttp/hook.go:import_"fmt" 7b04a3fec895247a2e6af9e527c6e53593a4afd23c internal/githttp/hook.go:import_"github.com/coder/openstorage/internal/auth" a6fc462be510789f5df8f2fd769b94612c4099fecfdd8be88a7a6b4ac6f12b03 internal/githttp/hook.go:import_"github.com/coder/openstorage/internal/blob" 7bbbe200b75dfad8f71f423fbf2bcd8ea49a5a98632059d22d77c4dc072e4026 internal/githttp/hook.go:import_"github.com/coder/openstorage/internal/envconfig" c05488126ab766402890a210f9a6b0cd8b6b3fb600c970209410bbafa6252d73 +internal/githttp/hook.go:import_"github.com/coder/openstorage/internal/errtext" f1419e850961b9c71ddb7ebed6d98ca1a156fef54592d2fbe6bd0adbd42bff6b internal/githttp/hook.go:import_"github.com/coder/openstorage/internal/gitlimit" 22f3f7dc1edac8d75858f1fe4ebcf09e7a520d8bdc31a4fb27a401f06cf288dd internal/githttp/hook.go:import_"github.com/coder/openstorage/internal/meta" 4260dc2e40a07d98bb999c941803200e032f17530aab6c21fd272ac3fcd2fdb6 internal/githttp/hook.go:import_"github.com/coder/openstorage/internal/ref" 47381ca0e8ca453365ce8da40c529fc6f1fe3b6b1d26847f2298f92d1377d520 From 7b38d46f88482c14200ad035b715fd40f0d23a58 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Tue, 17 Nov 2026 02:47:37 +0000 Subject: [PATCH 3/4] chore: re-record the lane-schedule sync commit after the merge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The merge brought #905's worker.go and worker_push.go fingerprints; TLC passes on the merged tree, so the sync commit moves to it. No fingerprint changes. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_ Change-Id: If8b8572d273d3071d1ccc2f0470d5881b0066b2d Signed-off-by: Thomas Kosiewski --- .agents/skills/verify-lane-schedule/SKILL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.agents/skills/verify-lane-schedule/SKILL.md b/.agents/skills/verify-lane-schedule/SKILL.md index c6bfc86c..dc1664cb 100644 --- a/.agents/skills/verify-lane-schedule/SKILL.md +++ b/.agents/skills/verify-lane-schedule/SKILL.md @@ -226,7 +226,7 @@ With every fact TRUE in the code, setting each fact FALSE in the model alone fai ## Coverage record -Sync commit: `5fe85b889cab62574ff7c94d9c0300ab110f0665` (the last commit at which someone confirmed that the model describes this code; only `check.sh --record` moves it). +Sync commit: `71947bcc360301c223b108b1f6f17332199cdb38` (the last commit at which someone confirmed that the model describes this code; only `check.sh --record` moves it). Every declaration in these files is covered: From 2e15bab7d0fd94cbfcc3b455b9726bc7839cdc9c Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Tue, 17 Nov 2026 02:47:47 +0000 Subject: [PATCH 4/4] test(githttp): name the budget-free evaluation in the unknown-op test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The review of #906 noted that the reservation classifier turns this refusal into a reservation denial; what gives the same refusal is evalRefPolicy with fullEval off, which the classifier runs. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_ Change-Id: I085e995d3a81dad9b7db3c5fddd64c066d7eaa12 Signed-off-by: Thomas Kosiewski --- internal/githttp/hook_unknown_op_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/githttp/hook_unknown_op_test.go b/internal/githttp/hook_unknown_op_test.go index 6fabf65a..573846a8 100644 --- a/internal/githttp/hook_unknown_op_test.go +++ b/internal/githttp/hook_unknown_op_test.go @@ -11,8 +11,8 @@ import ( // TestUnknownPolicyOpRefusalQuotedBounded: the update hook refuses a ref // policy op that it does not know with a refusal that git shows the // pusher, and quotes the op with errtext.Quote, so an op of any length -// makes a short line. The reservation classifier (fullEval off) gives the -// same refusal. +// makes a short line. The budget-free evaluation (fullEval off), which +// the reservation classifier runs, gives the same refusal. func TestUnknownPolicyOpRefusalQuotedBounded(t *testing.T) { const refName = "refs/heads/main" newSHA := strings.Repeat("a", 40)