-
-
Notifications
You must be signed in to change notification settings - Fork 621
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect use of net/http functions that have no support for setting tim…
…eouts (#842) https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/ https://blog.cloudflare.com/exposing-go-on-the-internet/ Closes #833
- Loading branch information
Showing
5 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package rules | ||
|
||
import ( | ||
"go/ast" | ||
|
||
"github.com/securego/gosec/v2" | ||
) | ||
|
||
type httpServeWithoutTimeouts struct { | ||
gosec.MetaData | ||
pkg string | ||
calls []string | ||
} | ||
|
||
func (r *httpServeWithoutTimeouts) ID() string { | ||
return r.MetaData.ID | ||
} | ||
|
||
func (r *httpServeWithoutTimeouts) Match(n ast.Node, c *gosec.Context) (gi *gosec.Issue, err error) { | ||
if _, matches := gosec.MatchCallByPackage(n, c, r.pkg, r.calls...); matches { | ||
return gosec.NewIssue(c, n, r.ID(), r.What, r.Severity, r.Confidence), nil | ||
} | ||
return nil, nil | ||
} | ||
|
||
// NewHTTPServeWithoutTimeouts detects use of net/http serve functions that have no support for setting timeouts. | ||
func NewHTTPServeWithoutTimeouts(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { | ||
return &httpServeWithoutTimeouts{ | ||
pkg: "net/http", | ||
calls: []string{"ListenAndServe", "ListenAndServeTLS", "Serve", "ServeTLS"}, | ||
MetaData: gosec.MetaData{ | ||
ID: id, | ||
What: "Use of net/http serve function that has no support for setting timeouts", | ||
Severity: gosec.Medium, | ||
Confidence: gosec.High, | ||
}, | ||
}, []ast.Node{(*ast.CallExpr)(nil)} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters