Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: securego/gosec
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.22.2
Choose a base ref
...
head repository: securego/gosec
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.22.3
Choose a head ref
  • 8 commits
  • 17 files changed
  • 6 contributors

Commits on Mar 10, 2025

  1. chore(deps): update all dependencies (#1315)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 10, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    e5fee17 View commit details
  2. Add support for //gosec:disable directive (#1314)

    frozenbonito authored Mar 10, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    57ec633 View commit details
  3. Update the integrity sha for babel dependency in html report (#1316)

    Signed-off-by: Cosmin Cojocar <ccojocar@google.com>
    ccojocar authored Mar 10, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    9452efe View commit details

Commits on Mar 19, 2025

  1. chore(deps): update all dependencies (#1319)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 19, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    6141d10 View commit details
  2. Add SSOJet (#1320)

    GovindMalviya authored Mar 19, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    39e4477 View commit details

Commits on Mar 31, 2025

  1. chore(deps): update all dependencies (#1325)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 31, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    5fd2a37 View commit details

Commits on Apr 3, 2025

  1. remove G113. It only affects old/unsupported versions of Go (#1328)

    * don't warn on G113 (big.Rat SetString) if on an unaffected version of Go
    
    Newer versions of go (>=1.16.14, >=1.17.7, 1.18+) are not affected by this. Don't warn at all on those newer versions. See https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-23772
    
    * alert on all known versions
    
    Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
    
    * remove G113 CVE-2022-23772 which only affects old/unsupport Go versions
    
    * Retire rule
    
    * gofmt
    
    ---------
    
    Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
    niij and ccoVeille authored Apr 3, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    1336dc6 View commit details
  2. Update go version to 1.24.2 and 1.23.8 (#1331)

    ccojocar authored Apr 3, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    955a68d View commit details
Showing with 854 additions and 187 deletions.
  1. +2 −2 .github/workflows/ci.yml
  2. +1 −1 .github/workflows/release.yml
  3. +8 −2 README.md
  4. +1 −0 USERS.md
  5. +63 −37 analyzer.go
  6. +604 −2 analyzer_test.go
  7. +18 −18 go.mod
  8. +40 −40 go.sum
  9. +0 −1 issue/issue.go
  10. +34 −5 report/formatter_test.go
  11. +7 −7 report/html/template.html
  12. +0 −45 rules/math_big_rat.go
  13. +0 −1 rules/rulelist.go
  14. +0 −4 rules/rules_test.go
  15. +44 −0 testutils/g101_samples.go
  16. +32 −0 testutils/g112_samples.go
  17. +0 −22 testutils/g113_samples.go
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ jobs:
test:
strategy:
matrix:
version: [{go: '1.23.7', golangci: 'latest'}, {go: '1.24.1', golangci: 'latest'}]
version: [{go: '1.23.8', golangci: 'latest'}, {go: '1.24.2', golangci: 'latest'}]
runs-on: ubuntu-latest
env:
GO111MODULE: on
@@ -48,7 +48,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: '1.24.1'
go-version: '1.24.2'
- name: Checkout Source
uses: actions/checkout@v4
- uses: actions/cache@v4
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24.1'
go-version: '1.24.2'
- name: Install Cosign
uses: sigstore/cosign-installer@v3
with:
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -138,7 +138,6 @@ directory you can supply `./...` as the input argument.
- G110: Potential DoS vulnerability via decompression bomb
- G111: Potential directory traversal
- G112: Potential slowloris attack
- G113: Usage of Rat.SetString in math/big with an overflow (CVE-2022-23772)
- G114: Use of net/http serve function that has no support for setting timeouts
- G115: Potential integer overflow when converting between integer types
- G201: SQL query construction using format string
@@ -172,6 +171,7 @@ directory you can supply `./...` as the input argument.
### Retired rules

- G105: Audit the use of math/big.Int.Exp - [CVE is fixed](https://github.com/golang/go/issues/15184)
- G113: Usage of Rat.SetString in math/big with an overflow (CVE-2022-23772). This affected Go <1.16.14 and Go <1.17.7, which are no longer supported by gosec.
- G307: Deferring a method which returns an error - causing more inconvenience than fixing a security issue, despite the details from this [blog post](https://www.joeshaw.org/dont-defer-close-on-writable-files/)

### Selecting rules
@@ -304,7 +304,13 @@ You could put the description or justification text for the annotation. The
justification should be after the rule(s) to suppress and start with two or
more dashes, e.g: `//#nosec G101 G102 -- This is a false positive`

In some cases you may also want to revisit places where `#nosec` annotations
Alternatively, gosec also supports the `//gosec:disable` directive, which functions similar to `#nosec`:

```go
//gosec:disable G101 -- This is a false positive
```

In some cases you may also want to revisit places where `#nosec` or `//gosec:disable` annotations
have been used. To run the scanner and ignore any `#nosec` annotations you
can do the following:

1 change: 1 addition & 0 deletions USERS.md
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ This is a list of gosec's users. Please send a pull request with your organisati
10. [Checkmarx](https://www.checkmarx.com/)
11. [SeatGeek](https://www.seatgeek.com/)
12. [reMarkable](https://remarkable.com)
13. [SSOJet](https://ssojet.com)

## Projects

100 changes: 63 additions & 37 deletions analyzer.go
Original file line number Diff line number Diff line change
@@ -57,6 +57,8 @@ const externalSuppressionJustification = "Globally suppressed."

const aliasOfAllRules = "*"

var directiveRegexp = regexp.MustCompile("^//gosec:disable(?: (.+))?$")

type ignore struct {
start int
end int
@@ -582,53 +584,77 @@ func (gosec *Analyzer) ignore(n ast.Node) map[string]issue.SuppressionInfo {
}

for _, group := range groups {
comment := strings.TrimSpace(group.Text())
foundDefaultTag := strings.HasPrefix(comment, noSecDefaultTag) || regexp.MustCompile("\n *"+noSecDefaultTag).MatchString(comment)
foundAlternativeTag := strings.HasPrefix(comment, noSecAlternativeTag) || regexp.MustCompile("\n *"+noSecAlternativeTag).MatchString(comment)

if foundDefaultTag || foundAlternativeTag {
gosec.stats.NumNosec++

// Discard what's in front of the nosec tag.
if foundDefaultTag {
comment = strings.SplitN(comment, noSecDefaultTag, 2)[1]
} else {
comment = strings.SplitN(comment, noSecAlternativeTag, 2)[1]
}
found, args := findNoSecDirective(group, noSecDefaultTag, noSecAlternativeTag)
if !found {
continue
}

// Extract the directive and the justification.
justification := ""
commentParts := regexp.MustCompile(`-{2,}`).Split(comment, 2)
directive := commentParts[0]
if len(commentParts) > 1 {
justification = strings.TrimSpace(strings.TrimRight(commentParts[1], "\n"))
}
gosec.stats.NumNosec++

// Pull out the specific rules that are listed to be ignored.
re := regexp.MustCompile(`(G\d{3})`)
matches := re.FindAllStringSubmatch(directive, -1)
// Extract the directive and the justification.
justification := ""
commentParts := regexp.MustCompile(`-{2,}`).Split(args, 2)
directive := commentParts[0]
if len(commentParts) > 1 {
justification = strings.TrimSpace(strings.TrimRight(commentParts[1], "\n"))
}

suppression := issue.SuppressionInfo{
Kind: "inSource",
Justification: justification,
}
// Pull out the specific rules that are listed to be ignored.
re := regexp.MustCompile(`(G\d{3})`)
matches := re.FindAllStringSubmatch(directive, -1)

// Find the rule IDs to ignore.
ignores := make(map[string]issue.SuppressionInfo)
for _, v := range matches {
ignores[v[1]] = suppression
}
suppression := issue.SuppressionInfo{
Kind: "inSource",
Justification: justification,
}

// If no specific rules were given, ignore everything.
if len(matches) == 0 {
ignores[aliasOfAllRules] = suppression
}
return ignores
// Find the rule IDs to ignore.
ignores := make(map[string]issue.SuppressionInfo)
for _, v := range matches {
ignores[v[1]] = suppression
}

// If no specific rules were given, ignore everything.
if len(matches) == 0 {
ignores[aliasOfAllRules] = suppression
}
return ignores
}
return nil
}

// findNoSecDirective checks if the comment group contains `#nosec` or `//gosec:disable` directive.
// If found, it returns true and the directive's arguments.
func findNoSecDirective(group *ast.CommentGroup, noSecDefaultTag, noSecAlternativeTag string) (bool, string) {
// Check if the comment grounp has a nosec comment.
for _, tag := range []string{noSecDefaultTag, noSecAlternativeTag} {
if found, args := findNoSecTag(group, tag); found {
return true, args
}
}

// Check if the comment group has a directive comment.
for _, c := range group.List {
match := directiveRegexp.FindStringSubmatch(c.Text)
if len(match) > 0 {
return true, match[0]
}
}

return false, ""
}

func findNoSecTag(group *ast.CommentGroup, tag string) (bool, string) {
comment := strings.TrimSpace(group.Text())

if strings.HasPrefix(comment, tag) || regexp.MustCompile("\n *"+tag).MatchString(comment) {
// Discard what's in front of the nosec tag.
return true, strings.SplitN(comment, tag, 2)[1]
}

return false, ""
}

// Visit runs the gosec visitor logic over an AST created by parsing go code.
// Rule methods added with AddRule will be invoked as necessary.
func (gosec *Analyzer) Visit(n ast.Node) ast.Visitor {
Loading