From 3ba49a58917aa8d79c8a6307bd577c4ea8e6945d Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Mon, 16 Nov 2026 22:02:19 +0000 Subject: [PATCH 1/7] fix(api): refuse an upstream host that no sync run resolves as given MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit POST /repos stored upstream hosts that the registration check could not vet and that the run could not use as given: - a hostname that Go's resolver refuses before it asks DNS, such as `<<<.com` or an IPv4 literal with a zone (`https://1.2.3.4%25eth0`): the courtesy check failed open, the create answered 201, and every run failed; - a name of only digits and dots that is no IP address, such as `2130706433`, `1.2.3` or `01.2.3.4`: curl reads them as 127.0.0.1, 1.2.0.3 and 1.2.3.4, so the run dialed an address that the registration check never saw (the dial-time guard still vets it); - a port outside 1-65535; - a base URL with a query or a fragment, even an empty one (`https://h?`), which ends the path of every fetch URL. validUpstreamHost now also requires a dialable authority: an IP address without a zone, or a name that passes the rule of Go's resolver (net.isDomainName: at most 253 bytes, labels of 1 to 63 letters, digits, '_' and '-', not only digits and dots); a port from 1 to 65535; and no '?' or '#' in a base URL. Such a host answers 400 `is not a valid host` in both host fields, as any other invalid host does. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_ Change-Id: I962873fa0be93de3eb41a79ac0805a745e5200a2 Signed-off-by: Thomas Kosiewski --- docs/reference/http-api.md | 8 +- internal/api/handlers_sync.go | 79 ++++++++++++-- internal/api/upstream_host_shape_test.go | 128 +++++++++++++++++++++++ 3 files changed, 205 insertions(+), 10 deletions(-) create mode 100644 internal/api/upstream_host_shape_test.go diff --git a/docs/reference/http-api.md b/docs/reference/http-api.md index 51c69d89..ea8747f1 100644 --- a/docs/reference/http-api.md +++ b/docs/reference/http-api.md @@ -404,7 +404,13 @@ the same scopes, query parameters and responses. open.storage does not have → 400. To sync a private GitHub repository, use the deprecated `base_repo` sync form with `auth.token`. - `host`: a bare `hostname[:port]`, or (open.storage extension) an `http(s)://` base - URL like `base_repo.upstream_host`. It defaults to the provider's public host. + URL like `base_repo.upstream_host`. It defaults to the provider's public host. Both + host fields take only what a sync run can dial as given: an IP address without a + zone, or a DNS name of at most 253 bytes whose labels hold 1 to 63 letters, digits, + `_` and `-` and do not start or end with `-`, and that is not only digits and dots + (`2130706433` → 400: curl would dial it as `127.0.0.1`); a port from 1 to 65535; and + a base URL with no `?` or `#`, even an empty one (`https://forge.example?` → 400). Any + other host → 400 `is not a valid host`. - No credential is stored at create. For a private non-GitHub upstream, add one with `POST /repos/git-credentials`, then call `pull-upstream`. - `upstream` has no `forward_pushes`; use the deprecated `base_repo` sync form to opt in. diff --git a/internal/api/handlers_sync.go b/internal/api/handlers_sync.go index ed6cc44c..5b7a2fc4 100644 --- a/internal/api/handlers_sync.go +++ b/internal/api/handlers_sync.go @@ -365,9 +365,12 @@ func (cfg upstreamConfig) validate(errs *bodyErrors) (host string) { // query/fragment noise must be rejected here, where the attacker-controlled // value enters (the worker additionally pins GIT_ALLOW_PROTOCOL). // -// A zone-scoped IPv6 address (fe80::1%25eth0) is refused too. The egress -// guard refuses it under every policy, so no run could use it, and the -// egress answer repeats the hostname, whose zone can be any length. +// It also refuses what no sync run can use, so the create answers 400 +// instead of storing a link whose every run fails: a hostname that is +// neither an IP address nor a name the run's resolver looks up +// (dialableHostname), a port outside 1-65535, and a base URL with a query +// or a fragment, even an empty one (`https://h?`), which would end the +// path of every fetch URL. func validUpstreamHost(host string) bool { assertf(host != "", "validUpstreamHost: empty host") if !strings.Contains(host, "://") { @@ -376,19 +379,77 @@ func validUpstreamHost(host string) bool { // is written %25, which the parse decodes, so it never // round-trips. u, err := neturl.Parse("https://" + host) - return err == nil && u.Host == host && u.Hostname() != "" && u.User == nil && - u.Path == "" && u.RawQuery == "" && u.Fragment == "" + return err == nil && u.Host == host && u.User == nil && + u.Path == "" && u.RawQuery == "" && u.Fragment == "" && dialableAuthority(u) } u, err := neturl.Parse(host) if err != nil || (u.Scheme != "http" && u.Scheme != "https") { return false } - if ip, err := netip.ParseAddr(u.Hostname()); err == nil && ip.Zone() != "" { + // A path is allowed (sub-path-hosted forges); credentials belong in + // the credential store, never in the URL. url.Parse drops an empty + // query or fragment, so the bytes are checked. + return u.User == nil && !strings.ContainsAny(host, "?#") && dialableAuthority(u) +} + +// dialableAuthority reports whether the host and port of u name something +// that a sync run can dial: a dialableHostname and, when u has one, a port +// from 1 to 65535. +func dialableAuthority(u *neturl.URL) bool { + if port := u.Port(); port != "" { + if n, err := strconv.Atoi(port); err != nil || n < 1 || n > 65535 { + return false + } + } + return dialableHostname(u.Hostname()) +} + +// dialableHostname reports whether name is an IP address without a zone, +// or a name that the resolver of a sync run looks up. A run dials through +// the egress proxy (upsync.startEgressProxy), whose Go resolver refuses any +// other name before it asks DNS (net.isDomainName, after RFC 1035 and RFC +// 3696): at most 253 bytes, or 254 with a final dot; labels of 1 to 63 +// letters, digits, '_' and '-' that do not start or end with '-'; and not +// only digits and dots, which curl reads as an IPv4 address (2130706433 is +// 127.0.0.1) that the registration check never saw. A zone-scoped address +// (fe80::1%eth0) is refused: +// the egress guard refuses it under every policy, and the egress answer +// would repeat a zone of any length. +func dialableHostname(name string) bool { + if ip, err := netip.ParseAddr(name); err == nil { + return ip.Zone() == "" + } + if name == "" || len(name) > 254 || len(name) == 254 && name[253] != '.' { return false } - // A path is allowed (sub-path-hosted forges); credentials belong in - // the credential store, never in the URL. - return u.Hostname() != "" && u.User == nil && u.RawQuery == "" && u.Fragment == "" + prev := byte('.') + letters := false // a letter, '_' or '-': all digits would be an address + label := 0 + for i := 0; i < len(name); i++ { + c := name[i] + switch { + case 'a' <= c && c <= 'z', 'A' <= c && c <= 'Z', c == '_': + letters = true + label++ + case '0' <= c && c <= '9': + label++ + case c == '-': + if prev == '.' { + return false + } + letters = true + label++ + case c == '.': + if prev == '.' || prev == '-' || label > 63 { + return false + } + label = 0 + default: + return false + } + prev = c + } + return prev != '-' && label <= 63 && letters } // upstreamHostname extracts the hostname the sync fetch will dial from a diff --git a/internal/api/upstream_host_shape_test.go b/internal/api/upstream_host_shape_test.go new file mode 100644 index 00000000..87209c36 --- /dev/null +++ b/internal/api/upstream_host_shape_test.go @@ -0,0 +1,128 @@ +package api + +import ( + "encoding/json" + "net/http" + "strconv" + "strings" + "testing" +) + +// TestValidUpstreamHost: an upstream host is a bare host[:port] or an +// http(s) base URL whose hostname a sync run can dial: an IP address +// without a zone, or a name that Go's resolver looks up (net.isDomainName), +// with a port from 1 to 65535 and no query or fragment. +func TestValidUpstreamHost(t *testing.T) { + label63 := strings.Repeat("a", 63) + // 63+1+63+1+63+1+61 = 253 bytes, the longest name without a final dot. + name253 := label63 + "." + label63 + "." + label63 + "." + strings.Repeat("b", 61) + for _, host := range []string{ + "forge.example", + "forge.example.", + "FORGE.Example:8443", + "a_b.example", + "xn--bcher-kva.example", + "localhost", + "1forge.example", + label63 + ".example", + name253, + name253 + ".", + "10.0.0.1", + "10.0.0.1:1", + "[::1]:65535", + "[2001:db8::1]", + "https://forge.example", + "https://forge.example/sub/path/", + "http://127.0.0.1:3000", + "https://[2001:db8::1]:443/git", + "https://forge.example/a%3Fb", + } { + if !validUpstreamHost(host) { + t.Errorf("validUpstreamHost(%q) = false, want true", host) + } + } + for _, host := range []string{ + // Names that the resolver refuses. + "<<<.com", + "https://<<<.com", + "bücher.example", + "https://bücher.example", + "a..b.example", + ".forge.example", + "-forge.example", + "forge-.example", + "forge.-example", + "forge.example-", + label63 + "a.example", + name253 + "a", + name253 + "a.", + ".", + // Only digits and dots, but no IP address: curl would read + // 2130706433 as 127.0.0.1, Go's resolver refuses it. + "2130706433", + "1.2.3", + "https://1.2.3", + "01.2.3.4", + // A zone. + "https://1.2.3.4%25eth0", + "https://[fe80::1%25eth0]", + "[fe80::1%25eth0]", + // Ports. + "forge.example:0", + "forge.example:65536", + "https://forge.example:99999/git", + // A query or fragment, even an empty one. + "https://forge.example?", + "https://forge.example#", + "https://forge.example/git?", + "https://forge.example/git?a=b", + "https://forge.example/git#x", + // Unchanged refusals. + ":80", + "https://:80", + "forge.example/git", + "ssh://forge.example", + "https://u:p@forge.example", + } { + if validUpstreamHost(host) { + t.Errorf("validUpstreamHost(%q) = true, want false", host) + } + } +} + +// TestSyncCreateRefusesUndialableHosts: POST /repos refuses, with 400 +// before anything is stored, a host that no sync run could use, in both +// host fields. Before, the create answered 201 and every run failed. +func TestSyncCreateRefusesUndialableHosts(t *testing.T) { + runBackends(t, func(t *testing.T, e *testEnv) { + org := e.newOrg(t) + for _, host := range []string{"<<<.com", "https://1.2.3.4%25eth0", "https://forge.example?", "2130706433", "forge.example:65536"} { + for _, field := range []struct{ name, body, msg string }{ + {"upstream.host", `{"upstream":{"provider":"gitea","owner":"o","name":"n","host":%s}}`, "invalid upstream host "}, + {"base_repo.upstream_host", `{"base_repo":{"provider":"gitea","owner":"o","name":"n","upstream_host":%s}}`, "invalid base_repo upstream_host "}, + } { + t.Run(field.name+" "+host, func(t *testing.T) { + name := "undialable-" + randomHex(t, 4) + tok := e.mint(t, tokenSpec{iss: org, repo: name, scopes: []string{"repo:write"}}) + quoted, err := json.Marshal(host) + if err != nil { + t.Fatal(err) + } + resp, out := e.doReq(t, http.MethodPost, "/api/v1/repos", tok, []byte(strings.Replace(field.body, "%s", string(quoted), 1)), "") + var p problemBody + if err := json.Unmarshal(out, &p); err != nil { + t.Fatal(err) + } + wantDetail := field.msg + strconv.Quote(host) + if resp.StatusCode != http.StatusBadRequest || p.Detail != wantDetail || + len(p.InvalidParams) != 1 || p.InvalidParams[0].Name != field.name || p.InvalidParams[0].Reason != "is not a valid host" { + t.Fatalf("status %d, body %s; want 400 %q naming %s", resp.StatusCode, out, wantDetail, field.name) + } + if _, err := e.store.GetRepoByURL(t.Context(), org, name); err == nil { + t.Fatal("the refused create stored a repository") + } + }) + } + } + }) +} From c5b0d3699572f48ff910cb83d395cdaa8fb37d57 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Mon, 16 Nov 2026 22:11:41 +0000 Subject: [PATCH 2/7] chore: re-record the lane-schedule fingerprints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit handlers_sync.go is covered code: validUpstreamHost and the new dialableAuthority and dialableHostname. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_ Change-Id: I5138f4324d2d709f49fab59b06c14a9308a4d86c Signed-off-by: Thomas Kosiewski --- .agents/skills/verify-lane-schedule/SKILL.md | 2 +- .agents/skills/verify-lane-schedule/model/fingerprints.txt | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.agents/skills/verify-lane-schedule/SKILL.md b/.agents/skills/verify-lane-schedule/SKILL.md index 6f1770be..111f01cf 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: `d83f28bad0c0ac98fbdfa500806a73d7cf578ebc` (the last commit at which someone confirmed that the model describes this code; only `check.sh --record` moves it). +Sync commit: `3ba49a58917aa8d79c8a6307bd577c4ea8e6945d` (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 97df3afd..ffb97e6f 100644 --- a/.agents/skills/verify-lane-schedule/model/fingerprints.txt +++ b/.agents/skills/verify-lane-schedule/model/fingerprints.txt @@ -70,6 +70,8 @@ internal/api/handlers_sync.go:const_pullUpstreamAcceptedMsg 76a52910111a2580c149 internal/api/handlers_sync.go:const_pushUpstreamAcceptedMsg a2ae388107c13efba0294df359ec78e2d5b92bbb2774f068e5507891b5fea698 internal/api/handlers_sync.go:const_upstreamAppAccessMsg e754e2f035f781ed53cc2ee4cf96a4ee8988a87fa93954aca9989c2040b75599 internal/api/handlers_sync.go:deprecated 3227984a4c52242a8804346ff26305a40483c81f04ead54d0ab913daa01daa24 +internal/api/handlers_sync.go:dialableAuthority 272fc206a7652abebab23cc8b90a106a7a2f4571277f9c52ae0ef0b63f3397bc +internal/api/handlers_sync.go:dialableHostname d357f523b66b4a6897e68bfcff6006eae5026600ad1da59c0e488f8b9292af5e internal/api/handlers_sync.go:import_"bytes" 151fc787b0679fc8767e367d1971b9f907660a3d72d8fa3888877ef9f8ebd9c3 internal/api/handlers_sync.go:import_"cmp" 6ee637994d3b529ead32b904453999f4347fa28f1bba3d141f490cbf02e1f7cc internal/api/handlers_sync.go:import_"context" 35d620b75b6b66f8c228f26b970a741d77137e4e691aa896119dd9d000eaadd2 @@ -117,7 +119,7 @@ internal/api/handlers_sync.go:type_usyncPushUpstreamRequest 3ad57ba2d21ad394741c internal/api/handlers_sync.go:upstreamConfig.validate 5d6cda757706a13060fb8b917b6931dd5927bf427d038cd707471b23ae4b555f internal/api/handlers_sync.go:upstreamHostname f65b41a625e2606e71c567cbc6d99d991e59b6ef4da9e976294b9ff3895aac34 internal/api/handlers_sync.go:upstreamURLProblem e66d2c29ef48b6891a62cca5ace9afbd52d579f5f4ae11aeba3cc61b3f3c488d -internal/api/handlers_sync.go:validUpstreamHost f63de7d7ddea98fa3760cd88a1077488c937d0aae1dcf51e8aa30075618027af +internal/api/handlers_sync.go:validUpstreamHost b3cbac2d7cead6e97c32967d63ff104c3542e40b3b149398f0a215b4fccde75b internal/api/handlers_sync.go:validateSyncBaseRepo 0d0acd7ad181d241c2da2a6e48dfaa23aed47c8847cfb8a4992e3693056c2ed1 internal/api/handlers_sync.go:withStrictPullBody 449923a2f639f42183416d391cac81b304bcf8b6cda9d207474e66e16178766f internal/api/handlers_sync.go:withUpstreamDetach b16659bb293b5f9eb05b5ade652dfe4fb224e8a7b6c475829007ee1933a164ec From 2b1a6a1f4a8eeb97b2b1bd141a2b9b8d73ab1f09 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Mon, 16 Nov 2026 22:11:58 +0000 Subject: [PATCH 3/7] docs(api): give a non-ASCII upstream name in its ASCII form MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit curl refuses bücher.example as a bad URL, so the host rule says so, and the dialableHostname comment says what bounds a zone the egress answer would repeat. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_ Change-Id: I410340caebd88cf2c0996dbc8b4c69cfbbfb51c3 Signed-off-by: Thomas Kosiewski --- docs/reference/http-api.md | 7 ++++--- internal/api/handlers_sync.go | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/reference/http-api.md b/docs/reference/http-api.md index ea8747f1..f37fdc22 100644 --- a/docs/reference/http-api.md +++ b/docs/reference/http-api.md @@ -408,9 +408,10 @@ the same scopes, query parameters and responses. host fields take only what a sync run can dial as given: an IP address without a zone, or a DNS name of at most 253 bytes whose labels hold 1 to 63 letters, digits, `_` and `-` and do not start or end with `-`, and that is not only digits and dots - (`2130706433` → 400: curl would dial it as `127.0.0.1`); a port from 1 to 65535; and - a base URL with no `?` or `#`, even an empty one (`https://forge.example?` → 400). Any - other host → 400 `is not a valid host`. + (`2130706433` → 400: curl would dial it as `127.0.0.1`); a name with other letters + goes in its ASCII form (`xn--bcher-kva.example`, not `bücher.example`); a port from 1 + to 65535; and a base URL with no `?` or `#`, even an empty one + (`https://forge.example?` → 400). Any other host → 400 `is not a valid host`. - No credential is stored at create. For a private non-GitHub upstream, add one with `POST /repos/git-credentials`, then call `pull-upstream`. - `upstream` has no `forward_pushes`; use the deprecated `base_repo` sync form to opt in. diff --git a/internal/api/handlers_sync.go b/internal/api/handlers_sync.go index 5b7a2fc4..2a5b5997 100644 --- a/internal/api/handlers_sync.go +++ b/internal/api/handlers_sync.go @@ -411,10 +411,11 @@ func dialableAuthority(u *neturl.URL) bool { // 3696): at most 253 bytes, or 254 with a final dot; labels of 1 to 63 // letters, digits, '_' and '-' that do not start or end with '-'; and not // only digits and dots, which curl reads as an IPv4 address (2130706433 is -// 127.0.0.1) that the registration check never saw. A zone-scoped address -// (fe80::1%eth0) is refused: -// the egress guard refuses it under every policy, and the egress answer -// would repeat a zone of any length. +// 127.0.0.1) that the registration check never saw. A name with other +// letters goes in its ASCII form (xn--bcher-kva.example): curl refuses +// bücher.example as a bad URL. A zone-scoped address (fe80::1%eth0) is +// refused: the egress guard refuses it under every policy, and the egress +// answer would repeat its zone, which only the upstream URL limit bounds. func dialableHostname(name string) bool { if ip, err := netip.ParseAddr(name); err == nil { return ip.Zone() == "" From bfffd0944feb75e5518bfca05d2349911f44a192 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Mon, 16 Nov 2026 22:44:08 +0000 Subject: [PATCH 4/7] fix(api): refuse the hex IPv4 forms, an upper-case scheme and a space MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit curl reads a host such as 0x7f000001, 0x7f.1 or 1.2.3.0x4 as an IPv4 address (127.0.0.1, 1.2.3.4), as it does 2130706433, but the letter x let it pass the resolver rule. curlIPv4Name refuses a name of one to four labels that are each a decimal, octal or hexadecimal number. A base URL must start with `http://` or `https://` in lower case (GIT_ALLOW_PROTOCOL refuses `HTTPS`, and the worker would not route it through the egress proxy) and hold no space, which curl refuses. The non-ASCII rule now gives the reason that holds everywhere: the registration check cannot look such a name up, and whether git and curl convert it depends on the locale of the server's git. The docs list the rules, say that an empty port is the default, and that a name may have 254 bytes with a final dot. Tests add the boundary cases that four mutants survived. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_ Change-Id: I07e32b3cc42a2039da7d52b8eb3b7948205bc89e Signed-off-by: Thomas Kosiewski --- docs/reference/http-api.md | 18 +++-- internal/api/README.md | 2 +- internal/api/handlers_sync.go | 88 ++++++++++++++++++------ internal/api/upstream_host_shape_test.go | 26 ++++++- 4 files changed, 104 insertions(+), 30 deletions(-) diff --git a/docs/reference/http-api.md b/docs/reference/http-api.md index f37fdc22..09b57296 100644 --- a/docs/reference/http-api.md +++ b/docs/reference/http-api.md @@ -405,13 +405,17 @@ the same scopes, query parameters and responses. deprecated `base_repo` sync form with `auth.token`. - `host`: a bare `hostname[:port]`, or (open.storage extension) an `http(s)://` base URL like `base_repo.upstream_host`. It defaults to the provider's public host. Both - host fields take only what a sync run can dial as given: an IP address without a - zone, or a DNS name of at most 253 bytes whose labels hold 1 to 63 letters, digits, - `_` and `-` and do not start or end with `-`, and that is not only digits and dots - (`2130706433` → 400: curl would dial it as `127.0.0.1`); a name with other letters - goes in its ASCII form (`xn--bcher-kva.example`, not `bücher.example`); a port from 1 - to 65535; and a base URL with no `?` or `#`, even an empty one - (`https://forge.example?` → 400). Any other host → 400 `is not a valid host`. + host fields take only what a sync run can use as given; any other host → 400 `is not + a valid host`: + - an IP address without a zone, or a DNS name: at most 253 bytes (254 with a final + dot), labels of 1 to 63 letters, digits, `_` and `-` that do not start or end with + `-`, and no number form that curl reads as an IPv4 address (`2130706433`, `1.2.3` + and `0x7f.1` → 400: curl would dial `127.0.0.1`, `1.2.0.3` and `127.0.0.1`); + - a name with other letters in its ASCII form (`xn--bcher-kva.example`, not + `bücher.example`); + - a port from 1 to 65535, or an empty one, which is the default; + - in a base URL, `http://` or `https://` in lower case, and no `?`, `#` or space, even + an empty query (`https://forge.example?` → 400). - No credential is stored at create. For a private non-GitHub upstream, add one with `POST /repos/git-credentials`, then call `pull-upstream`. - `upstream` has no `forward_pushes`; use the deprecated `base_repo` sync form to opt in. diff --git a/internal/api/README.md b/internal/api/README.md index aaa14c29..b5f1375f 100644 --- a/internal/api/README.md +++ b/internal/api/README.md @@ -33,7 +33,7 @@ The REST API (`/api/v1/...`) and its `/api/repos/{repo_name}` alias layer. `New` - Merges need git >= 2.38 and refuse unrelated histories unless allowed; a stale target SHA is 409 [handlers_write_merge.go:wmCheckGitVersion] [handlers_write_merge.go:handleMerge] - Fork and copy check the source token for `git:read` and the pack size against quota before creating any row [handlers_fork.go:handleForkRepo] - `publishPack` denies over-quota packs before upload and fails closed on a second stale usage floor [publish.go:publishPack] -- `validUpstreamHost` rejects userinfo, query, fragment, and non-http(s) schemes [handlers_sync.go:validUpstreamHost] +- `validUpstreamHost` rejects userinfo, query, fragment (even an empty one), a space, a scheme other than lower-case `http`/`https`, a port outside 1-65535, and a hostname that is neither an IP address without a zone nor a name that Go's resolver asks DNS for and that curl does not read as IPv4 [handlers_sync.go:validUpstreamHost] [handlers_sync.go:dialableHostname] [handlers_sync.go:curlIPv4Name] - Text the request asks to store answers 400 on every backend when it holds a NUL byte (a JSON body decodes invalid UTF-8 to U+FFFD, so only a NUL reaches the check): a webhook `secret`, a credential `username` and `password`, the `owner`, `name` and `auth.token` of a sync link, and a `pull-upstream` `ref`. A webhook or credential ID with a NUL byte or invalid UTF-8 answers the 404 of an unknown ID [errors.go:invalidTextFields] [handlers_webhooks.go:handleCreate] [handlers_credentials.go:handleCreateCredential] [handlers_sync.go:validateSyncBaseRepo] [handlers_sync.go:parseUpstreamConfig] [handlers_sync.go:handlePullUpstream] - A request value that git takes as one argument or one environment entry answers 400 before git starts when it does not fit `gitlimit.MaxArgBytes` with what the server puts around it: a read `path` or grep `paths` entry (`maxGitPathBytes`), a blame `range` and a grep `query.pattern`, and the `name` and `email` of an author, a committer or a note author (`maxGitIdentBytes`). A commit message goes to `commit-tree` on stdin. A list of such values (the grep `paths`, the diff `path` params, the blame `range` params) also answers 400 when its entries do not fit `gitlimit.MaxArgListBytes` together [handlers_read_query.go:listTooLong] [handlers_read_core.go:readPathOK] [handlers_read_query.go:cleanPathParams] [handlers_read_query.go:handleBlame] [handlers_read_query.go:handleGrep] [handlers_read_query.go:grepPathProblems] [handlers_write_commit.go:wcAuthorProblems] [handlers_write_refs.go:wrefHandleNote] [handlers_write_commit.go:wcScratch.writeCommit] - A sync link or credential that the sync worker could not hand to git answers 400 when it is stored: an upstream URL (`upsync.Upstream.CloneURL`) over `upsync.MaxUpstreamURLBytes`, naming the owner, the name and the host field the body sent, and a `base_repo.auth.token`, credential `username` or `password` over `upsync.MaxCredentialBytes`. The worker checks the same limits again for values stored before [handlers_sync.go:upstreamURLProblem] [handlers_sync.go:validateSyncBaseRepo] [handlers_credentials.go:gcredValidate] diff --git a/internal/api/handlers_sync.go b/internal/api/handlers_sync.go index 2a5b5997..591d12b8 100644 --- a/internal/api/handlers_sync.go +++ b/internal/api/handlers_sync.go @@ -365,12 +365,14 @@ func (cfg upstreamConfig) validate(errs *bodyErrors) (host string) { // query/fragment noise must be rejected here, where the attacker-controlled // value enters (the worker additionally pins GIT_ALLOW_PROTOCOL). // -// It also refuses what no sync run can use, so the create answers 400 -// instead of storing a link whose every run fails: a hostname that is -// neither an IP address nor a name the run's resolver looks up -// (dialableHostname), a port outside 1-65535, and a base URL with a query -// or a fragment, even an empty one (`https://h?`), which would end the -// path of every fetch URL. +// It also refuses hosts that a sync run cannot use as given, so the create +// answers 400 instead of storing a link that the registration check could +// not vet: a hostname that is neither an IP address nor a name that the +// run's resolver asks DNS for (dialableHostname), a port outside 1-65535, +// and a base URL with a query or a fragment, even an empty one +// (`https://h?`), which would end the path of every fetch URL, with a +// space, which curl refuses, or with a scheme that is not lower case +// (`HTTPS://`), which GIT_ALLOW_PROTOCOL refuses. func validUpstreamHost(host string) bool { assertf(host != "", "validUpstreamHost: empty host") if !strings.Contains(host, "://") { @@ -382,19 +384,23 @@ func validUpstreamHost(host string) bool { return err == nil && u.Host == host && u.User == nil && u.Path == "" && u.RawQuery == "" && u.Fragment == "" && dialableAuthority(u) } + if !strings.HasPrefix(host, "http://") && !strings.HasPrefix(host, "https://") { + return false + } u, err := neturl.Parse(host) - if err != nil || (u.Scheme != "http" && u.Scheme != "https") { + if err != nil { return false } // A path is allowed (sub-path-hosted forges); credentials belong in // the credential store, never in the URL. url.Parse drops an empty - // query or fragment, so the bytes are checked. - return u.User == nil && !strings.ContainsAny(host, "?#") && dialableAuthority(u) + // query or fragment and keeps a space in a path, so the bytes are + // checked. + return u.User == nil && !strings.ContainsAny(host, "?# ") && dialableAuthority(u) } // dialableAuthority reports whether the host and port of u name something // that a sync run can dial: a dialableHostname and, when u has one, a port -// from 1 to 65535. +// from 1 to 65535. An empty port (`forge.example:`) is the default one. func dialableAuthority(u *neturl.URL) bool { if port := u.Port(); port != "" { if n, err := strconv.Atoi(port); err != nil || n < 1 || n > 65535 { @@ -405,21 +411,33 @@ func dialableAuthority(u *neturl.URL) bool { } // dialableHostname reports whether name is an IP address without a zone, -// or a name that the resolver of a sync run looks up. A run dials through -// the egress proxy (upsync.startEgressProxy), whose Go resolver refuses any -// other name before it asks DNS (net.isDomainName, after RFC 1035 and RFC -// 3696): at most 253 bytes, or 254 with a final dot; labels of 1 to 63 -// letters, digits, '_' and '-' that do not start or end with '-'; and not -// only digits and dots, which curl reads as an IPv4 address (2130706433 is -// 127.0.0.1) that the registration check never saw. A name with other -// letters goes in its ASCII form (xn--bcher-kva.example): curl refuses -// bücher.example as a bad URL. A zone-scoped address (fe80::1%eth0) is -// refused: the egress guard refuses it under every policy, and the egress -// answer would repeat its zone, which only the upstream URL limit bounds. +// or a name that the resolver of a sync run asks DNS for and that curl +// does not read as an IPv4 address (curlIPv4Name). A zone-scoped address +// (fe80::1%eth0) is refused: the egress guard refuses it under every +// policy, and the egress answer would repeat its zone, which only the +// upstream URL limit bounds. func dialableHostname(name string) bool { if ip, err := netip.ParseAddr(name); err == nil { return ip.Zone() == "" } + return resolverName(name) && !curlIPv4Name(name) +} + +// resolverName reports whether the Go resolver of a sync run asks DNS for +// name. A run dials through the egress proxy (upsync.startEgressProxy), +// whose resolver refuses any other name (net.isDomainName, after RFC 1035 +// and RFC 3696): at most 253 bytes, or 254 with a final dot; labels of 1 to +// 63 letters, digits, '_' and '-' that do not start or end with '-'; and +// not only digits and dots, which curl reads as an IPv4 address +// (2130706433 is 127.0.0.1) that the registration check never saw. The +// resolver reads /etc/hosts before it applies the rule, but a name that +// only /etc/hosts holds is no upstream host. +// +// A name with other letters goes in its ASCII form +// (xn--bcher-kva.example): the registration check cannot look bücher.example +// up, and whether git and curl convert it depends on the locale that the +// server's git runs in. +func resolverName(name string) bool { if name == "" || len(name) > 254 || len(name) == 254 && name[253] != '.' { return false } @@ -453,6 +471,34 @@ func dialableHostname(name string) bool { return prev != '-' && label <= 63 && letters } +// curlIPv4Name reports whether curl reads name as an IPv4 address: one to +// four labels (a final dot aside), each a decimal, octal or hexadecimal +// (0x) number, such as 0x7f000001, 0x7f.1 or 1.2.3.0x4. curl dials such a +// name as the address (127.0.0.1, 1.2.3.4), which the registration check, +// which reads it as a name, never saw. +func curlIPv4Name(name string) bool { + labels := strings.Split(strings.TrimSuffix(name, "."), ".") + if len(labels) > 4 { + return false + } + for _, label := range labels { + digits, hex := label, false + if len(label) >= 2 && label[0] == '0' && (label[1] == 'x' || label[1] == 'X') { + digits, hex = label[2:], true + } + if digits == "" && !hex { + return false + } + for i := 0; i < len(digits); i++ { + c := digits[i] + if !('0' <= c && c <= '9' || hex && ('a' <= c && c <= 'f' || 'A' <= c && c <= 'F')) { + return false + } + } + } + return true +} + // upstreamHostname extracts the hostname the sync fetch will dial from a // validUpstreamHost-validated value (bare host[:port] or http(s):// base // URL) for the registration-time egress courtesy check (issue #139). diff --git a/internal/api/upstream_host_shape_test.go b/internal/api/upstream_host_shape_test.go index 87209c36..0803d366 100644 --- a/internal/api/upstream_host_shape_test.go +++ b/internal/api/upstream_host_shape_test.go @@ -25,6 +25,13 @@ func TestValidUpstreamHost(t *testing.T) { "localhost", "1forge.example", label63 + ".example", + "forge." + label63, + "1-1", + "1_1", + "cafe", + "0xg.example", + // Five labels are no IPv4 address for curl: a name. + "0x1.0x2.0x3.0x4.0x5", name253, name253 + ".", "10.0.0.1", @@ -36,6 +43,8 @@ func TestValidUpstreamHost(t *testing.T) { "http://127.0.0.1:3000", "https://[2001:db8::1]:443/git", "https://forge.example/a%3Fb", + "forge.example:", + "https://forge.example:/git", } { if !validUpstreamHost(host) { t.Errorf("validUpstreamHost(%q) = false, want true", host) @@ -54,6 +63,7 @@ func TestValidUpstreamHost(t *testing.T) { "forge.-example", "forge.example-", label63 + "a.example", + "forge." + label63 + "a", name253 + "a", name253 + "a.", ".", @@ -63,6 +73,15 @@ func TestValidUpstreamHost(t *testing.T) { "1.2.3", "https://1.2.3", "01.2.3.4", + "1.2.3.4.5", + // Hexadecimal forms that curl reads as IPv4 too. + "0x7f000001", + "0x7f.1", + "0X7F.0.0.1", + "1.2.3.0x4", + "0x7f.1.", + "0xa9fea9fe", + "http://0x7f000001:3000/git", // A zone. "https://1.2.3.4%25eth0", "https://[fe80::1%25eth0]", @@ -77,6 +96,11 @@ func TestValidUpstreamHost(t *testing.T) { "https://forge.example/git?", "https://forge.example/git?a=b", "https://forge.example/git#x", + // A space, which curl refuses, and a scheme that is not lower + // case, which GIT_ALLOW_PROTOCOL refuses. + "https://forge.example/a b", + "HTTPS://forge.example", + "Http://forge.example", // Unchanged refusals. ":80", "https://:80", @@ -96,7 +120,7 @@ func TestValidUpstreamHost(t *testing.T) { func TestSyncCreateRefusesUndialableHosts(t *testing.T) { runBackends(t, func(t *testing.T, e *testEnv) { org := e.newOrg(t) - for _, host := range []string{"<<<.com", "https://1.2.3.4%25eth0", "https://forge.example?", "2130706433", "forge.example:65536"} { + for _, host := range []string{"<<<.com", "https://1.2.3.4%25eth0", "https://forge.example?", "2130706433", "0x7f000001", "forge.example:65536", "HTTPS://forge.example"} { for _, field := range []struct{ name, body, msg string }{ {"upstream.host", `{"upstream":{"provider":"gitea","owner":"o","name":"n","host":%s}}`, "invalid upstream host "}, {"base_repo.upstream_host", `{"base_repo":{"provider":"gitea","owner":"o","name":"n","upstream_host":%s}}`, "invalid base_repo upstream_host "}, From aeba00c73635eca0ff27ba5da43a2c6dfa4cfa95 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Mon, 16 Nov 2026 22:51:02 +0000 Subject: [PATCH 5/7] chore: re-record the lane-schedule fingerprints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit handlers_sync.go is covered code: validUpstreamHost, dialableHostname, and the new resolverName and curlIPv4Name. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_ Change-Id: If37f3da4f5d67fdab58a35b91559b468a662832d Signed-off-by: Thomas Kosiewski --- .agents/skills/verify-lane-schedule/SKILL.md | 2 +- .agents/skills/verify-lane-schedule/model/fingerprints.txt | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.agents/skills/verify-lane-schedule/SKILL.md b/.agents/skills/verify-lane-schedule/SKILL.md index 111f01cf..08fc961e 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: `3ba49a58917aa8d79c8a6307bd577c4ea8e6945d` (the last commit at which someone confirmed that the model describes this code; only `check.sh --record` moves it). +Sync commit: `bfffd0944feb75e5518bfca05d2349911f44a192` (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 ffb97e6f..36b7ce4f 100644 --- a/.agents/skills/verify-lane-schedule/model/fingerprints.txt +++ b/.agents/skills/verify-lane-schedule/model/fingerprints.txt @@ -69,9 +69,10 @@ internal/api/handlers_sync.go:const_maxQuotedValueBytes 3535e2652322f905ebf42eed internal/api/handlers_sync.go:const_pullUpstreamAcceptedMsg 76a52910111a2580c149b7ea535374dd1196bde9753bf900ed6667fc5763bdb4 internal/api/handlers_sync.go:const_pushUpstreamAcceptedMsg a2ae388107c13efba0294df359ec78e2d5b92bbb2774f068e5507891b5fea698 internal/api/handlers_sync.go:const_upstreamAppAccessMsg e754e2f035f781ed53cc2ee4cf96a4ee8988a87fa93954aca9989c2040b75599 +internal/api/handlers_sync.go:curlIPv4Name 9499bc7d505e0d2fa9005d13b06c68efb0b059412c9a228f6d375ae79c440434 internal/api/handlers_sync.go:deprecated 3227984a4c52242a8804346ff26305a40483c81f04ead54d0ab913daa01daa24 internal/api/handlers_sync.go:dialableAuthority 272fc206a7652abebab23cc8b90a106a7a2f4571277f9c52ae0ef0b63f3397bc -internal/api/handlers_sync.go:dialableHostname d357f523b66b4a6897e68bfcff6006eae5026600ad1da59c0e488f8b9292af5e +internal/api/handlers_sync.go:dialableHostname 4aae5d4917b5a62b0b9483a694a95d585a56913a1756a60835291e61d5eb5880 internal/api/handlers_sync.go:import_"bytes" 151fc787b0679fc8767e367d1971b9f907660a3d72d8fa3888877ef9f8ebd9c3 internal/api/handlers_sync.go:import_"cmp" 6ee637994d3b529ead32b904453999f4347fa28f1bba3d141f490cbf02e1f7cc internal/api/handlers_sync.go:import_"context" 35d620b75b6b66f8c228f26b970a741d77137e4e691aa896119dd9d000eaadd2 @@ -95,6 +96,7 @@ internal/api/handlers_sync.go:parseUpstreamConfig dd27982847b44628b2a14a4364e4a2 internal/api/handlers_sync.go:policyDeniesPullUpstream 098960c7bef537c91ca905ce894432882eef7ef465a3ddb0b0f9e7224be746e7 internal/api/handlers_sync.go:quoteValue 65ba4a04ae8697e574a042770e053ec58c5e667a3a12ab1ee3f171afac190ff4 internal/api/handlers_sync.go:registerSyncRoutes 30a124203d6812c4b8fa939a4866caae6a74ac2b0b71e36a7de2fed3e0c25134 +internal/api/handlers_sync.go:resolverName 3e71c7fdad4e07921f939372c51f47fe4662e0140f0f73ee453bb27eee32f5b3 internal/api/handlers_sync.go:sentHost 06d61ad20c0eda8ee6d85423eba7a886af4d12740a62517242e024cb01e1381d internal/api/handlers_sync.go:syncServer.answerTakenSyncName 22cf55fac3487ceec250be953518f3cd9b54265fa9061a6f94c4dd2d8567b0e5 internal/api/handlers_sync.go:syncServer.completeOwnSyncCreate a301e0bad45ed03f793aa89eca3036f4e652051a33060812075c97ccf1076b16 @@ -119,7 +121,7 @@ internal/api/handlers_sync.go:type_usyncPushUpstreamRequest 3ad57ba2d21ad394741c internal/api/handlers_sync.go:upstreamConfig.validate 5d6cda757706a13060fb8b917b6931dd5927bf427d038cd707471b23ae4b555f internal/api/handlers_sync.go:upstreamHostname f65b41a625e2606e71c567cbc6d99d991e59b6ef4da9e976294b9ff3895aac34 internal/api/handlers_sync.go:upstreamURLProblem e66d2c29ef48b6891a62cca5ace9afbd52d579f5f4ae11aeba3cc61b3f3c488d -internal/api/handlers_sync.go:validUpstreamHost b3cbac2d7cead6e97c32967d63ff104c3542e40b3b149398f0a215b4fccde75b +internal/api/handlers_sync.go:validUpstreamHost 2aa28ab36ae31c94b9311a490f3bfb3707653ce95f7995727c31a37f58cf3c30 internal/api/handlers_sync.go:validateSyncBaseRepo 0d0acd7ad181d241c2da2a6e48dfaa23aed47c8847cfb8a4992e3693056c2ed1 internal/api/handlers_sync.go:withStrictPullBody 449923a2f639f42183416d391cac81b304bcf8b6cda9d207474e66e16178766f internal/api/handlers_sync.go:withUpstreamDetach b16659bb293b5f9eb05b5ade652dfe4fb224e8a7b6c475829007ee1933a164ec From 78f3a1a655d0bd332a2fc0a6f525e9ce2ac27b2d Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Mon, 16 Nov 2026 23:13:15 +0000 Subject: [PATCH 6/7] fix(api): refuse only the names that curl reads as IPv4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit curlIPv4Name refused any one to four labels made of digits or 0x hex, so names that only look numeric (0x100.1, 0x100000000) answered 400 although curl keeps them names. It now parses each label as curl's URL parser does: decimal, octal (leading 0) or hexadecimal (0x, 0X), at most 32 bits, all but the last at most 255 and the last within the bits the others leave. Against curl 8.22 it agrees on 33 forms, from 0x7f.1. and 0377.0377.0377.0377 to 0400.1.1.1 and 4294967296. Tests add upper-case hex digits, the range boundaries, names that only look numeric, and 64-byte labels of digits and of dashes; the docs say which number forms are refused. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_ Change-Id: Idf4ed0893728a8e3c43baba6eda5a5647f7eecad Signed-off-by: Thomas Kosiewski --- docs/reference/http-api.md | 6 ++- internal/api/README.md | 2 +- internal/api/handlers_sync.go | 47 +++++++++++++++--------- internal/api/upstream_host_shape_test.go | 25 ++++++++++++- 4 files changed, 59 insertions(+), 21 deletions(-) diff --git a/docs/reference/http-api.md b/docs/reference/http-api.md index 09b57296..f472ff9b 100644 --- a/docs/reference/http-api.md +++ b/docs/reference/http-api.md @@ -409,8 +409,10 @@ the same scopes, query parameters and responses. a valid host`: - an IP address without a zone, or a DNS name: at most 253 bytes (254 with a final dot), labels of 1 to 63 letters, digits, `_` and `-` that do not start or end with - `-`, and no number form that curl reads as an IPv4 address (`2130706433`, `1.2.3` - and `0x7f.1` → 400: curl would dial `127.0.0.1`, `1.2.0.3` and `127.0.0.1`); + `-`, not only digits and dots, and not a numerical IPv4 address in curl's forms: + one to four decimal, octal or `0x` hexadecimal numbers within IPv4's range + (`2130706433`, `1.2.3` and `0x7f.1` → 400: curl would dial `127.0.0.1`, `1.2.0.3` + and `127.0.0.1`; `0x100.1` is out of range, so it stays a name); - a name with other letters in its ASCII form (`xn--bcher-kva.example`, not `bücher.example`); - a port from 1 to 65535, or an empty one, which is the default; diff --git a/internal/api/README.md b/internal/api/README.md index b5f1375f..5590074b 100644 --- a/internal/api/README.md +++ b/internal/api/README.md @@ -33,7 +33,7 @@ The REST API (`/api/v1/...`) and its `/api/repos/{repo_name}` alias layer. `New` - Merges need git >= 2.38 and refuse unrelated histories unless allowed; a stale target SHA is 409 [handlers_write_merge.go:wmCheckGitVersion] [handlers_write_merge.go:handleMerge] - Fork and copy check the source token for `git:read` and the pack size against quota before creating any row [handlers_fork.go:handleForkRepo] - `publishPack` denies over-quota packs before upload and fails closed on a second stale usage floor [publish.go:publishPack] -- `validUpstreamHost` rejects userinfo, query, fragment (even an empty one), a space, a scheme other than lower-case `http`/`https`, a port outside 1-65535, and a hostname that is neither an IP address without a zone nor a name that Go's resolver asks DNS for and that curl does not read as IPv4 [handlers_sync.go:validUpstreamHost] [handlers_sync.go:dialableHostname] [handlers_sync.go:curlIPv4Name] +- `validUpstreamHost` rejects userinfo, query, fragment (even an empty one), a space, a scheme other than lower-case `http`/`https`, a port outside 1-65535, and a hostname that is neither an IP address without a zone nor a name that Go's resolver asks DNS for and that curl does not read as a numerical IPv4 address (one to four decimal, octal or hex numbers within IPv4's range) [handlers_sync.go:validUpstreamHost] [handlers_sync.go:dialableHostname] [handlers_sync.go:curlIPv4Name] - Text the request asks to store answers 400 on every backend when it holds a NUL byte (a JSON body decodes invalid UTF-8 to U+FFFD, so only a NUL reaches the check): a webhook `secret`, a credential `username` and `password`, the `owner`, `name` and `auth.token` of a sync link, and a `pull-upstream` `ref`. A webhook or credential ID with a NUL byte or invalid UTF-8 answers the 404 of an unknown ID [errors.go:invalidTextFields] [handlers_webhooks.go:handleCreate] [handlers_credentials.go:handleCreateCredential] [handlers_sync.go:validateSyncBaseRepo] [handlers_sync.go:parseUpstreamConfig] [handlers_sync.go:handlePullUpstream] - A request value that git takes as one argument or one environment entry answers 400 before git starts when it does not fit `gitlimit.MaxArgBytes` with what the server puts around it: a read `path` or grep `paths` entry (`maxGitPathBytes`), a blame `range` and a grep `query.pattern`, and the `name` and `email` of an author, a committer or a note author (`maxGitIdentBytes`). A commit message goes to `commit-tree` on stdin. A list of such values (the grep `paths`, the diff `path` params, the blame `range` params) also answers 400 when its entries do not fit `gitlimit.MaxArgListBytes` together [handlers_read_query.go:listTooLong] [handlers_read_core.go:readPathOK] [handlers_read_query.go:cleanPathParams] [handlers_read_query.go:handleBlame] [handlers_read_query.go:handleGrep] [handlers_read_query.go:grepPathProblems] [handlers_write_commit.go:wcAuthorProblems] [handlers_write_refs.go:wrefHandleNote] [handlers_write_commit.go:wcScratch.writeCommit] - A sync link or credential that the sync worker could not hand to git answers 400 when it is stored: an upstream URL (`upsync.Upstream.CloneURL`) over `upsync.MaxUpstreamURLBytes`, naming the owner, the name and the host field the body sent, and a `base_repo.auth.token`, credential `username` or `password` over `upsync.MaxCredentialBytes`. The worker checks the same limits again for values stored before [handlers_sync.go:upstreamURLProblem] [handlers_sync.go:validateSyncBaseRepo] [handlers_credentials.go:gcredValidate] diff --git a/internal/api/handlers_sync.go b/internal/api/handlers_sync.go index 591d12b8..ac41c2fe 100644 --- a/internal/api/handlers_sync.go +++ b/internal/api/handlers_sync.go @@ -471,34 +471,47 @@ func resolverName(name string) bool { return prev != '-' && label <= 63 && letters } -// curlIPv4Name reports whether curl reads name as an IPv4 address: one to -// four labels (a final dot aside), each a decimal, octal or hexadecimal -// (0x) number, such as 0x7f000001, 0x7f.1 or 1.2.3.0x4. curl dials such a -// name as the address (127.0.0.1, 1.2.3.4), which the registration check, -// which reads it as a name, never saw. +// curlIPv4Name reports whether curl reads name as an IPv4 address, as its +// URL parser does (ipv4_normalize): one to four labels, a final dot aside, +// each a decimal, octal (leading 0) or hexadecimal (0x) number of at most +// 32 bits, all but the last at most 255, and the last within the bits the +// others leave, such as 2130706433, 0x7f000001, 0x7f.1 or 1.2.3.0x4. curl +// dials such a name as the address (127.0.0.1, 1.2.3.4), which the +// registration check, which reads it as a name, never saw. A name that only +// looks numeric, such as 0x100.1 or 0x100000000, stays a name for curl. func curlIPv4Name(name string) bool { labels := strings.Split(strings.TrimSuffix(name, "."), ".") if len(labels) > 4 { return false } - for _, label := range labels { - digits, hex := label, false - if len(label) >= 2 && label[0] == '0' && (label[1] == 'x' || label[1] == 'X') { - digits, hex = label[2:], true - } - if digits == "" && !hex { + last := len(labels) - 1 + for i, label := range labels { + v, ok := curlIPv4Part(label) + if !ok || i < last && v > 0xff || i == last && v > 0xffffffff>>(8*last) { return false } - for i := 0; i < len(digits); i++ { - c := digits[i] - if !('0' <= c && c <= '9' || hex && ('a' <= c && c <= 'f' || 'A' <= c && c <= 'F')) { - return false - } - } } return true } +// curlIPv4Part parses one label of a numerical IPv4 address as curl does: +// 0x or 0X and hexadecimal digits, 0 and octal digits, or decimal digits, +// at most 32 bits. +func curlIPv4Part(label string) (uint64, bool) { + base, digits := 10, label + switch { + case len(label) >= 2 && label[0] == '0' && (label[1] == 'x' || label[1] == 'X'): + base, digits = 16, label[2:] + case len(label) >= 1 && label[0] == '0': + base = 8 + } + if digits == "" { + return 0, false + } + v, err := strconv.ParseUint(digits, base, 32) + return v, err == nil +} + // upstreamHostname extracts the hostname the sync fetch will dial from a // validUpstreamHost-validated value (bare host[:port] or http(s):// base // URL) for the registration-time egress courtesy check (issue #139). diff --git a/internal/api/upstream_host_shape_test.go b/internal/api/upstream_host_shape_test.go index 0803d366..58e5f00b 100644 --- a/internal/api/upstream_host_shape_test.go +++ b/internal/api/upstream_host_shape_test.go @@ -30,8 +30,23 @@ func TestValidUpstreamHost(t *testing.T) { "1_1", "cafe", "0xg.example", - // Five labels are no IPv4 address for curl: a name. + // Names that only look numeric stay names for curl: five labels, + // a part out of IPv4's range, an empty or a bad number. "0x1.0x2.0x3.0x4.0x5", + "0x0.0x0.0x0.0x0.0x0", + "0x100.1", + "0x100000000", + "0xff.0x1000000", + "0xff.0xff.0x10000", + "0x", + "0x.1", + "1.0x", + "09.0x1", + "0xg", + "axe", + "6x6", + // A 63-byte label of letters, digits and dashes. + "a" + strings.Repeat("1", 30) + strings.Repeat("-", 30) + "bc", name253, name253 + ".", "10.0.0.1", @@ -63,6 +78,8 @@ func TestValidUpstreamHost(t *testing.T) { "forge.-example", "forge.example-", label63 + "a.example", + "a" + strings.Repeat("1", 63) + ".example", + "a" + strings.Repeat("-", 62) + "a.example", "forge." + label63 + "a", name253 + "a", name253 + "a.", @@ -81,6 +98,12 @@ func TestValidUpstreamHost(t *testing.T) { "1.2.3.0x4", "0x7f.1.", "0xa9fea9fe", + "0xA9FEA9FE", + "0xA.0xA.0xA.0xA", + "0xffffffff", + "0xff.0xffffff", + "0xff.0xff.0xffff", + "0377.0377.0377.0377", "http://0x7f000001:3000/git", // A zone. "https://1.2.3.4%25eth0", From b8dfa9daff2ae9190f272e7197f9a92d18412d4c Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Mon, 16 Nov 2026 23:58:41 +0000 Subject: [PATCH 7/7] chore: re-record the lane-schedule fingerprints after the merge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_ Change-Id: Ib69e3836b0cd3da64045e0fdff26182c2c9bec88 Signed-off-by: Thomas Kosiewski --- .agents/skills/verify-lane-schedule/SKILL.md | 2 +- .../model/fingerprints.txt | 22 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.agents/skills/verify-lane-schedule/SKILL.md b/.agents/skills/verify-lane-schedule/SKILL.md index 08fc961e..ae63fe6d 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: `bfffd0944feb75e5518bfca05d2349911f44a192` (the last commit at which someone confirmed that the model describes this code; only `check.sh --record` moves it). +Sync commit: `2e98dad6dd886941543d266b99fed69d8b34b17d` (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 36b7ce4f..d11ce3d7 100644 --- a/.agents/skills/verify-lane-schedule/model/fingerprints.txt +++ b/.agents/skills/verify-lane-schedule/model/fingerprints.txt @@ -65,11 +65,11 @@ cmd/openstorage/wire_eventing_local.go:import_"time" 9dae0539db6e1e0ec43a0c7ef22 cmd/openstorage/wire_eventing_local.go:restIntentBeforeCAS 304db8998e396d39da976d3d2218d2972dbc2ddadc6b51b576bb053d4575c747 internal/api/handlers_sync.go:addFields eb7bbf22ad89084587f511413a6d677d529a41ac089b5b08b3d9729d491eb66a internal/api/handlers_sync.go:const_deprecationHeader 188405d30be79bf4a07cacfd258badc10e47e41baa71a10f0ea6ca320d0669df -internal/api/handlers_sync.go:const_maxQuotedValueBytes 3535e2652322f905ebf42eedd9adf5ac981ab62d766c317af592007564638cac internal/api/handlers_sync.go:const_pullUpstreamAcceptedMsg 76a52910111a2580c149b7ea535374dd1196bde9753bf900ed6667fc5763bdb4 internal/api/handlers_sync.go:const_pushUpstreamAcceptedMsg a2ae388107c13efba0294df359ec78e2d5b92bbb2774f068e5507891b5fea698 internal/api/handlers_sync.go:const_upstreamAppAccessMsg e754e2f035f781ed53cc2ee4cf96a4ee8988a87fa93954aca9989c2040b75599 -internal/api/handlers_sync.go:curlIPv4Name 9499bc7d505e0d2fa9005d13b06c68efb0b059412c9a228f6d375ae79c440434 +internal/api/handlers_sync.go:curlIPv4Name 3a642528f1cbc1e513c3d9280e277ce371ba7208b1f880b54b9b851fb92ae32b +internal/api/handlers_sync.go:curlIPv4Part 0d60932194160d2f0f58fc5f0ae6295b84337e94d3a2552565f4ad398cc7cbb4 internal/api/handlers_sync.go:deprecated 3227984a4c52242a8804346ff26305a40483c81f04ead54d0ab913daa01daa24 internal/api/handlers_sync.go:dialableAuthority 272fc206a7652abebab23cc8b90a106a7a2f4571277f9c52ae0ef0b63f3397bc internal/api/handlers_sync.go:dialableHostname 4aae5d4917b5a62b0b9483a694a95d585a56913a1756a60835291e61d5eb5880 @@ -94,18 +94,18 @@ internal/api/handlers_sync.go:isStrictPullBody ec4bff99487fd47a4c11c3cc2714cee70 internal/api/handlers_sync.go:isUpstreamDetach 25715f9e18d1bf7bc62e630e8164eab041ad70b6a627b2bb52c4ba6f1c177165 internal/api/handlers_sync.go:parseUpstreamConfig dd27982847b44628b2a14a4364e4a23ea414ef90a9e7a05cb5f7edc52e12cc00 internal/api/handlers_sync.go:policyDeniesPullUpstream 098960c7bef537c91ca905ce894432882eef7ef465a3ddb0b0f9e7224be746e7 -internal/api/handlers_sync.go:quoteValue 65ba4a04ae8697e574a042770e053ec58c5e667a3a12ab1ee3f171afac190ff4 +internal/api/handlers_sync.go:refPolicyOpDenies 14c74420941dbb32b29b6bccd73d4c8029dc794fba6a8df30beaf91104b7c0f1 internal/api/handlers_sync.go:registerSyncRoutes 30a124203d6812c4b8fa939a4866caae6a74ac2b0b71e36a7de2fed3e0c25134 internal/api/handlers_sync.go:resolverName 3e71c7fdad4e07921f939372c51f47fe4662e0140f0f73ee453bb27eee32f5b3 internal/api/handlers_sync.go:sentHost 06d61ad20c0eda8ee6d85423eba7a886af4d12740a62517242e024cb01e1381d internal/api/handlers_sync.go:syncServer.answerTakenSyncName 22cf55fac3487ceec250be953518f3cd9b54265fa9061a6f94c4dd2d8567b0e5 internal/api/handlers_sync.go:syncServer.completeOwnSyncCreate a301e0bad45ed03f793aa89eca3036f4e652051a33060812075c97ccf1076b16 internal/api/handlers_sync.go:syncServer.createAbandon 07809dcf477a5a8cec0ff8c63825bddf587cc49377865352ec4ce616d5ac9fda -internal/api/handlers_sync.go:syncServer.finishPendingSync bf0466eb3d30c1df4c6678fb30b4e84026f794f35227ddc79676f911b2a26e79 -internal/api/handlers_sync.go:syncServer.handleCreateRepo 2a16e28b69a5ba40b28a10b26bc4eb76f41e4bfdeea45f2547ef1ade0f085a92 +internal/api/handlers_sync.go:syncServer.finishPendingSync f6c0ab3647777b351f0a1a47390eb5a0f7923abb338ae110c1ab352b9d944dd3 +internal/api/handlers_sync.go:syncServer.handleCreateRepo 89ee49bf35d2743731f3301ddc56e75f8bfe60875c72b8069c1fea080d0eb933 internal/api/handlers_sync.go:syncServer.handleDetachBase a1a966b58e18eee556a253455d87b8f1642cdc009314c592e5e7371e87e7013b -internal/api/handlers_sync.go:syncServer.handlePullUpstream eeacae04d7ad19517907644396e70fb4d3f14f06ead3a0e600c6b493b75dbbaa -internal/api/handlers_sync.go:syncServer.handlePushUpstream 75f5fc0a37eba5b95b2e82b6f049ede62606857395b42ef79fe61a05aa4c71fd +internal/api/handlers_sync.go:syncServer.handlePullUpstream ecec930462dc4e4add2c6ffc630a6550a27f167f55348ebf3612982041b67a12 +internal/api/handlers_sync.go:syncServer.handlePushUpstream 8fca21a57ba65c7a3090d8a71f08e2c44c8bad6b4fa8d32c2130eef484fc8d65 internal/api/handlers_sync.go:syncServer.linked 8459608354ca43e6b1b94a7cd6ecb02d7f1817b80b4b939f6e6653afeab141e3 internal/api/handlers_sync.go:syncServer.syncCompletionOK c365642e8d5279cb9c112afd7f1bec02933dd02b4712137194b8a437507dcf66 internal/api/handlers_sync.go:textField d5b3a42d9e3669c19d63416a4b6c478834b86a73f011a25d7e2d60a8badb65b9 @@ -118,11 +118,11 @@ internal/api/handlers_sync.go:type_usyncBaseRepo fa63c2d8bb62db2a56acff9a8de55e5 internal/api/handlers_sync.go:type_usyncBaseRepoAuth cbce39e3f3df0443cfcb499a9e439e361335ee86e6e97c205c21b18b48141cd6 internal/api/handlers_sync.go:type_usyncPullUpstreamRequest b98132ea1ae7690f3f00aece7dd8fb2a00f69d0e9ea5f1f95c198c983cc18b0b internal/api/handlers_sync.go:type_usyncPushUpstreamRequest 3ad57ba2d21ad394741cb6b3ced05a273c72b38ca84d7a73b34d79b4510f4284 -internal/api/handlers_sync.go:upstreamConfig.validate 5d6cda757706a13060fb8b917b6931dd5927bf427d038cd707471b23ae4b555f +internal/api/handlers_sync.go:upstreamConfig.validate 4c75ed7ea1b26bcef15daa0358e3d79ee704eb27b8d1fbdb9861d7a0d4f2f509 internal/api/handlers_sync.go:upstreamHostname f65b41a625e2606e71c567cbc6d99d991e59b6ef4da9e976294b9ff3895aac34 internal/api/handlers_sync.go:upstreamURLProblem e66d2c29ef48b6891a62cca5ace9afbd52d579f5f4ae11aeba3cc61b3f3c488d internal/api/handlers_sync.go:validUpstreamHost 2aa28ab36ae31c94b9311a490f3bfb3707653ce95f7995727c31a37f58cf3c30 -internal/api/handlers_sync.go:validateSyncBaseRepo 0d0acd7ad181d241c2da2a6e48dfaa23aed47c8847cfb8a4992e3693056c2ed1 +internal/api/handlers_sync.go:validateSyncBaseRepo df7737d1b71ebccd3220b074e9002ee36edc83b549338e321394c012a9a6a807 internal/api/handlers_sync.go:withStrictPullBody 449923a2f639f42183416d391cac81b304bcf8b6cda9d207474e66e16178766f internal/api/handlers_sync.go:withUpstreamDetach b16659bb293b5f9eb05b5ade652dfe4fb224e8a7b6c475829007ee1933a164ec internal/events/refstore.go:BaseRepoID d45f84f8f7f8b9e27d21c7b17553527e76db8c3a5fa34718d2768840b351c8ae @@ -193,6 +193,7 @@ internal/githttp/hook.go:const_reservationDenied f72c8a7d40a9207271da47cf160c52e internal/githttp/hook.go:const_reservationJIT d051ee28340ba848f8282f31689c8bbdde129b4970df2be75292d3b4486c429c internal/githttp/hook.go:const_reservationNeedsVerify b8ec7eeca735e84bb9aa7aa596b7961d17778741956392c03d71116285ff5730 internal/githttp/hook.go:denyAuthorityDFConflict 3ad4a9b7cd317dbae7ebf368256b119a33774f58734c26fef36d47545f50ba5b +internal/githttp/hook.go:denyUnregisteredTargets 30226947720bb73dd56445e7227c26ae7647ccc04f4cfcaa61498129f47accca internal/githttp/hook.go:enforceRefPolicy 2cd2cf6aea243221e8fe27280a6333695d4455a0304e7f536f7e8729dbb17a4d internal/githttp/hook.go:enforceSyncClaimFence efb7b07e54bbb4008ac0cf53778c2ba690ad936051c103421aaf308b52e1cdf9 internal/githttp/hook.go:evalRefPolicy b232fd0a747ced157cec1bc4588e53bc13c54a39ff829f45108ae62c9601b5c8 @@ -231,6 +232,7 @@ internal/githttp/hook.go:isAncestorUncached 328f417bab162596b59fcc2d63c2e58f3ed3 internal/githttp/hook.go:isBranchTip 4b841bc86abf0876e093b19da54ff7e1fda6011f3b3c044f1adabecc759498e7 internal/githttp/hook.go:loadRefPolicies e974fac4024c3534aaa1c55514851744f5b1999bf8a503573a7530130e140c63 internal/githttp/hook.go:looksLikeSSHPublicKey 0dfb41f2c68c29f7bd43dc0630624e292599c1da3b168d3ba9eade2349706e53 +internal/githttp/hook.go:mainStoreKinds a0aec3df17e7b4134882cc8f5dec2922cba82553b6207c804a078b31ed9fc928 internal/githttp/hook.go:mustEnv f003f721f345a1dd8d73bf4b0c6f95e97157cab55714e6b922b10859e4c9c6b8 internal/githttp/hook.go:newGitRefusalProbe 2c8f044c7fdb1d98ae3a941702951fab72596e708fff64397e85fd7a607ef21d internal/githttp/hook.go:newSigVerifier a555514bf11dbd3caaded84b9cca58ef7a8b7a83e39b24bfda507edcbb5a446a @@ -241,7 +243,7 @@ internal/githttp/hook.go:objectKinds 713a3c75bbd6432313852c03e520b97d814f22eca0a internal/githttp/hook.go:parseRefTxCommitted 8471c50ec96eec8e6db39370335fbb30116af5fb3e4e1574e5934ef16254c783 internal/githttp/hook.go:pauseAtUpdateBarrier a57f4482fb6742f6146ca93452fc9e003a70fd9bab1147a87bb4b32b465859c0 internal/githttp/hook.go:postReceiveHook 1f060af8c07a0c11ab59f6a26f444d7648ddfa9fac7bb506346e808a72311261 -internal/githttp/hook.go:preReceive 472bccca1a374479cedb08f228f17893a2f20c1b971761085d5bdf0c60f35ba0 +internal/githttp/hook.go:preReceive 2a7166ab61e7b2cb6c41281f67eb162eefc367e864141a5ec00d884927b2aaad internal/githttp/hook.go:preReceivePolicyGate ca36486a30be47ace72b37aa7c77fec418a88d92a1a36951caf6d2a88a1ec4fd internal/githttp/hook.go:pushCommandUpdatable 7ff2f47180eec838d8c98da58a9836bc69a8b9ee1ac9d0f9270ee816594c04ba internal/githttp/hook.go:pushRefDeletable 33c0ee3ab6b1f4a8886faa66aa3db0a25efcb8407667c33d5c4fa1b3a5de3a94