Skip to content

os-git-backup: SCP-style SSH URLs corrupted by credential injection #5629

Description

@mplind

Important notices
Before you add a new report, we ask you kindly to acknowledge the following:

Describe the bug

backup() in src/opnsense/mvc/app/library/OPNsense/Backup/Git.php corrupts SCP-style SSH URLs (git@github.com:user/repo.git) when the User Name field is empty. strpos($url, '//') returns false for URLs without //, PHP evaluates false + 2 as 2, and substr() splits the URL at position 2:

git@github.com:user/repo.git
-> gi + @ + t@github.com:user/repo.git
-> gi@t@github.com:user/repo.git

git push then fails with an authentication error against the invalid remote URL.

Two defects combine here (lines 165-172):

  1. The code uses $pos in substr() without checking for false. SCP-style URLs contain no //.
  2. For non-HTTP URLs the code injects the user even when the field is empty, producing a bare @.

Last known working version: none known.

To Reproduce

  1. Install os-git-backup
  2. Set URL to git@github.com:user/repo.git
  3. Leave User Name empty
  4. Provide an SSH private key
  5. Run the backup

Expected behavior

The SCP-style URL passes through to git remote add origin unchanged; the SSH key handles authentication.

Screenshots

Not applicable.

Relevant log files

The backup log shows git push failing with an authentication error against the corrupted remote URL.

Additional context

Suggested fix: wrap credential injection in a $pos !== false check so the code never modifies SCP-style URLs, and skip injection for SSH URLs without a configured user:

if ($pos !== false) {
    if (stripos(trim((string)$mdl->url), 'http') === 0) {
        $cred = urlencode((string)$mdl->user) . ":" . urlencode((string)$mdl->password);
        $url = substr($url, 0, $pos + 2) . "{$cred}@" . substr($url, $pos + 2);
    } elseif (!empty((string)$mdl->user)) {
        $url = substr($url, 0, $pos + 2) . urlencode((string)$mdl->user) . "@" . substr($url, $pos + 2);
    }
}

Workaround: use ssh://github.com/user/repo.git with git in the User Name field; the plugin then builds ssh://git@github.com/user/repo.git.

Refiled from #5234 on the issue template; closing the original.

Environment

OPNsense 26.1.2
os-git-backup (current plugins master)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions