@@ -28,6 +28,7 @@ import (
2828
2929 "github.com/arduino/arduino-create-agent/config"
3030 "github.com/arduino/arduino-create-agent/gen/tools"
31+ "github.com/arduino/arduino-create-agent/upload"
3132 v2 "github.com/arduino/arduino-create-agent/v2"
3233 "github.com/gin-gonic/gin"
3334 "github.com/stretchr/testify/require"
@@ -48,6 +49,42 @@ func TestValidSignatureKey(t *testing.T) {
4849 require .NotNil (t , key )
4950}
5051
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+
5188func TestInstallToolDifferentContentType (t * testing.T ) {
5289 r := gin .New ()
5390 goa := v2 .Server (config .GetDataDir ().String ())
0 commit comments