Title: delete_file: no sha precondition, and a directory path deletes the whole subtree · Issue #3757 · github/github-mcp-server · GitHub
Open Graph Title: delete_file: no sha precondition, and a directory path deletes the whole subtree · Issue #3757 · github/github-mcp-server
X Title: delete_file: no sha precondition, and a directory path deletes the whole subtree · Issue #3757 · github/github-mcp-server
Description: Describe the bug delete_file does not use DELETE /repos/{owner}/{repo}/contents/{path} (which requires the blob sha). It builds a tree entry {path, mode 100644, type blob, sha: nil} on top of the branch's current head and commits it thro...
Open Graph Description: Describe the bug delete_file does not use DELETE /repos/{owner}/{repo}/contents/{path} (which requires the blob sha). It builds a tree entry {path, mode 100644, type blob, sha: nil} on top of the b...
X Description: Describe the bug delete_file does not use DELETE /repos/{owner}/{repo}/contents/{path} (which requires the blob sha). It builds a tree entry {path, mode 100644, type blob, sha: nil} on top of the b...
Opengraph URL: https://github.com/github/github-mcp-server/issues/3757
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"delete_file: no sha precondition, and a directory path deletes the whole subtree","articleBody":"### Describe the bug\n\n`delete_file` does not use `DELETE /repos/{owner}/{repo}/contents/{path}` (which requires the blob `sha`). It builds a tree entry `{path, mode 100644, type blob, sha: nil}` on top of the branch's current head and commits it through the Git Data API. That has two effects:\n\n1. **No precondition.** The input schema has no `sha` property. A `sha` argument is accepted and silently ignored. A file another writer changed after the caller read it is deleted anyway.\n2. **No type check on the path.** A directory path removes every file under it, recursively, and the tool reports success.\n\nCode (main 99d6d650, unchanged since v2.1.0): `pkg/github/repositories.go:1333` (`DeleteFile`; required `owner, repo, path, message, branch`, no `sha`), `:1430-1441` (nil-sha tree entry, `CreateTree` on the head's tree).\n\n### Affected version\n\nv2.1.0 (image `sha256:f6056fc1…0f8a`, commit 4bcdcdf8) and main nightly (image `sha256:48bc16d0…338f`, revision 99d6d650). Local stdio, fine-grained PAT.\n\n### Steps to reproduce the behavior\n\nStale delete:\n1. On branch `test`, create `p4/del.txt` with content `d0`. Its blob sha is `S0`.\n2. A second writer updates the file (`PUT /contents` with `sha: S0`, content `d1-written-after-read`). Its blob sha is now `S1`.\n3. Call:\n ```json\n {\"name\":\"delete_file\",\"arguments\":{\"owner\":\"OWNER\",\"repo\":\"REPO\",\"branch\":\"test\",\"path\":\"p4/del.txt\",\"message\":\"delete\",\"sha\":\"S0\"}}\n ```\n4. Result: success with a new commit. `GET /contents/p4/del.txt?ref=test` returns 404. The newer content is gone, although `S0 != S1`.\n\nDirectory path:\n1. `push_files` `p4/dir/a.txt` and `p4/dir/sub/b.txt` to `test`.\n2. Call:\n ```json\n {\"name\":\"delete_file\",\"arguments\":{\"owner\":\"OWNER\",\"repo\":\"REPO\",\"branch\":\"test\",\"path\":\"p4/dir\",\"message\":\"delete\"}}\n ```\n3. Result: success. Tree before: `p4/dir/a.txt`, `p4/dir/sub/b.txt`. Tree after: neither file.\n\n### Expected vs actual behavior\n\nExpected:\n- A `sha` parameter, as `create_or_update_file` has, checked against the current blob. A stale sha is refused, or at the least an unsupported `sha` argument is not silently accepted.\n- A directory path is rejected (\"path is a directory\").\n\nActual: both calls succeed. The schema gives a caller no way to make the delete conditional.\n\nSuggested fix: before building the tree, fetch the entry at `path` on `branch`. Refuse if it is not a blob, and refuse if a supplied `sha` differs from its sha. Using the Contents `DELETE` endpoint would enforce both, but the comment above `DeleteFile` (`repositories.go:1327-1331`) says the Git Data route is deliberate, because the Contents endpoint does not sign the deletion commit. A pre-check on the current code path avoids that trade-off. Note: open PR #3288 moves `delete_file` onto a shared commit path that retries a ref conflict by rebuilding on the latest tip. Without a sha check, that retry would also delete content written during the retry window.\n\n### Logs\n\n```\ndelete_file (stale sha S0, current S1) -> OK {\"commit\":{\"sha\":\"f9953c67…\", …}} (v2.1.0)\n -> OK {\"commit\":{\"sha\":\"a5e7ecf5…\", …}} (main)\nGET contents p4/del.txt -> 404\ndelete_file path \"p4/dir\" -> OK {\"commit\":{\"sha\":\"47c16484…\", …}} (v2.1.0); 3b1e4ad3… (main)\ntree p4/* before: p4/dir/a.txt, p4/dir/sub/b.txt, p4/stale.txt after: p4/stale.txt\ntools/list delete_file properties: branch, message, owner, path, repo\n```\n\nFound during an independent audit of v2.1.0 on a throwaway org and private test repo. Prepared with AI assistance (Claude Code); reproduced by two independent test runs before filing.\n","author":{"url":"https://github.com/rafe-walker","@type":"Person","name":"rafe-walker"},"datePublished":"2026-11-09T06:00:00Z","url":"https://github.com/github/github-mcp-server/issues/3757"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f9d28dd2-c425-c18f-bf45-9bbd0bcc61e5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C668:3A6805:8929D2:B60263:6B05F001 |
| html-safe-nonce | 0563407c7ff89eea7e64a1f9ba06fa87674861ebc4a5f32eb64eaf1460c7fadd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNjY4OjNBNjgwNTo4OTI5RDI6QjYwMjYzOjZCMDVGMDAxIiwidmlzaXRvcl9pZCI6IjUyNDQ4OTgwOTUyNTg3OTE5MzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 801c9aff4b459fd4d1e63eed017773946825cfd5e5848d0feb0a18c4348f59b8 |
| hovercard-subject-tag | issue:6280845523 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/github/github-mcp-server/3757/issue_layout |
| twitter:image | https://opengraph.githubassets.com/18b14a5c277d7b050f6b12d3f0dc1eb6f63ac933ad667ffcc0bf6552d588f7f5/github/github-mcp-server/issues/3757 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/18b14a5c277d7b050f6b12d3f0dc1eb6f63ac933ad667ffcc0bf6552d588f7f5/github/github-mcp-server/issues/3757 |
| og:image:alt | Describe the bug delete_file does not use DELETE /repos/{owner}/{repo}/contents/{path} (which requires the blob sha). It builds a tree entry {path, mode 100644, type blob, sha: nil} on top of the b... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rafe-walker |
| hostname | github.com |
| expected-hostname | github.com |
| None | c214754a6652274794ed4e054a7b71be999d69843f103ba54893001d45010ece |
| turbo-cache-control | no-preview |
| go-import | github.com/github/github-mcp-server git https://github.com/github/github-mcp-server.git |
| octolytics-dimension-user_id | 9919 |
| octolytics-dimension-user_login | github |
| octolytics-dimension-repository_id | 942771284 |
| octolytics-dimension-repository_nwo | github/github-mcp-server |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 942771284 |
| octolytics-dimension-repository_network_root_nwo | github/github-mcp-server |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7d164a4e71eb333b2b17fd5b17e18efb7855505c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width