Skip to content

fix(api): cut the webhook URL and the ref policy op that a refusal quotes - #902

Merged
ThomasK33 merged 6 commits into
mainfrom
echo-bounds
Nov 16, 2026
Merged

ThomasK33 merged 6 commits into
mainfrom
echo-bounds

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Three refusals repeated request text whole, cut only at the 16,384-byte bound of every answer. With 100,000 bytes of <, which JSON escapes to six bytes each, each answered about 196 KB. I measured them with requests against the full API server on main (1922669):

Request Answer on main
POST /webhooks with https://[fe80::1%25<100,000 bytes>]/hook (the host's IPv6 zone) 400, 196,306 bytes
POST /webhooks with https://:80/<100,000 bytes> (a URL with no host: the whole URL) 400, 196,296 bytes
A sync create with a token whose ref policy op has 100,000 bytes 403, 196,591 bytes

Now each of these quotes the value with errtext.Quote: a value of more than 256 bytes is cut at a character and followed by its length in bytes, as #882 cuts an unknown member name and #900 a refused sync value:

invalid webhook url: webhook target "fe80::1%<<<…" (100008 bytes) denied: zone-scoped address
ref policy op "<<<…" (100000 bytes) denies sync repository create

Changes

  • errtext.Quote(prefix, v) and errtext.MaxQuotedBytes (256) (internal/errtext): one helper for every answer that quotes one request value. It replaces quoteValue and maxQuotedValueBytes (handlers_sync.go) and the cut of unknownNameText and maxUnknownNameBytes (decode_body.go), which did the same. prefix is text of the server (the dotted path of a known field) and is never cut, so unknown field "author.xx…" (1000000 bytes) stays as it is.
  • Webhooks: TargetGuard.CheckRegistration (internal/events/guard.go) quotes the refused host (a literal, or a name that resolves to a denied address), the URL that has no host, and the URL of a parse error. For a parse error it no longer repeats url.Error's copy of the URL and cuts the error it adds, which can repeat a part of the URL such as an invalid port; POST /webhooks refuses such a URL before it gets there. A short host is now quoted too: webhook target "10.0.0.7" denied: private address.
  • Ref policy 403s: refPolicyOpDenies builds the six messages: a sync create, pull-upstream, push-upstream, completing a pending sync create, PATCH /repo and DELETE /repos/delete. A short op reads as before (ref policy op "no-push" denies pull-upstream). The 403 of a ref write (refs and tags), a commit write and a merge for an op that the server does not know quotes it too: unknown policy op "x" for refs/heads/main (it was unquoted in the commit and merge writes, %q in the ref writes; 196,556 bytes for a tag create with an op of 100,000 <).
  • CheckHost, the sync twin of the webhook check, is unchanged: since fix(api): refuse sync credentials that the run refuses, and cut quoted sync values #900 a sync host is an IP literal without a zone or a name that resolved, so the hostname it repeats is short.
  • Docs: docs/reference/webhooks.md (registration refusals) and docs/reference/http-api.md (ref policy 403s); internal/errtext/README.md.
  • handlers_sync.go is covered by the lane-schedule model, so its fingerprints are re-recorded.

Evidence

  • Tests: TestQuote (internal/errtext): the limit, one byte over, a prefix that is not cut, a cut inside a rune. TestRefusalsQuoteRequestTextBounded (internal/api): the three webhook refusals and the ref policy 403 of a sync create, pull-upstream, push-upstream, PATCH /repo and DELETE /repos/delete, with a long op (the cut answer, at most 8 KiB) and with no-push (unchanged). Completing a pending sync create builds its message with the same helper and has no case of its own (its callers check the same policy first). TestUnknownPolicyOpQuotedBounded calls the three unknown-op checks with a long and a short op. TestCheckRegistrationQuotesURLTextBounded (internal/events) pins a resolved host, a long resolved host and a URL that does not parse.
  • Red on main: with main's guard.go, handlers_sync.go, handlers.go and decode_body.go overlaid, every webhook case and every long-op case fails; the short-op cases pass.
  • Lanes: go test -race -tags=openstorage_viewcheck of ./internal/errtext/... (1 s), ./internal/events/... (26 s) and ./internal/api/... without pg (362 s) pass at 590a0c8. At 78bde2a the api tests of ref policies, ref, commit and merge writes and webhooks (66 s), and ./internal/events/... and ./internal/errtext/... with -race, pass. PostgreSQL and S3-WAL rely on CI.
  • lint, vet (linux and darwin), gofmt, the docs gate and both fingerprint gates pass.

