X Tutup
Skip to content

feat(gitter): affected commits graph walking#4974

Open
Ly-Joey wants to merge 19 commits intogoogle:masterfrom
Ly-Joey:feat-gitter-affected-commits
Open

feat(gitter): affected commits graph walking#4974
Ly-Joey wants to merge 19 commits intogoogle:masterfrom
Ly-Joey:feat-gitter-affected-commits

Conversation

@Ly-Joey
Copy link
Contributor

@Ly-Joey Ly-Joey commented Mar 5, 2026

Add graph related logic and find affected commits.

Definition of affected commits:

A commit is affected when: from at least one introduced there is no path from the commit through a fix to the introduced
(A better worded def coming soon!)

Key changes

New endpoint:

  • POST /affected-commits:
    • Accepts a list of events (each containing an eventType (introduced, fixed, lastAffected, or limit) and commit hash)
    • Returns a list of affected commits (hash in bytes and associated refs) in protobuf format

Cherry-pick Detection:
Optional support to expand introduced and fixed commits to include their cherry-picked equivalents (determined with PatchID)

There's a follow-up PR (WIP) to refactor gitter and add LRU cache of the in-memory repo.

@Ly-Joey
Copy link
Contributor Author

Ly-Joey commented Mar 9, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces significant new functionality for determining affected commits by walking the git graph. However, it also introduces several critical security vulnerabilities, primarily related to command injection and SSRF. The most severe issue is in buildCommitGraph, where user-controlled data is concatenated into a shell command, and new endpoints lack the protocol validation present in existing ones, allowing for command execution via git protocols. Additionally, a potential Denial of Service vulnerability due to unvalidated input length during hash parsing was identified. Beyond these security concerns, a critical bug was found in the graph building logic, and there are opportunities to improve code structure and testing practices to enhance maintainability and robustness.

Comment on lines +269 to +272
if status := rr.Code; status != tt.expectedCode {
t.Errorf("handler returned wrong status code: got %v want %v",
status, tt.expectedCode)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The test case for a valid request (Valid range in public repo) only checks for http.StatusOK. It would be more robust to also validate the response body to ensure the correct affected commits are returned. You could unmarshal the protobuf response and compare it against an expected set of commits.

@Ly-Joey Ly-Joey force-pushed the feat-gitter-affected-commits branch from 4227a68 to 97b9e25 Compare March 10, 2026 02:19
@Ly-Joey
Copy link
Contributor Author

Ly-Joey commented Mar 10, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a new /affected-commits API endpoint to the gitter service, enabling clients to query for commits affected by specific events (introduced, fixed, last_affected, limit) within a Git repository. This includes implementing graph traversal logic (Affected and Limit methods) with support for cherry-pick detection, defining new Protobuf messages for the API response, and adding URL validation to both the new and existing /cache handlers. The Commit struct was updated to use Refs instead of Tags, and rootCommits were added to the Repository struct. Review comments highlighted several areas for improvement: optimizing regex compilation for URL validation in both cacheHandler and affectedCommitsHandler by compiling it once at the package level; enhancing test robustness and readability in TestAffectedCommitsHandler by using EventType constants instead of hardcoded strings; clarifying the Limit function's assumption about linear history when traversing commits by following only the first parent; and correcting a bug in the decodeSHA1 helper function in repository_test.go where fmt.Sprintf incorrectly pads with spaces instead of zeros, which would cause hex.DecodeString to fail.

@Ly-Joey Ly-Joey marked this pull request as ready for review March 10, 2026 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

X Tutup