Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
7a060cc5
Commit
7a060cc5
authored
Oct 15, 2023
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ssh: option injection code review
parent
ad3799e8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
31 deletions
+25
-31
src/libgit2/transports/ssh_exec.c
+11
-15
src/libgit2/transports/ssh_libssh2.c
+3
-2
src/util/net.c
+0
-5
src/util/net.h
+0
-9
src/util/process.h
+11
-0
No files found.
src/libgit2/transports/ssh_exec.c
View file @
7a060cc5
...
...
@@ -132,26 +132,22 @@ static int get_ssh_cmdline(
const
char
*
default_ssh_cmd
=
"ssh"
;
int
error
;
/* Safety check: like git, we forbid paths that look like an option as
* that could lead to injection to ssh that can make us do unexpected
* things */
if
(
git_net_looks_like_command_line_option
(
url
->
username
))
{
git_error_set
(
GIT_ERROR_NET
,
"strange username '%s' blocked"
,
url
->
username
);
/*
* Safety check: like git, we forbid paths that look like an
* option as that could lead to injection to ssh that can make
* us do unexpected things
*/
if
(
git_process__is_cmdline_option
(
url
->
username
))
{
git_error_set
(
GIT_ERROR_NET
,
"cannot ssh: username '%s' is ambiguous with command-line option"
,
url
->
username
);
return
-
1
;
}
if
(
git_net_looks_like_command_line_option
(
url
->
host
))
{
git_error_set
(
GIT_ERROR_NET
,
"strange host '%s' blocked"
,
url
->
host
);
}
else
if
(
git_process__is_cmdline_option
(
url
->
host
))
{
git_error_set
(
GIT_ERROR_NET
,
"cannot ssh: host '%s' is ambiguous with command-line option"
,
url
->
host
);
return
-
1
;
}
/* Safety check: like git, we forbid paths that look like an option as
* that could lead to injection on the remote side */
if
(
git_net_looks_like_command_line_option
(
url
->
path
))
{
git_error_set
(
GIT_ERROR_NET
,
"strange path '%s' blocked"
,
url
->
path
);
}
else
if
(
git_process__is_cmdline_option
(
url
->
path
))
{
git_error_set
(
GIT_ERROR_NET
,
"cannot ssh: path '%s' is ambiguous with command-line option"
,
url
->
path
);
return
-
1
;
}
if
((
error
=
git_repository_config_snapshot
(
&
cfg
,
repo
))
<
0
)
return
error
;
...
...
src/libgit2/transports/ssh_libssh2.c
View file @
7a060cc5
...
...
@@ -14,6 +14,7 @@
#include "runtime.h"
#include "net.h"
#include "smart.h"
#include "process.h"
#include "streams/socket.h"
#include "sysdir.h"
...
...
@@ -790,8 +791,8 @@ static int _git_ssh_setup_conn(
/* Safety check: like git, we forbid paths that look like an option as
* that could lead to injection on the remote side */
if
(
git_
net_looks_like_command_
line_option
(
s
->
url
.
path
))
{
git_error_set
(
GIT_ERROR_NET
,
"
strange path '%s' blocked
"
,
s
->
url
.
path
);
if
(
git_
process__is_cmd
line_option
(
s
->
url
.
path
))
{
git_error_set
(
GIT_ERROR_NET
,
"
cannot ssh: path '%s' is ambiguous with command-line option
"
,
s
->
url
.
path
);
error
=
-
1
;
goto
done
;
}
...
...
src/util/net.c
View file @
7a060cc5
...
...
@@ -1152,8 +1152,3 @@ void git_net_url_dispose(git_net_url *url)
git__free
(
url
->
username
);
url
->
username
=
NULL
;
git__free
(
url
->
password
);
url
->
password
=
NULL
;
}
int
git_net_looks_like_command_line_option
(
const
char
*
str
)
{
return
str
&&
str
[
0
]
==
'-'
;
}
src/util/net.h
View file @
7a060cc5
...
...
@@ -107,13 +107,4 @@ extern bool git_net_url_matches_pattern_list(
/** Disposes the contents of the structure. */
extern
void
git_net_url_dispose
(
git_net_url
*
url
);
/**
* Returns true if the string starts with a dash
*
* These could be used to try to trick an executed subcommand like ssh to do
* something other than what we intend.
*/
int
git_net_looks_like_command_line_option
(
const
char
*
str
);
#endif
src/util/process.h
View file @
7a060cc5
...
...
@@ -106,6 +106,17 @@ extern int git_process__cmdline(
#endif
/*
* Whether the given string looks like a command line option (starts
* with a dash). This is useful for examining strings that will become
* cmdline arguments to ensure that they are not erroneously treated
* as an option. For example, arguments to `ssh`.
*/
GIT_INLINE
(
bool
)
git_process__is_cmdline_option
(
const
char
*
str
)
{
return
(
str
&&
str
[
0
]
==
'-'
);
}
/**
* Start the process.
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment