GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(mcp): forward image tool results on the existing image channel by cairn-intern · Pull Request #1077 · Twigpine/zero

fix(mcp): forward image tool results on the existing image channel #1077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
kevincodex1 merged 2 commits into Twigpine:main from cairn-intern:recreate-1012-feat-823-forward-mcp-images
Oct 12, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

fix(mcp): forward image tool results on the existing image channel #1077

Changes from 1 commit
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
dff1861
fix(mcp): forward image tool results on the existing image channel
cairn-intern Sep 24, 2026
cca5074
test(mcp): pin the pre-decode encoded cap and MIME sniffing guards
cairn-intern Sep 24, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
test(mcp): pin the pre-decode encoded cap and MIME sniffing guards
Adds the two reviewer-requested tests for the untrusted-input boundary:
- TestOverCapEncodedPayloadIsRejectedBeforeDecoding: a payload one byte
  over EncodedLen(MaxImageBytes) is rejected and the decoder is never
  called, so a hostile server cannot force arbitrary decode work.
- TestDeclaredMimeTypeDisagreeingWithSniffedBytesIsDropped: an HTML
  payload declared as image/png is sniffed from its bytes and dropped
  rather than forwarded to the provider as an image.

Both mutations (removing the cap, trusting the declared mimeType) were
verified to turn their test red locally.
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@cairn-intern
cairn-intern committed Sep 24, 2026
commit cca50749a32e22a21f7234b4757c6fbb9f5e27fd

There are no files selected for viewing

62 changes: 62 additions & 0 deletions 62 internal/mcp/non_text_content_test.go
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -668,3 +668,65 @@ func TestMCPResultUninspectedImageLimitingReasonNotes(t *testing.T) {
}
})
}

// The pre-decode encoded-length cap is the decode-DoS guard: it keeps a
// hostile server from making Zero decode a payload of any size (up to the
// inspection cap times per result) before the post-decode backstop drops it.
// Removing the cap changes nothing that is forwarded, so no existing test
// notices; this pins the guard on the decode hook instead. A payload one
// byte over the encoded cap must be rejected without the decoder ever being
// called.
func TestOverCapEncodedPayloadIsRejectedBeforeDecoding(t *testing.T) {
previous := decodeImageBase64
decodes := 0
decodeImageBase64 = func(s string) ([]byte, error) {
decodes++
return previous(s)
}
t.Cleanup(func() { decodeImageBase64 = previous })

// An at-limit PNG would decode to exactly MaxImageBytes and forward; a
// single extra base64 character pushes it one byte over the encoded cap,
// so only the pre-decode guard can be responsible for rejecting it.
payload := paddedPNGBase64(imageinput.MaxImageBytes) + "A"
content := []Content{{Type: "image", MimeType: "image/png", Data: payload}}

if images := ImageBlocks(content); len(images) != 0 {
t.Fatalf("ImageBlocks forwarded %d images from an over-cap payload, want 0", len(images))
}
if decodes != 0 {
t.Fatalf("decoder ran %d times, want 0: the pre-decode cap must reject before any decode work", decodes)
}
if got := DroppedContentSummary(content); got != "1 image/png block" {
t.Fatalf("DroppedContentSummary() = %q, want the over-cap payload named as dropped", got)
}
}

// The media type is sniffed from the decoded bytes, never taken from the
// block's declared mimeType: a hostile server must not be able to relabel
// HTML or a script as image/png and have it forwarded to the provider as an
// image. Every other fixture pairs real PNG bytes with image/png, so
// sniffing and trusting the declared type agree there and no test can tell
// them apart; this fixture makes them disagree.
func TestDeclaredMimeTypeDisagreeingWithSniffedBytesIsDropped(t *testing.T) {
html := []byte("<!doctype html><html><body><script>alert(1)</script></body></html>")
tool := registryTool{
client: &nonTextClient{content: []Content{
{Type: "image", MimeType: "image/png", Data: base64.StdEncoding.EncodeToString(html)},
}},
server: Server{Name: "shots"},
remote: RemoteTool{Name: "screenshot"},
}

result := tool.Run(context.Background(), map[string]any{})

if len(result.Images) != 0 {
t.Fatalf("forwarded %d images from an HTML payload declared as image/png, want 0", len(result.Images))
}
if strings.Contains(result.Output, "[image returned by tool]") {
t.Errorf("a non-image payload declared as image/png is still announced as a returned image:\n%s", result.Output)
}
if !strings.Contains(result.Output, "image/png") {
t.Errorf("the dropped block is not named in the drop summary:\n%s", result.Output)
}
}
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402809 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.