Skip to content

fix(mcp): reject malformed base64 file writes - #378

Open
Prajwal2246 wants to merge 1 commit into
superserve-ai:mainfrom
Prajwal2246:fix/mcp-base64-validation
Open

Prajwal2246 wants to merge 1 commit into
superserve-ai:mainfrom
Prajwal2246:fix/mcp-base64-validation

Conversation

@Prajwal2246

Copy link
Copy Markdown
Contributor

Related Issues

Fixes #377

Description

Reject malformed base64 in sandbox_files_write before calling the write client. Previously, inputs such as !!! or SGVsbG8=garbage could silently overwrite a file with empty or partial content because Buffer.from accepts invalid input.

Validate the alphabet, length, and padding at the MCP boundary. Keep standard and URL-safe characters, optional padding, ASCII whitespace, intentional empty writes, text writes, and the decoded-size limit supported. Document the accepted variants in the tool's content description.

Additional Context

The SDK receives decoded bytes, so validation belongs in the MCP handler while the original encoded input is still available. No dependencies or SDK interfaces change.

Testing

  • Tested locally
  • Added/updated tests
  • All tests passing

Added 23 tests through the existing in-memory MCP transport and fake sandbox client. All 12 malformed-input cases failed against the unchanged handler and pass with the fix; they assert that the write client is not called and existing contents are preserved. Other cases cover accepted encodings, empty content, and exactly/above the 8 MiB decoded-size limit.

  • Full suite: 2,177 passed, two credential-dependent MCP E2E tests skipped with API credentials removed.
  • bun run lint, bun run format:check, bun run typecheck, bun run build, and bun run docs:check-nav passed.
  • Live sandbox writes were not tested.

Screenshots/Demo

Not applicable; no UI changes.

@vercel

vercel Bot commented Oct 8, 2026

Copy link
Copy Markdown

@Prajwal2246 is attempting to deploy a commit to the superserve Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@onepatch-agent onepatch-agent Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OnePatch is tracking this change: malformed base64 is rejected at the sandbox_files_write boundary instead of being silently decoded into an empty or truncated overwrite.

Watching

  • The hosted MCP server (Production – superserve-mcp) deploys the merge commit, so the validation is actually live — baseline 30 success / 0 failure over 30 days.
  • CI / Lint, typecheck, test, build stays green on main at the merge commit, within its usual ~164s — the 23 new cases are the only thing pinning the accepted alphabet.
  • Production – ui and Production – console ship the same commit, as build witnesses that localise any failure to packages/mcp.

Would fail it

  • The superserve-mcp production deployment goes red, or never reports the merge commit — the #377 overwrite bug stays unfixed in production.
  • CI goes red on main: a failing test means the validator and its documented contract disagree, and the live risk is rejecting a write that used to succeed.
  • A sibling Vercel project ships the commit while superserve-mcp does not.

Note on coverage: the hosted MCP server sends OnePatch no telemetry, so the rejection rate itself cannot be measured — these checks verify that the change reaches production, not how it behaves once there. Installed @superserve/mcp copies keep the old handler until a release is cut.

changes/superserve-ai--superserve--pr-378 · awaiting merge

@Prajwal2246

Copy link
Copy Markdown
Contributor Author

Hi @meAmitPatil 👋 I've rebased this on the latest main and the tests pass. The Vercel checks are failing only because the fork deployment needs a team member to authorize it. It's a small change (one file plus tests) that fixes #377, where malformed base64 silently overwrites sandbox files with empty or truncated content. Could you take a look when you have a moment? Thanks!

@Prajwal2246
Prajwal2246 force-pushed the fix/mcp-base64-validation branch from cc68741 to 63f8833 Compare October 23, 2026 05:29

This branch has not been deployed

No deployments
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.

MCP: reject malformed base64 before writing sandbox files

1 participant