@@ -26,6 +26,7 @@ import (
26
26
"path/filepath"
27
27
"testing"
28
28
29
+ "github.com/arduino/arduino-create-agent/upload"
29
30
"github.com/arduino/arduino-create-agent/config"
30
31
"github.com/arduino/arduino-create-agent/gen/tools"
31
32
v2 "github.com/arduino/arduino-create-agent/v2"
@@ -48,6 +49,42 @@ func TestValidSignatureKey(t *testing.T) {
48
49
require .NotNil (t , key )
49
50
}
50
51
52
+ func TestUploadHandlerAgainstEvilFileNames (t * testing.T ) {
53
+ r := gin .New ()
54
+ r .POST ("/" , uploadHandler )
55
+ ts := httptest .NewServer (r )
56
+
57
+ uploadEvilFileName := Upload {
58
+ Port : "/dev/ttyACM0" ,
59
+ Board : "arduino:avr:uno" ,
60
+ Extra : upload.Extra {Network : true },
61
+ Hex : []byte ("test" ),
62
+ Filename : "../evil.txt" ,
63
+ ExtraFiles : []additionalFile {{Hex : []byte ("test" ), Filename : "../evil.txt" }},
64
+ }
65
+ uploadEvilExtraFile := Upload {
66
+ Port : "/dev/ttyACM0" ,
67
+ Board : "arduino:avr:uno" ,
68
+ Extra : upload.Extra {Network : true },
69
+ Hex : []byte ("test" ),
70
+ Filename : "file.txt" ,
71
+ ExtraFiles : []additionalFile {{Hex : []byte ("test" ), Filename : "../evil.txt" }},
72
+ }
73
+
74
+ for _ , request := range []Upload {uploadEvilFileName , uploadEvilExtraFile } {
75
+ payload , err := json .Marshal (request )
76
+ require .NoError (t , err )
77
+
78
+ resp , err := http .Post (ts .URL , "encoding/json" , bytes .NewBuffer (payload ))
79
+ require .NoError (t , err )
80
+ require .Equal (t , http .StatusBadRequest , resp .StatusCode )
81
+
82
+ body , err := io .ReadAll (resp .Body )
83
+ require .NoError (t , err )
84
+ require .Contains (t , string (body ), "unsafe path join" )
85
+ }
86
+ }
87
+
51
88
func TestInstallToolDifferentContentType (t * testing.T ) {
52
89
r := gin .New ()
53
90
goa := v2 .Server (config .GetDataDir ().String ())
0 commit comments