@@ -27,6 +27,9 @@ type createBranchResponse struct {
2727func (p * githubPlugin ) createBranch (req * plugin.Request , res * plugin.Response ) {
2828 projectID := req .Caller .ProjectID
2929 taskID := req .PathParam ("taskId" )
30+ if ! p .taskBelongsToProject (taskID , projectID , res ) {
31+ return
32+ }
3033
3134 type createBranchBody struct {
3235 RepoID string `json:"repo_id"`
@@ -112,6 +115,9 @@ func (p *githubPlugin) createBranch(req *plugin.Request, res *plugin.Response) {
112115func (p * githubPlugin ) linkBranchToTask (req * plugin.Request , res * plugin.Response ) {
113116 projectID := req .Caller .ProjectID
114117 taskID := req .PathParam ("taskId" )
118+ if ! p .taskBelongsToProject (taskID , projectID , res ) {
119+ return
120+ }
115121
116122 type linkBranchToTaskBody struct {
117123 RepoID string `json:"repo_id"`
@@ -199,24 +205,48 @@ func (p *githubPlugin) linkBranchToTask(req *plugin.Request, res *plugin.Respons
199205// ─── GET /tasks/:taskId/github/branches ───────────────────────────────────────
200206
201207func (p * githubPlugin ) listTaskBranches (req * plugin.Request , res * plugin.Response ) {
208+ projectID := req .Caller .ProjectID
202209 taskID := req .PathParam ("taskId" )
210+ if ! p .taskBelongsToProject (taskID , projectID , res ) {
211+ return
212+ }
203213
204- result , err := p .db .Query (`
205- SELECT id, task_id, repo_id, branch_name, created_at
206- FROM github_task_branches WHERE task_id = $1 ORDER BY created_at ASC
207- ` , taskID )
214+ result , err := p .db .Query (
215+ ` SELECT id, task_id, repo_id, branch_name, created_at FROM github_task_branches WHERE task_id = $1 ORDER BY created_at ASC` ,
216+ taskID ,
217+ )
208218 if err != nil {
209219 apiError (res , 500 , "INTERNAL_ERROR" , err .Error ())
210220 return
211221 }
212222
223+ // github_task_branches has no project_id column of its own — only
224+ // repo_id, which links to github_repositories (which does). Re-verify
225+ // each branch's repo against the caller's project as defense-in-depth:
226+ // taskBelongsToProject above already closes the main vector (a foreign
227+ // taskId), but this also protects against any row a pre-fix caller
228+ // might have already linked across projects. No SQL JOIN here (kept
229+ // consistent with resolvePRForTask's style elsewhere in this plugin,
230+ // which also resolves through separate single-table queries).
213231 items := make ([]taskBranchResponse , 0 , len (result .Rows ))
214232 for _ , row := range result .Rows {
215233 sc := newRowScanner (result .Columns , row )
234+ repoID := sc .str ("repo_id" )
235+ repoResult , rErr := p .db .Query (
236+ `SELECT id FROM github_repositories WHERE id = $1 AND project_id = $2` ,
237+ repoID , projectID ,
238+ )
239+ if rErr != nil {
240+ apiError (res , 500 , "INTERNAL_ERROR" , rErr .Error ())
241+ return
242+ }
243+ if len (repoResult .Rows ) == 0 {
244+ continue
245+ }
216246 items = append (items , taskBranchResponse {
217247 ID : sc .str ("id" ),
218248 TaskID : sc .str ("task_id" ),
219- RepoID : sc . str ( "repo_id" ) ,
249+ RepoID : repoID ,
220250 BranchName : sc .str ("branch_name" ),
221251 CreatedAt : sc .str ("created_at" ),
222252 })
0 commit comments