Skip to content

fix(pkg/git): normalize web URL schemes, strip credentials, and improve SCP username parsing - #7510

Open
Norway-02 wants to merge 1 commit into
pipe-cd:masterfrom
Norway-02:fix/git-url-scheme-and-scp-parsing
Open

Norway-02 wants to merge 1 commit into
pipe-cd:masterfrom
Norway-02:fix/git-url-scheme-and-scp-parsing

Conversation

@Norway-02

Copy link
Copy Markdown
Contributor

What this PR does:

This PR improves Git URL parsing and web URL generation in pkg/git/url.go:

  1. Normalize web URL schemes to https: In MakeCommitURL and MakeDirURL, the scheme previously checked if u.Scheme != "ssh" { scheme = u.Scheme }. For repositories configured with git:// or git+ssh://, this produced git://... or git+ssh://... links that cannot be opened in a web browser. Now, any non-HTTP protocol (ssh, git, git+ssh) cleanly normalizes to https, while http is preserved.
  2. Prevent credential / token leakage in file creation URLs: In MakeFileCreationURL, previously u.User = nil was only applied if u.Scheme == "ssh". When using HTTP/HTTPS repository URLs containing user credentials or access tokens (e.g., https://oauth2:token@github.com/...), the sensitive credentials leaked into the generated browser URL. u.User is now always stripped.
  3. Support hyphens and dots in SCP usernames: The SCP regex previously used ([a-zA-Z0-9_]+@)?, which failed to parse valid Git SCP URLs containing hyphens or dots in the username (such as git-deployer@host:... or deploy.bot@host:...). Updating the character class to [a-zA-Z0-9_.-]+ enables proper parsing.
  4. Trim surrounding whitespace in parseGitURL: Strips leading and trailing whitespace from input URLs.
  5. Scheme case-insensitivity in parseTransport: Normalizes the scheme to lowercase per RFC 3986 so mixed-case or uppercase schemes (e.g., HTTPS://...) are handled gracefully.

Why we need it:

  • Generated commit and directory links for git:// and git+ssh:// repositories failed to open in web browsers.
  • Embedded tokens/credentials in HTTP/HTTPS URLs were leaked in browser links generated by MakeFileCreationURL.
  • SCP URLs with hyphenated or dotted usernames failed with no scp URL found.

Which issue(s) this PR fixes:

Fixes #

Does this PR introduce a user-facing change?:

  • How are users affected by this change: Generates valid browser URLs for more Git schemes, protects credentials from appearing in web links, and parses SCP URLs with hyphens/dots in usernames.
  • Is this breaking change: No
  • How to migrate (if breaking change): N/A

cc @mohammedfirdouss @armistcxy

…ve SCP username parsing

- In MakeCommitURL and MakeDirURL, ensure non-HTTP schemes (git, git+ssh, ssh) normalize to https so generated browser links open properly.
- In MakeFileCreationURL, strip user credentials (u.User = nil) to prevent credential and token leakage in generated browser links.
- In parseScp, support hyphens and dots in SCP usernames (e.g. git-deployer, deploy.bot).
- In parseGitURL, trim leading/trailing whitespace around raw URLs.
- In parseTransport, treat URL scheme case-insensitively.
- Add unit tests covering git, git+ssh, and ssh:// schemes, credential stripping, hyphenated/dotted SCP usernames, whitespace, and uppercase schemes.

Signed-off-by: Norway-02 <anshulkhetade02@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 22, 2026 05:03
@Norway-02
Norway-02 requested a review from a team as a code owner October 22, 2026 05:03
@netlify

netlify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for pipecd-site canceled.

Name Link
🔨 Latest commit 86137ec
🔍 Latest deploy log https://app.netlify.com/projects/pipecd-site/deploys/6ad9993abd6601abb9f95f29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants