Commit Graph
1323 Commits
Author SHA1 Message Date
Cosmin Cojocar f8691bd77b fix(sarif): avoid invalid null relationships in SARIF output (#1569)
* fix(sarif): avoid null relationships for rules without CWE

* test(sarif): add offline schema validation and self-scan coverage

* test(sarif): fix lint in self-scan helper
2026-03-01 10:08:47 +01:00
Cosmin Cojocar ade1d0e0a0 chore: migrate gosec container image references to GHCR (#1567) 2026-02-28 18:57:44 +01:00
Cosmin Cojocar 88835e86bb Update gorelease to use the latest cosign bundle argument (#1565)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
v2.24.6
2026-02-28 14:46:12 +01:00
Cosmin Cojocar 4b8cc9aa1f Migrate goreleaser to use the proper cosign arguments (#1564)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
v2.24.5
2026-02-28 14:19:42 +01:00
Cosmin Cojocar 22485d54dd Update the cosing to version v3.0.5 (#1563)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
v2.24.4
2026-02-28 13:54:19 +01:00
Cosmin Cojocar 46e53da622 fix(release): use existing cosign-installer action version (#1562) v2.24.3 v2.24.2 2026-02-28 13:48:20 +01:00
Cosmin Cojocar a7ab382a89 chore(prompts): add skill and prompt to update supported Go versions (#1561)
* chore(prompts): add supported Go version update skill and prompt

* docs: add usage for supported Go version update prompt
v2.24.1
2026-02-28 11:00:42 +01:00
Cosmin Cojocar 84df6fadcb chore(prompts): add action version update skill and prompt (#1560) 2026-02-28 10:50:17 +01:00
Cosmin Cojocar 7210bac169 fix(analyzers): avoid SSA dependency cycle blowups in issue #1555 paths (#1559)
Route redirect dependency checks through the cycle-safe
dependencyChecker instead of raw recursive valueDependsOn traversal.
This ensures Phi-cycle graphs terminate quickly and avoids recursive
work amplification that can look like hangs on large/generated
codebases.

Also remove the nil fallback in dependencyChecker.dependsOn so all
analyzer paths consistently use cycle-aware logic.

Add regression tests covering raw valueDependsOn behavior on:

Phi cycle without target (must return false)
Phi cycle with target path (must return true)
Self-referential Phi node (must return false)

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-28 10:47:40 +01:00
Cosmin Cojocar 34fe69430b Add a SKILL and PROMPT for fixing a GitHub issue (#1558)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-28 10:08:44 +01:00
Cosmin Cojocar 50c43450f7 Add a SKILL and PROMPT for generating rules with AI (#1557)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-28 09:47:19 +01:00
Cosmin Cojocar 9e5b3e2e5a fix(G120): prevent hang-like analysis blowup in wrapper protection checks (#1556)
Summary:
This change fixes the hang/perceived hang reported in issue #1555 when
scanning large codebases with complex SSA graphs. The fix is
intentionally scoped to G120 form parsing analysis only.

Root cause:
G120 wrapper/middleware protection logic repeatedly called
value-dependency checks across many function/call combinations. The
dependency traversal was depth-limited but not memoized, so cyclic and
branch-heavy SSA structures (especially Phi-related paths) caused
repeated re-traversal of the same graph regions and severe runtime
blowup.

What changed:
A cycle-safe, memoized dependency checker was added and used only inside
the G120 form parsing analysis flow. Existing G120 logic was kept
semantically equivalent while replacing repeated raw dependency
traversals with cached checks. Focused regression tests were added for
cyclic Phi graphs to verify both cases: no target reachable (false) and
target reachable (true), including stable repeated evaluation.

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-28 09:46:52 +01:00
Leon Löchner e7eb24d806 fix(G705): eliminate false positive when guard type cannot be resolved (#1554)
* fix(G705): eliminate false positive when guard type cannot be resolved

A guard cannot be satisfied when its type cannot be resolved.
Otherwise gosec fires for code like:
```go
package main

import (
	"fmt"
	"os"
)

func main() {
	fmt.Fprint(os.Stdout, os.Args[1])
}
```
In this case the guard type `http.ResponseWriter` cannot be resolved, all guards (1)
are satisfied and we have a false gosec warning.

Signed-off-by: leonnicolas <leonloechner@gmx.de>

* remove the http package from example

---------

Signed-off-by: leonnicolas <leonloechner@gmx.de>
2026-02-28 09:04:39 +01:00
Cosmin Cojocar c8a396c0b0 Remove gcmurphy from funding list 2026-02-27 13:51:01 +01:00
Cosmin Cojocar 14d95fe39e Extend the release workflow to push the container images also to GHCR
The relese process is extended to push also images to GHCR in addition
to DockerHub. This is in preparation to migrate to GHCR after the next
release.

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-27 13:48:41 +01:00
Cosmin Cojocar fd697486c0 Update to gosec to v2.24.0 in the action and fix the docker image signing (#1552)
Update the GitHub action to use gosec v2.24.0 and fix the docker image
signing

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-27 13:25:22 +01:00
Ravi Sastry Kadali 271492bcd9 fix: G704 false positive on const URL (#1551) v2.24.0 2026-02-27 11:51:08 +01:00
Ravi Sastry Kadali 1341aeadb4 fix(G705): eliminate false positive for non-HTTP io.Writer (#1550)
* fix(G705): eliminate false positive for non-HTTP io.Writer

Adds ArgTypeGuards map[int]string to taint.Sink. The XSS analyzer now
requires arg[0] of fmt.Fprint* to implement net/http.ResponseWriter.
Writing exec pipe output to os.Stdout no longer triggers G705.

Fixes: #1548

* improve code coverage
2026-02-27 08:01:14 +01:00
Cosmin Cojocar f2262c88ff G120: avoid false positive when MaxBytesReader is applied in middleware (#1547)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-25 15:51:24 +01:00
Cosmin Cojocar 5b580c76e4 Fix G602 regression coverage for issue #1545 and stabilize G117 TOML test dependency (#1546)
This PR adds regression coverage for the G602 false-positive reported in
issue #1545 by introducing two sample cases: one valid range-over-array
indexing pattern that should not trigger, and one true out-of-bounds
variant that should still be detected.

It also fixes test instability in the rules suite by adding the missing
BurntSushi TOML module metadata required by G117 sample compilation in
the test harness.

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-25 15:01:01 +01:00
Richard RigbyandClaude Opus 4.6 eba2d1582b taint: skip context.Context arguments during taint propagation to fix false positives (#1543)
* taint: skip `context.Context` args during taint propagation

`context.Context` is a control-flow mechanism (deadlines, cancellation,
request-scoped metadata) that does not carry user-controlled data
relevant to taint sinks. When `request.Context()` is passed to downstream
functions (gRPC clients, DB calls), the taint engine was conservatively
marking all return values as tainted, causing cascading false positives
for G703-G706 in any HTTP handler using the standard Go context pattern.

Add `isContextType()` helper and skip `context.Context-typed` arguments at
all four argument-scanning sites in the taint engine: interface method
calls, external static method calls, external plain function calls, and
`doTaintedArgsFlowToReturn` interprocedural analysis.

Receiver taint propagation (e.g., `req.URL.Query().Get()`) is unaffected.

ref: #1542

* taint: add tests for `isContextType` and context.Context false positive prevention

Add unit tests for the `isContextType` helper verifying it correctly
identifies context.Context and rejects non-context types (http.Request,
string, wrong package, pointer-wrapped, nil). Add G705 integration test
exercising the HTTP handler + r.Context() pattern that previously caused
false positives.

* fix(taint): handle pointer context types in isContextType

The isContextType function now properly unwraps pointer layers to
detect context.Context types even when wrapped in pointers
(e.g., *context.Context). This prevents false taint propagation
to function outputs from context arguments. Added comprehensive
test coverage for both direct context.Context and pointer
variants to ensure robust type checking.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:25 +01:00
Clara Bennett a6381c1e2f test: add missing rules to formatter report tests (#1540)
Adds G108, G114, G117, G306 to the formatter test coverage.
G116 and G307 excluded (no CWE entry in database).
2026-02-24 15:07:18 +01:00
renovate[bot] fea9725934 chore(deps): update all dependencies (#1541)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-02-24 14:24:16 +01:00
Cosmin Cojocar f3e2fac4d5 Regenrate the TLS config rule (#1539)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-21 13:53:22 +01:00
Cosmin Cojocar 200461fcf7 Improve documentation (#1538)
* Improve documentation

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

* More docs improvements

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

* Restructure DEVELOPMENT.md

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

* Improve structure of Development

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

---------

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-21 13:37:02 +01:00
Cosmin Cojocar 078a62afc3 Expand analyzer-core test coverage for orchestration, go/analysis adapter logic, and taint integration (#1537)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-21 12:35:16 +01:00
Cosmin Cojocar ffdc6205c8 Add unit tests for CLI orchestration, TLS config generation, and SSA cache behavior (#1536)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-21 12:10:19 +01:00
Cosmin Cojocar c13a48626b Add G707 taint analyzer for SMTP command/header injection (#1535)
This change introduces a new taint-analysis rule, G707, to detect
potential SMTP command/header injection when untrusted input reaches
net/smtp sink.

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-21 11:12:34 +01:00
Cosmin Cojocar f61ed314c2 Add G123 analyzer for tls.VerifyPeerCertificate resumption bypass risk (#1534)
Add a new SSA-based analyzer, G123, to detect risky TLS configurations
where VerifyPeerCertificate is set, VerifyConnection is not set, and
session resumption may still be enabled.

The analyzer inspects tls.Config field assignments and also follows
configurations returned from GetConfigForClient callbacks so
callback-based setup paths are covered as well.

This change wires G123 into analyzer registration, maps it to CWE-295,
updates the README rule list, and adds dedicated vulnerable/safe sample
coverage in analyzer tests.

It also includes a targeted #nosec G101 suppression on the analyzer
message string to prevent a known false positive from the linter
(message text only, no credential handling impact).

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-21 10:42:36 +01:00
Cosmin Cojocar b568aa1445 Add G122 SSA analyzer for filepath.Walk/WalkDir symlink TOCTOU race risks (#1532)
This change introduces a new SSA-based analyzer, G122, to detect unsafe
filesystem operations inside filepath.Walk, filepath.WalkDir, and
io/fs.WalkDir callbacks when callback path values flow into race-prone
sinks such as os.Remove, os.OpenFile, os.Rename, and os.Chmod.

It adds CWE mapping for the new rule as G122 -> CWE-367 (TOCTOU race
condition), and adds the CWE-367 definition to the CWE data.

It wires G122 into analyzer registration and updates the README
available rules list.

It adds dedicated G122 sample coverage with vulnerable and safe cases,
including safe root-scoped usage through os.Root APIs (for example
root.Open and root.Remove).

Validation was completed: full test suite passes, golangci-lint reports
zero issues, and gosec CLI validation confirms expected trigger and
non-trigger behavior for G122.

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-20 19:24:17 +01:00
Cosmin Cojocar 1735e5a9ac fix(G602): avoid false positives for range-over-array indexing (#1531)
This change fixes a false positive in G602 when iterating over
fixed-size arrays with range and indexing using the loop variable.

Corrects loop bound normalization in SSA-based index analysis so offsets
are not applied twice.
Preserves true-positive detection for real out-of-bounds patterns (for
example index + 1 at upper edge).
Adds regression samples covering both:
valid range-over-array indexing (no issue expected)
invalid shifted indexing inside the same loop (issue expected)

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-19 17:39:14 +01:00
Cosmin Cojocar caf93d07f1 Improve taint analyzer performance with shared SSA cache, parallel analyzer execution, and CI regression guard (#1530)
* Improve taint analyzer performance with shared SSA cache, parallel analyzer execution, and CI regression guard

* Added a shared per-package SSA analysis cache with lazy,
concurrency-safe call graph reuse across analyzers.
* Updated taint analyzers to consume the shared cache instead of
recomputing expensive artifacts per rule run.
* Parallelized analyzer execution at package level while preserving
deterministic issue aggregation.
* Added a package-level taint benchmark to measure real end-to-end taint
analyzer pass performance.
* Introduced a CI benchmark regression guard with configurable
thresholds for ns/op, B/op, and allocs/op.
* Documented the performance guard workflow, local run command, and
baseline update process in the README.

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

* Fix script

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

---------

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-19 16:50:41 +01:00
Ravi Sastry Kadali bd11fbe2ba fix: taint analysis false positives with G703,G705 (#1522)
* fix: taint analysis false positives with G703,G705

* additional tests

* cross package coverage increase

* Add additonal G118 tests for codecov

* improve code coverage

* field-level taint tracking and test coverage

* add more tests

* improve test coverage

* fix unnecessary nosec comments for tool

* improve code coverage

* address codecov issues

* improve code coverage
2026-02-19 15:43:03 +01:00
Cosmin Cojocar e34e8dd8e8 Extend the G117 rule to cover other types of serialization such as yaml/xml/toml (#1529)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-18 22:27:02 +01:00
Cosmin Cojocar b940702d5e Fix the G117 rule to take the JSON serialization into account (#1528)
* Fix g117 to take into account the json serialization

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

* Ignore lint warning

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

---------

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-18 21:50:17 +01:00
Cameron Steffen 4f84627380 (docs) fix justification format (#1524) 2026-02-18 16:38:29 +01:00
Cosmin Cojocar 36ba72bb7f Add G121 analyzer for unsafe CORS bypass patterns in CrossOriginProtection (#1521)
* Add G121 analyzer for unsafe CORS bypass patterns in CrossOriginProtection

Adds new SSA-only analyzer G121 to detect unsafe usage of
AddInsecureBypassPattern in net/http.CrossOriginProtection.
Flags:
overbroad static bypass patterns (for example /, /*, empty/wildcard-like
values),
request-derived dynamic bypass patterns.
Wires G121 into default analyzer registration, analyzer test suite, CWE
mapping (CWE-346), README rule list, and dedicated sample fixtures.
Includes a narrow lint suppression for a G101 false positive in analyzer
message constants.
Validation: analyzer tests pass and golangci-lint reports 0 issues.

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

* Ignore false positive warnings

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

---------

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-16 15:59:57 +01:00
Cosmin Cojocar 238f982325 Add G120 SSA analyzer for unbounded form parsing in HTTP handlers (#1520)
Introduces new G120 to detect potential memory-exhaustion paths caused
by unbounded form parsing in HTTP handlers.
Uses a pure SSA implementation (no AST fallback), checking ParseForm,
ParseMultipartForm, FormValue, and PostFormValue on *http.Request.
Suppresses findings when request bodies are explicitly bounded with
http.MaxBytesReader.
Wires G120 into analyzer registration, README rule catalog, and CWE
mapping (CWE-400).
Adds focused vulnerable/safe samples and analyzer test coverage;
analyzer tests and lint pass.

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-16 15:06:09 +01:00
Cosmin Cojocar 89cde277b5 Add G119 analyzer for unsafe redirect header propagation in CheckRedirect callbacks (#1519)
- Introduces a new G119 security rule to detect redirect policies that
can leak sensitive headers across origins.
- Flags direct request header replacement inside CheckRedirect callbacks
and explicit re-adding of sensitive headers (Authorization,
Proxy-Authorization, Cookie).
- Wires G119 into analyzer registration, README rule list, and CWE
mapping.
- Adds focused positive/negative samples and analyzer coverage; analyzer
package tests pass.

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-16 14:40:53 +01:00
oittaa 14fdd9cb07 Fix G115 false positives and negatives (Issue #1501) (#1518)
Fixes false positives for guarded conversions in loops by excluding back-edge dominators from reachability check. Fixes false negatives for array/slice element conversions by preventing recursive range resolution through IndexAddr. Also fixes isNonNegative check for range loops.
2026-02-16 13:58:21 +01:00
renovate[bot] cec54ec685 chore(deps): update all dependencies (#1517)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-02-16 13:56:41 +01:00
Cosmin Cojocar 2b2077e921 Add G118 SSA analyzer for context propagation failures that can cause goroutine/resource leaks (#1516)
* Add G118 SSA analyzer for context propagation failures that can cause goroutine/resource leaks

This PR introduces G118, a new SSA-based gosec rule that detects
high-risk context misuse patterns: goroutines using
context.Background/TODO when request context exists, missing cancel()
calls from WithCancel/WithTimeout/WithDeadline, and unbounded blocking
loop regions without ctx.Done() guards.
These patterns can leak goroutines and I/O resources, leading to
resource exhaustion/DoS in production services.
The rule is mapped to CWE-400, integrated into analyzer registration and
docs, and includes positive/negative samples (including complex loop CFG
cases) to reduce false positives while preserving detection quality.

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

* Fix false pasitive

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

---------

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-15 21:35:54 +01:00
Cosmin Cojocar a7666f3c70 Add G113: Detect HTTP Request Smuggling via conflicting headers (CVE-2025-22891, CWE-444) (#1515)
Implements a new SSA-based analyzer G113 to detect HTTP request
smuggling vulnerabilities caused by setting conflicting
Transfer-Encoding and Content-Length headers on the same HTTP response.

Addresses CVE-2025-22871 where ambiguous HTTP message parsing can lead
to request smuggling attacks. When both Transfer-Encoding: chunked and
Content-Length headers are set, intermediary proxies and backend servers
may disagree on message boundaries, allowing attackers to inject
malicious requests.

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-15 18:48:01 +01:00
Cosmin Cojocar 47f8b52fb8 Add G408: SSH PublicKeyCallback Authentication Bypass Analyzer (#1513)
* Add G408: SSH PublicKeyCallback Authentication Bypass Analyzer

Implements a new SSA-based security analyzer (G408) that detects
stateful misuse of ssh.PublicKeyCallback in SSH server configurations.
This vulnerability can lead to authentication bypass where a server
authenticates one SSH key but performs authorization checks on a
different key.

This addresses a critical security vulnerability (CVE-2024-45337, CVSS
9.1) that has affected production systems including Kubernetes and other
SSH-based services. The vulnerability occurs when developers incorrectly
capture and modify state within PublicKeyCallback closures, enabling
attackers to authenticate with one key while the server operates on
another key's credentials.

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

* Fix tests

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

---------

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-14 23:11:18 +01:00
Cosmin Cojocar 4f1f362671 Add more unit tests to improve coverage (#1512)
* Add more tests to improve test coverage

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

* Fix lint warnings

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

* fix lint warnings

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

* Fix lint warnings

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

* Fix lint warnings

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

* Fix lint warnings

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

---------

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-14 21:57:51 +01:00
Cosmin Cojocar 9344582ee4 Improve test coverage in various areas (#1511)
* Improve test coverage

Improve tests coverage in various areas.

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

* Fix lint warnings

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>

---------

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-14 16:48:39 +01:00
Cosmin Cojocar 8d1b2c63ae Imprve the test coverage (#1510)
Add more tests in areas which are not currently covered.

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-14 15:47:36 +01:00
Cosmin Cojocar 993c1c4da2 Fix incorrect detection of fixed iv in G407 (#1509)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-14 14:15:55 +01:00
Cosmin Cojocar 8668b74892 Add support for go 1.26.x and removed support for go 1.24.x (#1508)
We keep support only for two major version.

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-14 13:53:19 +01:00
Cosmin Cojocar 514225c8cb Fix the sonar report to follow the latest schema (#1507)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-02-14 12:59:24 +01:00