Reviews

  • Round 1 (590a0c8): the Codex review and the Codex security review found nothing. A fresh read-only review found one P2: no test pinned the refusal of a host that resolves to a denied address, whose text this PR changes. Its 21 overlay mutants left 5 alive. 78bde2a adds that test and fixes four P3 points: the unknown-op 403s above, a TestQuote case where only the prefix takes the text past 256 bytes, the cut of the parse error, and the example in webhooks.md now names its 100,000-byte zone. Left open, older than this PR: other request text that an answer repeats is still cut only at 16,384 bytes (a path filter, a range, a glob, archive.prefix, a notes ref, a strategy, the fork point), and the git hook's own unknown policy op refusal goes to git's stderr.

  • Round 2 (78bde2a): the Codex review and the Codex security review found nothing. A fresh read-only review: PASS. It sent the unknown-op requests through the real commit-pack, diff-commit, restore-commit, merge, branch, tag and note routes: each answered a 403 problem body with the exact text, about 3.3 KB for a 100,000-byte op (196,556–196,574 bytes on main). Its 35 overlay mutants left alive only finishPendingSync's 403, which no request reaches, and three equivalent sites. Two P3 points follow up in the desk's docs PR: internal/errtext/README.md does not list the unknown-op callers, and the unit test of wcCheckRefPolicy could read each route's envelope statuses instead of none.

  • Round 3 (9e9bad3): 6aa76aa merges main (fix(githttp): refuse a ref at an object that no registered pack holds #896); the only conflict was the lane-schedule sync commit, which 9e9bad3 re-records. The Codex review and the Codex security review found nothing, and a fresh read-only review passed: the PR's own diff is unchanged apart from that line, and main's rewrite of handlers_write_refs.go refuses an unknown op only through the quoted wrefPolicyCheck.

Found by the reviews of #900 (desk follow-up).


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: xhigh

…otes

Three refusals repeated request text whole, cut only at the 16,384-byte
bound of every answer: a 100,000-byte value of `<` made answers of about
196 KB once JSON escaped each byte to six.

- POST /webhooks quoted the host of a refused URL, and an IPv6 zone can
  be any length (`https://[fe80::1%25…]`), or the whole URL when it has
  no host (`https://:80/…`).
- The 403 of a ref policy (a sync create, pull-upstream, push-upstream,
  completing a pending sync create, PATCH /repo, DELETE /repos/delete)
  quoted the op of the token.

errtext.Quote now quotes one request value for every such answer: a
value of more than errtext.MaxQuotedBytes (256) is cut at a character
and followed by its length, `"xx…" (100000 bytes)`. It replaces the
api helpers quoteValue and the cut of unknownNameText, which did the
same, and refPolicyOpDenies builds the six 403 messages.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_

Change-Id: Id2a60a35c0fb612af14b905771b4bff6c293fb7a
Signed-off-by: Thomas Kosiewski <tk@coder.com>
Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_

Change-Id: Ied4ff4cfc72963a1f44b5a5c7583cea54919e420
Signed-off-by: Thomas Kosiewski <tk@coder.com>
handlers_sync.go is covered code: errtext.Quote replaces quoteValue, and
refPolicyOpDenies builds the ref policy 403s.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_

Change-Id: I5ef519973d97172f301f048a273ec68f276091b7
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T23:14:27.358575Z 9e9bad3 Manual request
🔒 Security Review ✅ Completed 2026-11-16T23:15:18.377115Z 9e9bad3 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 590a0c827b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 590a0c827b

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

A ref write (refs and tags), a commit write and a merge refuse a ref
policy op that they do not know with a 403 that repeated the op whole
(196,556 bytes for an op of 100,000 `<` on a tag create). They now quote
it with errtext.Quote, as the other ref policy 403s do.

CheckRegistration also cuts the url.Parse error that it adds after the
quoted URL, which can repeat part of the URL (an invalid port). Tests
pin the refusal of a host that resolves to a denied address, a long
resolved host, a URL that does not parse, and a prefix that takes the
quote past 256 bytes without cutting it.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_

Change-Id: I2560cee6477552e0975ba0d0f56a38a2ab4be9f4
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 78bde2a11e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 78bde2a11e

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Main gained #896 (githttp). The only conflict is the sync commit of the
lane-schedule model; the next commit re-records it on the merged tree.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_

Change-Id: I366cda54751e41e91f387d4647f02b1a4dd3e3e1
Signed-off-by: Thomas Kosiewski <tk@coder.com>
Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_

Change-Id: I08b980735fd8c3695df98c5e72318a685dbc9ac7
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 9e9bad36a5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 9e9bad36a5

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33
ThomasK33 added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit 04b97f9 Nov 16, 2026
16 checks passed
@ThomasK33
ThomasK33 deleted the echo-bounds branch November 16, 2026 23:51
ThomasK33 added a commit that referenced this pull request Nov 16, 2026
Main gained #896, #901 and #902. #902 dropped the strconv import of
handlers_sync.go with quoteValue; this branch's port and IPv4 checks use
it, so the merge keeps it. The other conflicts are the lane-schedule
fingerprints and sync commit; the next commit re-records them on the
merged tree.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_

Change-Id: Ib2c61d6a44b3a74698bce02f2eef91f7fe0568a3
Signed-off-by: Thomas Kosiewski <tk@coder.com>
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