@@ -81,8 +81,8 @@ public function testCanAddArguments()
81
81
$ command ->addArg ('-b= ' , array ('v4 ' ,'v5 ' ,'v6 ' ));
82
82
$ command ->addArg ('-c ' , '' );
83
83
$ command ->addArg ('some name ' , null , true );
84
- $ this ->assertEquals ("--arg1=x --a --a '中文字äüp' --a 'v'\''1' 'v2' 'v3' -b=v -b ='v4' 'v5' 'v6' -c '' 'some name' " , $ command ->getArgs ());
85
- $ this ->assertEquals ("test --arg1=x --a --a '中文字äüp' --a 'v'\''1' 'v2' 'v3' -b=v -b ='v4' 'v5' 'v6' -c '' 'some name' " , $ command ->getExecCommand ());
84
+ $ this ->assertEquals ("--arg1=x ' --a' ' --a' '中文字äüp' ' --a' 'v'\''1' 'v2' 'v3' -b=v '-b' ='v4' 'v5' 'v6' '-c' '' 'some name' " , $ command ->getArgs ());
85
+ $ this ->assertEquals ("test --arg1=x ' --a' ' --a' '中文字äüp' ' --a' 'v'\''1' 'v2' 'v3' -b=v '-b' ='v4' 'v5' 'v6' '-c' '' 'some name' " , $ command ->getExecCommand ());
86
86
}
87
87
public function testCanResetArguments ()
88
88
{
@@ -102,14 +102,29 @@ public function testCanDisableEscaping()
102
102
$ command ->addArg ('-b= ' ,'v ' , true );
103
103
$ command ->addArg ('-b= ' , array ('v4 ' ,'v5 ' ,'v6 ' ));
104
104
$ command ->addArg ('some name ' , null , true );
105
- $ this ->assertEquals ("--a --a v --a v1 v2 v3 -b='v' -b=v4 v5 v6 'some name' " , $ command ->getArgs ());
105
+ $ this ->assertEquals ("--a --a v --a v1 v2 v3 '-b'='v' -b=v4 v5 v6 'some name' " , $ command ->getArgs ());
106
+ }
107
+ public function testCanPreventCommandInjection ()
108
+ {
109
+ $ command = new Command (array (
110
+ 'command ' => 'curl ' ,
111
+ ));
112
+ $ command ->addArg ('http://example.com --wrong-argument || echo "RCE 1" ' );
113
+ $ this ->assertEquals ("'http://example.com --wrong-argument || echo \"RCE 1 \"' " , $ command ->getArgs ());
114
+
115
+ $ command = new Command (array (
116
+ 'command ' => 'curl ' ,
117
+ ));
118
+ $ command ->addArg ('http://example.com ' );
119
+ $ command ->addArg ('--header foo --wrong-argument || echo "RCE 2" || ' , 'bar ' );
120
+ $ this ->assertEquals ("'http://example.com' '--header foo --wrong-argument || echo \"RCE 2 \" ||' 'bar' " , $ command ->getArgs ());
106
121
}
107
122
public function testCanRunCommandWithArguments ()
108
123
{
109
124
$ command = new Command ('ls ' );
110
125
$ command ->addArg ('-l ' );
111
126
$ command ->addArg ('-n ' );
112
- $ this ->assertEquals ("ls -l -n " , $ command ->getExecCommand ());
127
+ $ this ->assertEquals ("ls '-l' '-n' " , $ command ->getExecCommand ());
113
128
$ this ->assertFalse ($ command ->getExecuted ());
114
129
$ this ->assertTrue ($ command ->execute ());
115
130
$ this ->assertTrue ($ command ->getExecuted ());
@@ -163,7 +178,7 @@ public function testCanCastToString()
163
178
$ command = new Command ('ls ' );
164
179
$ command ->addArg ('-l ' );
165
180
$ command ->addArg ('-n ' );
166
- $ this ->assertEquals ("ls -l -n " , (string )$ command );
181
+ $ this ->assertEquals ("ls '-l' '-n' " , (string )$ command );
167
182
}
168
183
169
184
// Exec
0 commit comments