Skip to content

fix(git): validate literal branch refs and node URLs - #667

Closed
jatmn wants to merge 1 commit into
Twigpine:mainfrom
jatmn:fix/code-scanning-alerts
Closed

jatmn wants to merge 1 commit into
Twigpine:mainfrom
jatmn:fix/code-scanning-alerts

Conversation

@jatmn

@jatmn jatmn commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Validate Git branch names as literal local refs and require a valid HTTP(S) node URL before the remote helper builds its request destination.

Motivation & context

Git's branch shorthand validator can consult the working repository. Validation should depend only on the name being stored or used. The remote helper now rejects malformed node configuration before appending repository path components.

Kind of change

  • Bug fix
  • Security fix

What changed

  • twigpine-node checks the literal full ref with Git and applies the short-name rules before launch.
  • git-remote-twigpine parses the configured node URL before applying the existing transport policy. Regression coverage checks malformed configuration with and without the plaintext opt-in.

How a reviewer can verify

cargo test --locked -p git-remote-twigpine --bin git-remote-twigpine insecure_transport_tests
cargo test --locked -p twigpine-node validate_git_ref
cargo test --locked --workspace

Before you request review

  • Scope is one logical change
  • New behavior is covered by tests
  • Checked existing PRs for overlap
  • cargo test --workspace passed locally
  • Formatting and Clippy passed on Rust 1.100.1
  • Conventional Commit title

The PostgreSQL-backed real-node deny and models harness, release build, and MSRV check on Rust 1.91.1 also passed. CodeQL 2.27.6 removed the branch-validation command-line result and found no new results. Its surviving HTTP result follows a test fixture that verifies a signed request locally.

Reviewed commit aae8dde92d86a38dba9513cb3e495577118b40fe.

Summary by CodeRabbit

  • Bug Fixes
    • Remote connections now reject malformed URLs and schemes other than HTTP or HTTPS, regardless of whether plaintext HTTP is allowed.
    • Branch names that are HEAD, begin with a hyphen, or fail Git’s reference-format rules are rejected. Invalid branch names now produce a consistent error message.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The remote helper now validates the node URL before applying the existing plaintext HTTP check. Git branch validation rejects reserved names and checks refs/heads/{name} with git check-ref-format.

Changes: Transport URL validation

Layer / File(s) Summary
Parse and check transport URLs
crates/git-remote-twigpine/src/main.rs
The transport check parses the node base URL and rejects parse failures and schemes other than HTTP and HTTPS. Tests cover malformed, missing-scheme, and file URLs with both plaintext settings.

Git branch-name validation

Layer / File(s) Summary
Validate local branch refs
crates/twigpine-node/src/git/store.rs
The validator rejects HEAD and names beginning with -, then checks refs/heads/{name} without --branch. Format failures return a fixed invalid-branch-name message. The documentation describes these rules and explicit local refs at diff and merge sinks.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: kind:bug, kind:security, crate:node, crate:git-remote

Suggested reviewers: beardthelion

Merge Risk: Minimal · up to aae8d

The change tightens validation of node URLs and branch names before they are used. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(git): validate literal branch refs and node URLs" matches the main changes. The diff validates branch names as literal full refs with git check-ref-format in twigpine-node, and git-remo…
Description check Passed The description follows the template's main sections: Summary, Motivation & context, Kind of change, What changed, How a reviewer can verify, and Before you request review. It describes the branch-ref…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(git): validate literal branch refs and node URLs" matches the main changes. The diff validates branch names as literal full refs with git check-ref-format in twigpine-node, and git-remote-twigpine parses TWIGPINE_NODE as a URL and rejects non-HTTP(S) schemes before the transport check. The title names both areas and uses a Conventional Commit prefix. It is specific, but it is a long single line that lists two changes.

Full details: Description check

Explanation

The description follows the template's main sections: Summary, Motivation & context, Kind of change, What changed, How a reviewer can verify, and Before you request review. It describes the branch-ref and node-URL changes and gives the test commands. The Motivation section does not include the template's 'Closes #' issue link, and the 'Notes for reviewers' section is omitted, which is optional. The checklist was filled in, but the template's 'Protocol & signing impact' block was not addressed, and the description does not state whether the change touches the protocol. The 'How a reviewer can verify' block includes commands but does not include repro steps with proof that the bug is fixed. The description also mentions CodeQL and the PostgreSQL harness, which the template does not ask for.

Resolution

Optionally add the linked issue to 'Closes #', state whether the protocol-impact block applies or delete it, and note the 'Docs / .env.example' checklist item (the change updates validation docs, so it should be checked or marked N/A).

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 9aebf6ff-f72f-47f2-832f-6f6eba12b5a7
Commits

Reviewing files that changed from the base of the PR and between 617e876 and aae8dde.

Files selected for processing: 2

  • crates/git-remote-twigpine/src/main.rs
  • crates/twigpine-node/src/git/store.rs

Included review availability: This review used your included allowance. 4 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

@jatmn jatmn self-assigned this Dec 2, 2026
@jatmn
jatmn marked this pull request as ready for review December 2, 2026 05:31
Copilot AI balanced review requested due to automatic review settings December 2, 2026 05:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the branch-name and node-URL validation changes.

No open issues 🎉

What changed in this PR

Strengthens input validation for Git branch names in the node and configured node URLs in the remote helper.

Changes:

  • Validates literal refs/heads/ names independently of the working repository while preserving short-name restrictions.
  • Requires a parseable HTTP(S) node URL before applying transport policy, with regression tests covering plaintext opt-in.
File Description
crates/​twigpine-node/​src/​git/​store.rs Replaces branch-shorthand validation with literal full-ref validation.
crates/​git-remote-twigpine/​src/​main.rs Validates node URLs and tests malformed or unsupported configurations.

Review effort: Balanced

@jatmn
jatmn requested a review from beardthelion December 2, 2026 05:40

@beardthelion beardthelion left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Branch validation now runs git check-ref-format refs/heads/<name> with explicit rejection of HEAD and a leading -. I ran the old --branch path against the new logic on git 2.43.0 over 49 names (@{-1}, .lock, .., control characters, -x, HEAD, refs/heads/x) and accept/reject matched on every one. Removing the HEAD/dash guard turns the existing validate_git_ref tests red, so the guard is covered.

check_transport_security now fails closed on an unparseable or non-http(s) TWIGPINE_NODE, including with the plaintext opt-in set. Dropping either the parse error or the scheme check turns gate_requires_a_valid_node_url_even_with_plaintext_opt_in red. repo_base is still built from the raw string, and is_insecure_remote re-parses its input, so gating on the normalized URL gives the same result.

Callers of validate_git_ref only match on the Invalid/GitUnavailable variants, so dropping git's stderr changes message text only. Two non-blocking notes: no test pins the repo-independent behavior the description claims (reverting to --branch stays green), and the gl gate in twigpine-cli/src/http.rs has no equivalent parse step.

@beardthelion

Copy link
Copy Markdown
Collaborator

Continued in #673, same commit carried over unchanged on an upstream branch. Closing this one in favor of it.

auto-merge was automatically disabled December 3, 2026 14:58

Pull request was closed

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.

3 participants