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):
- The code uses
$pos in substr() without checking for false. SCP-style URLs contain no //.
- 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
- Install os-git-backup
- Set URL to
git@github.com:user/repo.git
- Leave User Name empty
- Provide an SSH private key
- 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)
Important notices
Before you add a new report, we ask you kindly to acknowledge the following:
Describe the bug
backup()insrc/opnsense/mvc/app/library/OPNsense/Backup/Git.phpcorrupts SCP-style SSH URLs (git@github.com:user/repo.git) when the User Name field is empty.strpos($url, '//')returnsfalsefor URLs without//, PHP evaluatesfalse + 2as2, andsubstr()splits the URL at position 2:git pushthen fails with an authentication error against the invalid remote URL.Two defects combine here (lines 165-172):
$posinsubstr()without checking forfalse. SCP-style URLs contain no//.@.Last known working version: none known.
To Reproduce
git@github.com:user/repo.gitExpected behavior
The SCP-style URL passes through to
git remote add originunchanged; the SSH key handles authentication.Screenshots
Not applicable.
Relevant log files
The backup log shows
git pushfailing with an authentication error against the corrupted remote URL.Additional context
Suggested fix: wrap credential injection in a
$pos !== falsecheck so the code never modifies SCP-style URLs, and skip injection for SSH URLs without a configured user:Workaround: use
ssh://github.com/user/repo.gitwithgitin the User Name field; the plugin then buildsssh://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)