mirror of
https://github.com/securego/gosec.git
synced 2026-01-15 01:33:41 +08:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e57efa8482 | ||
|
|
ff17c30a97 | ||
|
|
3eba7b8a3e | ||
|
|
55c6ceaaa6 | ||
|
|
40fa36d1de | ||
|
|
873ac243ea | ||
|
|
f1f0056a90 | ||
|
|
0680c75f99 | ||
|
|
79c8b79263 |
@@ -8,7 +8,7 @@ RUN go mod download
|
||||
RUN make build-linux
|
||||
|
||||
FROM golang:${GO_VERSION}-alpine
|
||||
RUN apk add --update --no-cache ca-certificates bash git gcc libc-dev
|
||||
RUN apk add --update --no-cache ca-certificates bash git gcc libc-dev openssh
|
||||
ENV GO111MODULE on
|
||||
COPY --from=builder /build/gosec /bin/gosec
|
||||
COPY entrypoint.sh /bin/entrypoint.sh
|
||||
|
||||
@@ -358,7 +358,7 @@ Then generate the types with :
|
||||
schema-generate -i sarif-schema-2.1.0.json -o mypath/types.go
|
||||
```
|
||||
|
||||
Most of the MarshallJSON/UnmarshalJSON are removed except the one for PropertyBag which is handy to inline the additionnal properties. The rest can be removed.
|
||||
Most of the MarshallJSON/UnmarshalJSON are removed except the one for PropertyBag which is handy to inline the additional properties. The rest can be removed.
|
||||
The URI,ID, UUID, GUID were renamed so it fits the Golang convention defined [here](https://github.com/golang/lint/blob/master/lint.go#L700)
|
||||
|
||||
### Tests
|
||||
|
||||
@@ -113,7 +113,7 @@ func NewAnalyzer(conf Config, tests bool, excludeGenerated bool, logger *log.Log
|
||||
}
|
||||
}
|
||||
|
||||
// SetConfig upates the analyzer configuration
|
||||
// SetConfig updates the analyzer configuration
|
||||
func (gosec *Analyzer) SetConfig(conf Config) {
|
||||
gosec.config = conf
|
||||
}
|
||||
|
||||
@@ -247,9 +247,9 @@ func saveReport(filename, format string, rootPaths []string, reportInfo *gosec.R
|
||||
return nil
|
||||
}
|
||||
|
||||
func convertToScore(severity string) (gosec.Score, error) {
|
||||
severity = strings.ToLower(severity)
|
||||
switch severity {
|
||||
func convertToScore(value string) (gosec.Score, error) {
|
||||
value = strings.ToLower(value)
|
||||
switch value {
|
||||
case "low":
|
||||
return gosec.Low, nil
|
||||
case "medium":
|
||||
@@ -257,7 +257,7 @@ func convertToScore(severity string) (gosec.Score, error) {
|
||||
case "high":
|
||||
return gosec.High, nil
|
||||
default:
|
||||
return gosec.Low, fmt.Errorf("provided severity '%s' not valid. Valid options: low, medium, high", severity)
|
||||
return gosec.Low, fmt.Errorf("provided value '%s' not valid. Valid options: low, medium, high", value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ func firstIsGreater(less, greater *gosec.Issue) {
|
||||
}
|
||||
|
||||
var _ = Describe("Sorting by Severity", func() {
|
||||
It("sortes by severity", func() {
|
||||
It("sorts by severity", func() {
|
||||
less := createIssue()
|
||||
less.Severity = gosec.Low
|
||||
greater := createIssue()
|
||||
@@ -46,8 +46,8 @@ var _ = Describe("Sorting by Severity", func() {
|
||||
firstIsGreater(&less, &greater)
|
||||
})
|
||||
|
||||
Context("Serverity is same", func() {
|
||||
It("sortes by What", func() {
|
||||
Context("Severity is same", func() {
|
||||
It("sorts by What", func() {
|
||||
less := createIssue()
|
||||
less.What = "test1"
|
||||
greater := createIssue()
|
||||
@@ -56,8 +56,8 @@ var _ = Describe("Sorting by Severity", func() {
|
||||
})
|
||||
})
|
||||
|
||||
Context("Serverity and What is same", func() {
|
||||
It("sortes by File", func() {
|
||||
Context("Severity and What is same", func() {
|
||||
It("sorts by File", func() {
|
||||
less := createIssue()
|
||||
less.File = "test1"
|
||||
greater := createIssue()
|
||||
@@ -67,8 +67,8 @@ var _ = Describe("Sorting by Severity", func() {
|
||||
})
|
||||
})
|
||||
|
||||
Context("Serverity, What and File is same", func() {
|
||||
It("sortes by line number", func() {
|
||||
Context("Severity, What and File is same", func() {
|
||||
It("sorts by line number", func() {
|
||||
less := createIssue()
|
||||
less.Line = "1"
|
||||
greater := createIssue()
|
||||
|
||||
@@ -20,7 +20,7 @@ func NewError(line, column int, err string) *Error {
|
||||
}
|
||||
}
|
||||
|
||||
// sortErros sorts the golang erros by line
|
||||
// sortErrors sorts the golang errors by line
|
||||
func sortErrors(allErrors map[string][]Error) {
|
||||
for _, errors := range allErrors {
|
||||
sort.Slice(errors, func(i, j int) bool {
|
||||
|
||||
8
go.mod
8
go.mod
@@ -2,12 +2,12 @@ module github.com/securego/gosec/v2
|
||||
|
||||
require (
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/gookit/color v1.4.2
|
||||
github.com/lib/pq v1.10.3
|
||||
github.com/gookit/color v1.5.0
|
||||
github.com/lib/pq v1.10.4
|
||||
github.com/mozilla/tls-observatory v0.0.0-20210609171429-7bc42856d2e5
|
||||
github.com/nbutton23/zxcvbn-go v0.0.0-20210217022336-fa2cb2858354
|
||||
github.com/onsi/ginkgo v1.16.4
|
||||
github.com/onsi/gomega v1.16.0
|
||||
github.com/onsi/ginkgo v1.16.5
|
||||
github.com/onsi/gomega v1.17.0
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
|
||||
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
|
||||
golang.org/x/text v0.3.7
|
||||
|
||||
18
go.sum
18
go.sum
@@ -166,8 +166,8 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||
github.com/gookit/color v1.4.2 h1:tXy44JFSFkKnELV6WaMo/lLfu/meqITX3iAV52do7lk=
|
||||
github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ=
|
||||
github.com/gookit/color v1.5.0 h1:1Opow3+BWDwqor78DcJkJCIwnkviFi+rrOANki9BUFw=
|
||||
github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo=
|
||||
github.com/gordonklaus/ineffassign v0.0.0-20200309095847-7953dde2c7bf/go.mod h1:cuNKsD1zp2v6XfE/orVX2QE1LC+i254ceGcVeDT3pTU=
|
||||
github.com/gorhill/cronexpr v0.0.0-20180427100037-88b0669f7d75/go.mod h1:g2644b03hfBX9Ov0ZBDgXXens4rxSxmqFBbhvKv2yVA=
|
||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||
@@ -219,8 +219,8 @@ github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+
|
||||
github.com/letsencrypt/pkcs11key/v4 v4.0.0/go.mod h1:EFUvBDay26dErnNb70Nd0/VW3tJiIbETBPTl9ATXQag=
|
||||
github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/lib/pq v1.10.3 h1:v9QZf2Sn6AmjXtQeFpdoq/eaNtYP6IN+7lcrygsIAtg=
|
||||
github.com/lib/pq v1.10.3/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk=
|
||||
github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
@@ -264,12 +264,13 @@ github.com/olekukonko/tablewriter v0.0.2/go.mod h1:rSAaSIOAGT9odnlyGlUfAJaoc5w2f
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
|
||||
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
|
||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
|
||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c=
|
||||
github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
|
||||
github.com/onsi/gomega v1.17.0 h1:9Luw4uT5HTjHTN8+aNcSThgH1vdXnmdJ8xIfZ4wyTRE=
|
||||
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
|
||||
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
|
||||
@@ -322,8 +323,9 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20200427203606-3cfed13b9966/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
|
||||
@@ -1,20 +1,3 @@
|
||||
// (c) Copyright 2016 Hewlett Packard Enterprise Development LP
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package html
|
||||
|
||||
const templateContent = `
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
@@ -454,4 +437,4 @@ const templateContent = `
|
||||
);
|
||||
</script>
|
||||
</body>
|
||||
</html>`
|
||||
</html>
|
||||
@@ -1,12 +1,18 @@
|
||||
package html
|
||||
|
||||
import (
|
||||
|
||||
// use go embed to import template
|
||||
_ "embed"
|
||||
"html/template"
|
||||
"io"
|
||||
|
||||
"github.com/securego/gosec/v2"
|
||||
)
|
||||
|
||||
//go:embed template.html
|
||||
var templateContent string
|
||||
|
||||
// WriteReport write a report in html format to the output writer
|
||||
func WriteReport(w io.Writer, data *gosec.ReportInfo) error {
|
||||
t, e := template.New("gosec").Parse(templateContent)
|
||||
|
||||
@@ -269,7 +269,7 @@ type ExternalProperties struct {
|
||||
// An array of graph objects that will be merged with a separate run.
|
||||
Graphs []*Graph `json:"graphs,omitempty"`
|
||||
|
||||
// A stable, unique identifer for this external properties object, in the form of a GUID.
|
||||
// A stable, unique identifier for this external properties object, in the form of a GUID.
|
||||
GUID string `json:"guid,omitempty"`
|
||||
|
||||
// Describes the invocation of the analysis tool that will be merged with a separate run.
|
||||
@@ -287,7 +287,7 @@ type ExternalProperties struct {
|
||||
// An array of result objects that will be merged with a separate run.
|
||||
Results []*Result `json:"results,omitempty"`
|
||||
|
||||
// A stable, unique identifer for the run associated with this external properties object, in the form of a GUID.
|
||||
// A stable, unique identifier for the run associated with this external properties object, in the form of a GUID.
|
||||
RunGUID string `json:"runGuid,omitempty"`
|
||||
|
||||
// The URI of the JSON schema corresponding to the version of the external property file format.
|
||||
@@ -315,7 +315,7 @@ type ExternalProperties struct {
|
||||
// ExternalPropertyFileReference Contains information that enables a SARIF consumer to locate the external property file that contains the value of an externalized property associated with the run.
|
||||
type ExternalPropertyFileReference struct {
|
||||
|
||||
// A stable, unique identifer for the external property file in the form of a GUID.
|
||||
// A stable, unique identifier for the external property file in the form of a GUID.
|
||||
GUID string `json:"guid,omitempty"`
|
||||
|
||||
// A non-negative integer specifying the number of items contained in the external property file.
|
||||
@@ -801,7 +801,7 @@ type ReportingDescriptor struct {
|
||||
// A description of the report. Should, as far as possible, provide details sufficient to enable resolution of any problem indicated by the result.
|
||||
FullDescription *MultiformatMessageString `json:"fullDescription,omitempty"`
|
||||
|
||||
// A unique identifer for the reporting descriptor in the form of a GUID.
|
||||
// A unique identifier for the reporting descriptor in the form of a GUID.
|
||||
GUID string `json:"guid,omitempty"`
|
||||
|
||||
// Provides the primary documentation for the report, useful when there is no online documentation.
|
||||
@@ -894,7 +894,7 @@ type Result struct {
|
||||
// An array of zero or more unique graph objects associated with the result.
|
||||
Graphs []*Graph `json:"graphs,omitempty"`
|
||||
|
||||
// A stable, unique identifer for the result in the form of a GUID.
|
||||
// A stable, unique identifier for the result in the form of a GUID.
|
||||
GUID string `json:"guid,omitempty"`
|
||||
|
||||
// An absolute URI at which the result can be viewed.
|
||||
@@ -1080,7 +1080,7 @@ type RunAutomationDetails struct {
|
||||
// A description of the identity and role played within the engineering system by this object's containing run object.
|
||||
Description *Message `json:"description,omitempty"`
|
||||
|
||||
// A stable, unique identifer for this object's containing run object in the form of a GUID.
|
||||
// A stable, unique identifier for this object's containing run object in the form of a GUID.
|
||||
GUID string `json:"guid,omitempty"`
|
||||
|
||||
// A hierarchical string that uniquely identifies this object's containing run object.
|
||||
@@ -1154,7 +1154,7 @@ type Report struct {
|
||||
// Suppression A suppression that is relevant to a result.
|
||||
type Suppression struct {
|
||||
|
||||
// A stable, unique identifer for the suprression in the form of a GUID.
|
||||
// A stable, unique identifier for the suprression in the form of a GUID.
|
||||
GUID string `json:"guid,omitempty"`
|
||||
|
||||
// A string representing the justification for the suppression.
|
||||
@@ -1278,7 +1278,7 @@ type ToolComponent struct {
|
||||
// A dictionary, each of whose keys is a resource identifier and each of whose values is a multiformatMessageString object, which holds message strings in plain text and (optionally) Markdown format. The strings can include placeholders, which can be used to construct a message in combination with an arbitrary number of additional string arguments.
|
||||
GlobalMessageStrings map[string]*MultiformatMessageString `json:"globalMessageStrings,omitempty"`
|
||||
|
||||
// A unique identifer for the tool component in the form of a GUID.
|
||||
// A unique identifier for the tool component in the form of a GUID.
|
||||
GUID string `json:"guid,omitempty"`
|
||||
|
||||
// The absolute URI at which information about this version of the tool component can be found.
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
package text
|
||||
|
||||
const templateContent = `Results:
|
||||
Results:
|
||||
{{range $filePath,$fileErrors := .Errors}}
|
||||
Golang errors in file: [{{ $filePath }}]:
|
||||
{{range $index, $error := $fileErrors}}
|
||||
@@ -23,4 +21,3 @@ Golang errors in file: [{{ $filePath }}]:
|
||||
{{- danger .Stats.NumFound }}
|
||||
{{- end }}
|
||||
|
||||
`
|
||||
@@ -3,6 +3,9 @@ package text
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
|
||||
// use go embed to import template
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
@@ -17,6 +20,9 @@ var (
|
||||
errorTheme = color.New(color.FgLightWhite, color.BgRed)
|
||||
warningTheme = color.New(color.FgBlack, color.BgYellow)
|
||||
defaultTheme = color.New(color.FgWhite, color.BgBlack)
|
||||
|
||||
//go:embed template.txt
|
||||
templateContent string
|
||||
)
|
||||
|
||||
// WriteReport write a (colorized) report in text format
|
||||
|
||||
@@ -55,6 +55,10 @@ func (r *subprocess) Match(n ast.Node, c *gosec.Context) (*gosec.Issue, error) {
|
||||
// .. indeed it is a variable then processing is different than a normal
|
||||
// field assignment
|
||||
if variable {
|
||||
// skip the check when the declaration is not available
|
||||
if ident.Obj == nil {
|
||||
continue
|
||||
}
|
||||
switch ident.Obj.Decl.(type) {
|
||||
case *ast.AssignStmt:
|
||||
_, assignment := ident.Obj.Decl.(*ast.AssignStmt)
|
||||
|
||||
@@ -44,7 +44,7 @@ func (t *badTempFile) Match(n ast.Node, c *gosec.Context) (gi *gosec.Issue, err
|
||||
func NewBadTempFile(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
|
||||
calls := gosec.NewCallList()
|
||||
calls.Add("io/ioutil", "WriteFile")
|
||||
calls.Add("os", "Create")
|
||||
calls.AddAll("os", "Create", "WriteFile")
|
||||
return &badTempFile{
|
||||
calls: calls,
|
||||
args: regexp.MustCompile(`^/tmp/.*$|^/var/tmp/.*$`),
|
||||
|
||||
@@ -88,7 +88,7 @@ func (t *insecureConfigTLS) processTLSConfVal(n *ast.KeyValueExpr, c *gosec.Cont
|
||||
|
||||
case "MinVersion":
|
||||
if d, ok := n.Value.(*ast.Ident); ok {
|
||||
if vs, ok := d.Obj.Decl.(*ast.ValueSpec); ok {
|
||||
if vs, ok := d.Obj.Decl.(*ast.ValueSpec); ok && len(vs.Values) > 0 {
|
||||
if s, ok := vs.Values[0].(*ast.SelectorExpr); ok {
|
||||
x := s.X.(*ast.Ident).Name
|
||||
sel := s.Sel.Name
|
||||
|
||||
@@ -1757,6 +1757,7 @@ package samples
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -1764,7 +1765,17 @@ func main() {
|
||||
if err != nil {
|
||||
fmt.Println("Error while writing!")
|
||||
}
|
||||
}`}, 1, gosec.NewConfig()}}
|
||||
f, err := os.Create("/tmp/demo2")
|
||||
if err != nil {
|
||||
fmt.Println("Error while writing!")
|
||||
} else if err = f.Close(); err != nil {
|
||||
fmt.Println("Error while closing!")
|
||||
}
|
||||
err = os.WriteFile("/tmp/demo2", []byte("This is some data"), 0644)
|
||||
if err != nil {
|
||||
fmt.Println("Error while writing!")
|
||||
}
|
||||
}`}, 3, gosec.NewConfig()}}
|
||||
|
||||
// SampleCodeG304 - potential file inclusion vulnerability
|
||||
SampleCodeG304 = []CodeSample{{[]string{`
|
||||
|
||||
Reference in New Issue
Block a user