@@ -90,6 +90,8 @@ func main() {
9090 ))
9191 // Uncomment to enable TLS server
9292 // log.Fatal(http.ListenAndServeTLS(":8081", certFile, keyFile, r))
93+ // G114 (CWE-676): Use of net/http serve function that has no support for setting timeouts (Confidence: HIGH, Severity: MEDIUM)
94+ // #nosec G114
9395 log .Fatal (http .ListenAndServe (":8081" , r ))
9496}
9597
@@ -135,7 +137,7 @@ func fooHandler(w http.ResponseWriter, r *http.Request) {
135137 w .Header ().Set ("Content-Type" , "application/json" )
136138 w .WriteHeader (http .StatusOK )
137139
138- w .Write ([]byte (fmt .Sprintf ("{\" param0\" : \" Hello %s\" , \" authorization\" : \" Bearer some-jwt-token\" , \" param2\" :{\" param3\" :\" param4\" ,\" value\" :\" 00000\" }}" , p .Name )))
140+ _ , _ = w .Write ([]byte (fmt .Sprintf ("{\" param0\" : \" Hello %s\" , \" authorization\" : \" Bearer some-jwt-token\" , \" param2\" :{\" param3\" :\" param4\" ,\" value\" :\" 00000\" }}" , p .Name )))
139141}
140142
141143var responseBody string = `{"serviceCount":4,"personalDetailChildren":[{"id":"41d29bf9-3d7b-4e7b-90f1-e405693b592f","firstName":"Bruce","lastName":"Meyer","dateOfBirth":"1951-4-20",` +
@@ -192,7 +194,7 @@ func payloadHandler(w http.ResponseWriter, r *http.Request) {
192194
193195 w .Header ().Set ("Content-Type" , "application/json" )
194196 w .WriteHeader (http .StatusOK )
195- w .Write ([]byte (responseBody ))
197+ _ , _ = w .Write ([]byte (responseBody ))
196198}
197199
198200// Should be a GET request
@@ -215,7 +217,7 @@ func barHandler(w http.ResponseWriter, r *http.Request) {
215217 }
216218
217219 w .WriteHeader (http .StatusOK )
218- w .Write ([]byte (fmt .Sprintf ("{\" message\" : \" Hello %s\" }" , author )))
220+ _ , _ = w .Write ([]byte (fmt .Sprintf ("{\" message\" : \" Hello %s\" }" , author )))
219221}
220222
221223// Should be a POST request.
@@ -234,7 +236,7 @@ func barBodyHandler(w http.ResponseWriter, r *http.Request) {
234236 w .Header ().Add ("Set-Cookie" , "timothercookie789=cval1;secure" )
235237 w .Header ().Add ("Set-Cookie" , "timothercookie=cval2;secure" )
236238 w .WriteHeader (http .StatusOK )
237- w .Write ([]byte (fmt .Sprintf ("{\" message\" : \" Hello %s\" }" , author )))
239+ _ , _ = w .Write ([]byte (fmt .Sprintf ("{\" message\" : \" Hello %s\" }" , author )))
238240}
239241
240242const multipartMaxSize int64 = 1024 * 1024
@@ -261,7 +263,7 @@ func multipartFormHandler(w http.ResponseWriter, r *http.Request) {
261263 w .WriteHeader (http .StatusInternalServerError )
262264 return
263265 }
264- err = os .WriteFile ("/tmp/gadat1.png" , buf , 0644 )
266+ err = os .WriteFile ("/tmp/gadat1.png" , buf , 0600 )
265267 if err != nil {
266268 fmt .Printf ("error while writing file: %v\n " , err )
267269 w .WriteHeader (http .StatusInternalServerError )
@@ -275,7 +277,7 @@ func multipartFormHandler(w http.ResponseWriter, r *http.Request) {
275277 w .Header ().Add ("Set-Cookie" , "othercookie789=cval1;secure" )
276278 w .Header ().Add ("Set-Cookie" , "othercookie=cval2;secure" )
277279 w .WriteHeader (http .StatusOK )
278- w .Write ([]byte (fmt .Sprintf ("{\" message\" : \" Hello %s\" }" , author )))
280+ _ , _ = w .Write ([]byte (fmt .Sprintf ("{\" message\" : \" Hello %s\" }" , author )))
279281}
280282
281283func outgoingCallHandler (w http.ResponseWriter , r * http.Request ) {
@@ -330,7 +332,7 @@ func echoUpperCaseHandler(w http.ResponseWriter, r *http.Request) {
330332
331333 w .Header ().Set ("Content-Type" , "application/json" )
332334 w .WriteHeader (http .StatusOK )
333- w .Write ([]byte (strings .ToUpper (string (sBody ))))
335+ _ , _ = w .Write ([]byte (strings .ToUpper (string (sBody ))))
334336}
335337
336338func echoHandler (w http.ResponseWriter , r * http.Request ) {
@@ -350,7 +352,7 @@ func echoHandler(w http.ResponseWriter, r *http.Request) {
350352 }
351353 w .Header ().Set ("Access-Control-Allow-Credentials" , "true" )
352354 w .WriteHeader (http .StatusOK )
353- w .Write ([]byte (string (sBody )))
355+ _ , _ = w .Write ([]byte (string (sBody )))
354356}
355357
356358func getXmlHandler (w http.ResponseWriter , r * http.Request ) {
@@ -372,5 +374,5 @@ func getXmlHandler(w http.ResponseWriter, r *http.Request) {
372374
373375 w .Header ().Set ("Content-Type" , "application/xml" )
374376 w .WriteHeader (http .StatusOK )
375- w .Write ([]byte (xmlSampleBody ))
377+ _ , _ = w .Write ([]byte (xmlSampleBody ))
376378}
0 commit comments