Encode owner/repo path segments in issue tools (path-rewrite risk) #1
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Every tool in
src/tools/issues.jsinterpolatesownerandrepostraight into the request path without encoding, for example:Because
forgejoRequestbuilds the URL withnew URL(), the WHATWG URL parser normalizes..segments before the request is sent. A crafted value therefore rewrites the target path rather than being rejected. Verified locally:So the request escapes the
/api/v1/reposprefix entirely and is still sent with the all-access PAT attached. Practical exploitability is limited because the fixed suffix (/issues,/comments,/times, ...) always sticks to the end of the rewritten path, but the same class of input can also cause owner/repo confusion (a value containing/silently targets a different namespace).This is inconsistent with the generic path:
fillPathParamsinsrc/forgejo-client.jsalready doesencodeURIComponent(String(value))on every path parameter, andsubscribe_to_issue/unsubscribe_from_issuealready encodeusername.Affected
src/tools/issues.js- list_issues, get_issue, create_issue, update_issue, add_issue_comment, subscribe_to_issue, unsubscribe_from_issue, start_stopwatch, stop_stopwatch, add_tracked_time. Alsosrc/issue-helpers.js(resolveLabelIds,resolveMilestoneIdbuild/repos/${owner}/${repo}/labelsand/milestonesthe same way).Suggested fix
Route every hand-written path through
fillPathParamsso encoding is centralized and consistent:Alternatively add a small
encodeSegmentshelper, but reusingfillPathParamsavoids a second code path that can drift.Severity
Medium - defense in depth. The token used here is an all-access PAT, and tool arguments come from model output, so untrusted-ish input reaching the path builder is a realistic scenario.