100 Commits
Author SHA1 Message Date
Cosmin Cojocar 9addc97cef Update to go version 1.26.4 and 1.25.11 (#1690)
Signed-off-by: Cosmin Cojocar <ccojocar@google.com>
2026-06-03 17:48:52 +02:00
Cosmin Cojocar 92ed8df328 Update the gosec in the Github action to v2.27.1 (#1688)
Signed-off-by: Cosmin Cojocar <ccojocar@google.com>
2026-06-01 20:53:11 +02:00
Cosmin Cojocar 0a5c6504c4 Downgrade the jsonschema dep to v0.13.0 due to incompatibility with anthropick-sdk-go (#1686)
Signed-off-by: Cosmin Cojocar <ccojocar@google.com>
2026-06-01 10:12:49 +02:00
Cosmin Cojocar bd17b2589e Downgrade the github.com/invopop/jsonschema v0.13.0 to solve incopatibility with anthropic-sdk (#1683)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-05-26 21:48:51 +02:00
Cosmin Cojocar 5676cbccda Update vulnerabilities alerts for indirect dependencies
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-05-26 20:31:35 +02:00
Cosmin Cojocar 74b726dfce Skip pining for my repos
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-05-26 20:15:02 +02:00
Cosmin Cojocar a68f8825bf Update renovate configuration
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-05-26 19:56:47 +02:00
Cosmin Cojocar 85814f2e39 Update renovate config to pin the actions dependencies by digests (#1676)
Signed-off-by: Cosmin Cojocar <ccojocar@google.com>
2026-05-26 18:51:53 +02:00
Cosmin Cojocar 55f0519732 Migrate the html remport to react v19. (#1675)
Signed-off-by: Cosmin Cojocar <ccojocar@google.com>
2026-05-26 18:33:30 +02:00
Cosmin Cojocar 6ad4476d26 Manually update version to fix renovate (#1674)
Signed-off-by: Cosmin Cojocar <ccojocar@google.com>
2026-05-26 18:07:55 +02:00
Cosmin Cojocar de65614d10 Add two options to require rule ID and justificaiton for inline annotations (#1671)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-05-11 22:06:17 +02:00
Cosmin Cojocar e354c572d9 Fix false positive in G118 when cancel is stored in a slice/map (#1670)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-05-11 21:00:26 +02:00
Cosmin CojocarandClaude Opus 4.7 4161f0b433 chore(go): update supported Go versions to 1.25.10 and 1.26.3 (#1669)
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-11 20:29:31 +02:00
Cosmin Cojocar b4f2934756 Harden the github workflows and action (#1665)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-05-04 20:10:35 +02:00
Cosmin Cojocar 5f4eec95fa Update action to use gosec version v2.26.1 (#1660)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-04-28 09:32:42 +02:00
Cosmin Cojocar 4a3bd8af17 Update cosign to v3.0.6 (#1659)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-04-28 08:44:21 +02:00
Cosmin Cojocar 8ff985fe09 Fix formatting
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-04-25 11:31:48 +02:00
Cosmin Cojocar a1aad0cd00 Update the default models use by autofix and phase out the older models
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-04-25 11:31:48 +02:00
Cosmin Cojocar 74bdf7f880 Format and clean-up the README
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-04-25 11:31:48 +02:00
Cosmin Cojocar 74dc9893d6 Add HTTP file-serving function to the skins of pathtraversal analyzer (#1647)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-04-25 10:37:00 +02:00
Cosmin Cojocar 70201119fe Skip flaging the TLS min version for go 1.18+ (#1646)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-04-25 10:06:56 +02:00
Cosmin Cojocar 24ee992e95 Added filepath.Abs as a sanitizer (#1643)
it calls Clean internally per Go docs.

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-04-23 15:25:57 +02:00
Cosmin Cojocar 87bdc09bee Allow rune to byte conversion (#1642)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-04-23 09:21:59 +02:00
Cosmin Cojocar 73293bde6b Allow platform specific conversions (#1641)
Allow platform conversion such as uintptr -> int since are a common
pattern and they are safe.

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-04-23 08:43:29 +02:00
Cosmin CojocarandClaude Opus 4.6 2687376596 chore(go): update supported Go versions to 1.25.9 and 1.26.2 (#1633)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 17:44:55 +02:00
Cosmin Cojocar 1af5d582f8 Added a visited cycle-detection guard in the *ssa.Phi case (#1626)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-03-30 19:18:16 +02:00
Cosmin Cojocar 8d05295c5a Gate the AI security review by the security-review environment (#1621)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-03-23 09:50:30 +01:00
Cosmin Cojocar 3e99c47487 Fix anthropic autofix after dependencies update (#1620)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-03-23 09:32:55 +01:00
Cosmin CojocarandClaude Sonnet 4.6 6d41a7978e chore(action): bump gosec to 2.25.0 (#1618)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-19 11:53:03 +01:00
Cosmin CojocarandClaude Opus 4.6 b23a9e5348 fix: allow barry action to access secrets on fork PRs (#1616)
Use pull_request_target event so the GOOGLE_API_KEY secret is available
when PRs come from forks. Checkout the PR head SHA explicitly since
pull_request_target defaults to the base branch. Guard other jobs to
skip on pull_request_target to avoid duplicate runs.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 09:08:42 +01:00
Cosmin CojocarandClaude Opus 4.6 355cfa5a43 fix: reduce G117 false positives for custom marshalers and transformed values (#1614) (#1615)
G117 now skips findings when:
- The marshal call is inside a custom marshaler method (MarshalJSON, MarshalYAML, etc.)
- The type being marshaled implements a custom marshaler interface
- A composite literal wraps the sensitive field value in a function call (e.g. mask())

Also fixes the issue message to show the correct format name (JSON/YAML/XML/TOML)
instead of always saying "JSON key".

Closes #1614

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 08:56:12 +01:00
Cosmin Cojocar 744bfb5ef0 Add barry security scanner as a step in the CI (#1612)
* Add barry security scanner as a step in the CI

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

* Enable SARIF upload to GitHub security center

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

* Switch to gemini-3-flash for validation and autofix

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

* Use the correct model name

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

* Fix the SARIF upload

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

* Update the output directory of the barry scan

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

* Fix the output and the permissions to comment on pull request

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

---------

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-03-16 12:05:58 +01:00
Cosmin CojocarandClaude Opus 4.6 dec52c4101 fix: prevent taint analysis hang on packages with many CHA call graph edges (#1608) (#1610)
Cap incoming call graph edges to 32 per function and add cross-query
parameter taint memoization to prevent combinatorial explosion when CHA
over-approximates interface method calls across transitive dependencies.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-15 12:40:15 +01:00
Cosmin Cojocar a0de8b6aab Add some skills for claude code to automate some tasks (#1609)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-03-15 11:57:48 +01:00
Cosmin Cojocar 8aec3f48a2 fix: skip SSA analysis on ill-typed packages to prevent panic (#1607)
Packages with type errors (pkg.IllTyped == true) have partial type
information that can cause nil pointer dereferences inside the SSA
builder (golang.org/x/tools/go/ssa.emitConv).

Add a pkg.IllTyped guard in buildSSA that returns a clean error
instead of letting the SSA builder panic. AST-based rules continue
to run normally on the affected package.

Fixes #1604
2026-03-13 12:24:16 +01:00
Cosmin Cojocar 1ced32df14 Port G120 from SSA-based to taint analysis (fixes #1600, #1603) (#1605)
* Port G120 from SSA-based to taint analysis

Fix #1600: G120 now detects ParseMultipartForm across function boundaries
using the taint engine's interprocedural call graph analysis.

Fix #1603: Remove ParseForm, FormValue, and PostFormValue from G120 sinks.
These methods already enforce a built-in 10 MiB body limit in Go's
standard library, so flagging them was a false positive. Only
ParseMultipartForm (genuinely unbounded without MaxBytesReader) is now
flagged.

Changes:
- Replace the 521-line custom SSA analyzer in form_parsing_limits.go with
  a ~55-line taint analysis configuration.
- Extract the shared dependencyChecker (used by G119, G121, G122) into
  its own file dependency_checker.go.
- Add FormParsingLimitRule (CWE-400) to the taint rule registry.
- Rewrite test samples to cover the new behavior including interprocedural
  detection and the built-in limit exclusions.

* Update the RULES.md to be consistent with the implementation

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

---------

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-03-13 12:01:02 +01:00
Cosmin Cojocar b7b2c7b668 feat: add G124 rule for insecure HTTP cookie configuration (#1599)
Add SSA-based analyzer G124 to detect http.Cookie allocations missing
secure attributes: Secure, HttpOnly, or SameSite.

CWE-614. Includes 5 test samples (3 positive, 2 negative).
2026-03-11 14:32:15 +01:00
Cosmin Cojocar 6e66a943db feat: add G709 rule for unsafe deserialization of untrusted data (#1598)
Add taint analysis rule G709 to detect unsafe deserialization when
untrusted input flows into encoding/gob, encoding/xml, or
gopkg.in/yaml.v2 deserialization functions.

CWE-502. Includes 5 test samples (3 positive, 2 negative).
2026-03-11 12:31:10 +01:00
Cosmin Cojocar e7ea2377aa feat: add G708 rule for server-side template injection via text/template (#1597)
Add taint analysis rule G708 to detect SSTI vulnerabilities when using
Go text/template package. Covers two attack vectors:
- User input flowing into Template.Parse() (SSTI/RCE)
- Tainted data passed to Execute/ExecuteTemplate with http.ResponseWriter (XSS)

CWE-94. Includes 6 test samples (3 positive, 3 negative).
2026-03-11 11:03:55 +01:00
Cosmin Cojocar 619ce2117e Fix infinite recursion in interprocedural taint analysis (#1594)
The interprocedural taint analysis functions isCalleValueTainted,
isFieldOfAllocTaintedInCallee, and isFieldTaintedViaCall did not check
the visited map before recursing. Since callee-scope SSA values are
different objects from caller-scope ones, the visited map populated by
isTainted never cached them, causing exponential recursion on codebases
with multi-level constructor chains that fan out tainted config through
struct fields.

Add visited map checks at the entry of each interprocedural function to
prevent re-analyzing the same SSA values, call sites, and allocations.

Also add test cases exercising multi-level constructor chains, fan-out
constructors, and deep nested struct field access to verify termination.

Fixes #1587
2026-03-09 17:52:52 +01:00
Cosmin Cojocar 0e0eb1792f Fix G118 false positive when cancel is stored in returned struct field (#1593)
When a cancel function is stored in a struct field and the struct is
returned to the caller, the cancel responsibility is transferred.
isCancelCalled did not detect this pattern because the FieldAddr trace
reached a dead end — it never connected the field store to the struct
being returned.

Add isStructFieldReturnedFromFunc that checks whether the struct base
pointer of a FieldAddr is loaded and returned, and call it from the
Store+FieldAddr branch in isCancelCalled.

Fixes #1591
2026-03-09 15:49:02 +01:00
Cosmin Cojocar 59a9da022f Fix G118 false positive on cancel called inside goroutine closure (#1592)
The isCancelCalled function did not handle *ssa.MakeClosure, so when
a cancel function was captured as a free variable in a closure
(e.g. go func() { cancel() }()), gosec could not see the call inside
the closure body and reported a false positive.

Add a MakeClosure case that follows the cancel value into the closure's
FreeVars, allowing the existing call-detection logic to find the
invocation.

Fixes #1590
2026-03-09 15:25:30 +01:00
Cosmin Cojocar c709ed8be3 fix(G118): treat returned cancel func as called (fixes #1584) (#1585)
The isCancelCalled BFS did not handle *ssa.Return, so a cancel
function returned from a helper was flagged as lost even though
responsibility was transferred to the caller.

Add a Return case that recognises the cancel value among the return
operands and treats it as called.

Update the existing 'cancel returned to caller' test to expect 0
issues, and add a new test case matching the exact pattern from
issue #1584 (cancel returned as func() and invoked by the caller
through a shutdown chain).
2026-03-06 19:27:18 +01:00
Cosmin Cojocar fa74dd7069 chore(go): update supported Go versions to 1.25.8 and 1.26.1 (#1583)
* chore(go): update supported Go versions to 1.25.8 and 1.26.1

* test(g117): persist BurntSushi toml dependency for sample builds
2026-03-06 09:27:20 +01:00
Cosmin Cojocar cd1f29ec71 Update the README with the correct version of the Github action for gosec (#1582)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-03-06 08:46:01 +01:00
Cosmin Cojocar 6641fcf966 Fix G115 false positives for guarded int64-to-byte conversions (#1578)
* Fix G115 false positives for guarded int64-to-byte conversions

* Fix lint warnings

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

---------

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-03-01 20:59:20 +01:00
Cosmin Cojocar 3c9c3da692 Update the container image migration notice (#1576)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-03-01 18:16:33 +01:00
Cosmin Cojocar 973e94e8fc chore(action): bump gosec to 2.24.7 (#1575) 2026-03-01 18:03:52 +01:00
Cosmin Cojocar bb17e422fc Ignore nosec comments in action integration workflow to generate some warnings (#1573)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-03-01 10:42:57 +01:00
Cosmin Cojocar e1502ad216 Add a workflow for action integration test (#1571)
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-03-01 10:33:59 +01:00
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>
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>
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>
2026-02-28 13:54:19 +01:00
Cosmin Cojocar 46e53da622 fix(release): use existing cosign-installer action version (#1562) 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
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
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
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
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
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
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
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
Cosmin Cojocar 1b7e1e94bc Update gosec to version v2.23.0 in the Github action (#1496)
Update Github action to use the release of gosec v2.23.0

Change-Id: I72672694bea0a1e25229283e15459f7762965fba

Signed-off-by: Cosmin Cojocar <ccojocar@google.com>
2026-02-11 13:52:41 +01:00
Cosmin Cojocar b579523bf6 Update the go version to 1.25.6 and 1.24.12 (#1474)
fixes #1469

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2026-01-19 18:38:57 +01:00
Cosmin Cojocar c073629009 Improve slice bound check (#1442)
Improve slice bound check to habdle bounded values and properly parse
the address index only from references

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2025-12-28 19:39:40 +02:00
Cosmin Cojocar dcf93a8b8b Update GitHub action to gosec 2.22.11 (#1438)
Signed-off-by: Cosmin Cojocar <ccojocar@google.com>
2025-12-11 15:27:06 +01:00
Cosmin Cojocar d4be2876cf Update go to 1.25.5 and 1.24.11 in CI (#1433)
* Update go version to 1.25.5 and 1.24.11 in CI


Signed-off-by: Cosmin Cojocar <ccojocar@google.com>

* Update the buildSSA to use the new tools package

Signed-off-by: Cosmin Cojocar <ccojocar@google.com>

* Remove the type allignment check

Signed-off-by: Cosmin Cojocar <ccojocar@google.com>

---------

Signed-off-by: Cosmin Cojocar <ccojocar@google.com>
2025-12-03 13:57:07 +01:00
Cosmin Cojocar c34cbbf565 Update go to version 1.25.4 and 1.24.10 in CI (#1415)
fixes #1404

Signed-off-by: Cosmin Cojocar <ccojocar@google.com>
2025-11-06 17:09:17 +01:00
Cosmin Cojocar 0adab9d9be Update gosec to version v2.22.10 in the github action (#1405)
Signed-off-by: Cosmin Cojocar <ccojocar@google.com>
2025-10-15 10:18:27 +02:00
Cosmin Cojocar 6be2b51fd7 Update go to version 1.25.3 and 1.24.9 in CI (#1404)
Signed-off-by: Cosmin Cojocar <ccojocar@google.com>
2025-10-14 14:54:01 +02:00
Cosmin Cojocar f6760311e8 Update go to version 1.25.2 and 2.24.8 in CI (#1401)
Signed-off-by: Cosmin Cojocar <ccojocar@google.com>
2025-10-08 12:55:04 +02:00
Cosmin Cojocar 955a68d0d1 Update go version to 1.24.2 and 1.23.8 (#1331) 2025-04-03 16:53:13 +02:00