Skip to content

fix(mcp): Fix sandbox read-only mode not being applied to MCP sessions#57306

Open
harsh21234i wants to merge 2 commits intoPostHog:masterfrom
harsh21234i:fix/issue-57268
Open

fix(mcp): Fix sandbox read-only mode not being applied to MCP sessions#57306
harsh21234i wants to merge 2 commits intoPostHog:masterfrom
harsh21234i:fix/issue-57268

Conversation

@harsh21234i
Copy link
Copy Markdown
Contributor

Summary

This fixes a header mismatch between the task sandbox and the MCP service
that was preventing read-only mode from being enforced for sandbox-created
MCP sessions.

The sandbox was sending x-posthog-read-only, while the MCP service was
only looking for x-posthog-readonly. Because of that mismatch, sandbox
sessions could silently miss the read-only restriction even when they were
meant to be locked down.

What changed

  • updated the sandbox MCP config builder to send the canonical x-posthog-
    readonly header
  • updated the existing Python tests to assert the correct header name
  • added a small compatibility fallback on the MCP side so it still accepts
    the old x-posthog-read-only header
  • added MCP-side regression coverage for both header spellings, plus the
    existing query-param fallback

Why

The main fix is making the sender and receiver agree on the same header
name. I also kept the MCP side backward-compatible so older internal
callers or in-flight clients don’t silently lose read-only enforcement
while everything catches up.

Validation

I verified the touched Python files compile cleanly locally. I didn’t run
the MCP vitest suite from this machine, so CI will be the final check.

Fixes #57268

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 1, 2026

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
services/mcp/tests/unit/readonly-header.test.ts:5-27
**Prefer parameterised tests**

All three cases test the same function with different inputs and the same expected output — this is exactly the pattern `it.each` is designed for. The Python side of this very PR uses `@parameterized.expand` correctly; the TypeScript side should follow the same convention.

```suggestion
    it.each([
        ['canonical x-posthog-readonly header', { 'x-posthog-readonly': 'true' }, ''],
        ['legacy x-posthog-read-only header', { 'x-posthog-read-only': '1' }, ''],
        ['readonly query parameter', {}, '?readonly=true'],
    ])('reads read-only from %s', (_, headers, qs) => {
        const request = new Request(`https://mcp.posthog.com/mcp${qs}`, { headers })
        expect(getReadOnlyFromRequest(request, new URL(request.url))).toBe(true)
    })
```

Reviews (1): Last reviewed commit: "fix(mcp): align sandbox readonly header" | Re-trigger Greptile

Comment thread services/mcp/tests/unit/readonly-header.test.ts
@harsh21234i
Copy link
Copy Markdown
Contributor Author

harsh21234i commented May 4, 2026

hey @haacked have you checked this?

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.

bug(mcp): sandbox read-only header name mismatch — x-posthog-read-only vs x-posthog-readonly

1 participant