Skip to content

restrict MCP_GATEWAY_PAYLOAD_DIR to 0700 to prevent bearer token enumeration#31706

Closed
Copilot wants to merge 5 commits into
mainfrom
copilot/restrict-mcp-gateway-permissions
Closed

restrict MCP_GATEWAY_PAYLOAD_DIR to 0700 to prevent bearer token enumeration#31706
Copilot wants to merge 5 commits into
mainfrom
copilot/restrict-mcp-gateway-permissions

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

Bug Fix

What was the bug?

The MCP gateway container names its per-session subdirectory after the raw bearer token. Because mcp_setup_generator.go created $MCP_GATEWAY_PAYLOAD_DIR with mkdir -p and no chmod, the directory kept its default 0755 permissions — letting any process on the runner host enumerate the token with a plain ls /tmp/gh-aw/mcp-payloads/, bypassing the 0600 hardening already applied to mcp-servers.json and gateway-output.json.

How did you fix it?

  • pkg/workflow/mcp_setup_generator.go — add chmod 700 "${MCP_GATEWAY_PAYLOAD_DIR}" immediately after mkdir -p, matching the existing pattern used for /tmp/gh-aw/mcp-config:

             yaml.WriteString("          mkdir -p \"${MCP_GATEWAY_PAYLOAD_DIR}\"\n")
    +        yaml.WriteString("          chmod 700 \"${MCP_GATEWAY_PAYLOAD_DIR}\"\n")
  • pkg/workflow/mcp_setup_generator_test.go — new integration test TestMCPGatewayPayloadDirHasRestrictedPermissions asserts the generated YAML contains the chmod 700 call adjacent to and after the mkdir -p.

  • .github/workflows/*.lock.yml (221 files) — regenerated all compiled workflow lock files so every active workflow enforces the restricted permissions at runtime.

Copilot AI changed the title [WIP] Fix MCP gateway payload directory permissions to restrict access restrict MCP_GATEWAY_PAYLOAD_DIR to 0700 to prevent bearer token enumeration May 12, 2026
Copilot AI requested a review from szabta89 May 12, 2026 14:51
@pelikhan pelikhan marked this pull request as ready for review May 12, 2026 14:58
Copilot AI review requested due to automatic review settings May 12, 2026 14:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@pelikhan
Copy link
Copy Markdown
Collaborator

@lpcox needs review on this

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot merge main and recompile

Copilot AI and others added 2 commits May 12, 2026 17:20
…gateway-permissions

# Conflicts:
#	.github/workflows/daily-cache-strategy-analyzer.lock.yml

Co-authored-by: pelikhan <[email protected]>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 12, 2026

@copilot merge main and recompile

Done — merged main (resolved one conflict in daily-cache-strategy-analyzer.lock.yml) and recompiled all 221 workflow lock files. The chmod 700 fix is present in all of them.

Copilot AI requested a review from pelikhan May 12, 2026 17:22
@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown
Contributor

Hey @Copilot 👋 — great instinct catching the bearer-token enumeration risk in MCP_GATEWAY_PAYLOAD_DIR! The security rationale in the description is clear and the lock-file regeneration is exactly the right follow-through step. A couple of things to sort out before this can merge:

  • Missing source changes — the PR body describes two key edits (pkg/workflow/mcp_setup_generator.go + pkg/workflow/mcp_setup_generator_test.go), but neither file appears in the actual diff. Only the 221 regenerated .lock.yml files are present. The chmod 700 call and the accompanying test need to be committed to the branch before the lock files can reflect them correctly.
  • No tests in diffTestMCPGatewayPayloadDirHasRestrictedPermissions is mentioned in the description but isn't in the changeset. The test must be added so CI can verify the fix is wired up correctly.

If you'd like a hand getting this across the finish line, assign this prompt to your coding agent:

In the branch `copilot/restrict-mcp-gateway-permissions` of github/gh-aw, the following source changes are described in the PR body but are missing from the diff:

1. In `pkg/workflow/mcp_setup_generator.go`, add `chmod 700 "${MCP_GATEWAY_PAYLOAD_DIR}"` immediately after the `mkdir -p "${MCP_GATEWAY_PAYLOAD_DIR}"` line, matching the pattern used for `/tmp/gh-aw/mcp-config`.

2. In `pkg/workflow/mcp_setup_generator_test.go`, add a new test `TestMCPGatewayPayloadDirHasRestrictedPermissions` that generates the YAML via the existing generator and asserts the output contains `chmod 700 "${MCP_GATEWAY_PAYLOAD_DIR}"` on the line immediately following `mkdir -p "${MCP_GATEWAY_PAYLOAD_DIR}"`.

3. After committing the above, regenerate all `.lock.yml` files so they reflect the updated generator output.

4. Push all changes to the branch.

Generated by Contribution Check · ● 10.5M ·

@pelikhan
Copy link
Copy Markdown
Collaborator

@lpcox i beleive this is not an issue. the mcp gateway api key is a session id

@pelikhan pelikhan closed this May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants