Commit Graph
32 Commits
Author SHA1 Message Date
Ravi Sastry Kadali 553d8a5050 Sync taint rule docs and add missing CWE mappings for G113/G307 (#1658)
Update README and DEVELOPMENT to list G707-G710 alongside the existing
taint rules. Add CWE-444 for G113 (HTTP request smuggling) and CWE-276
for G307 (os.Create permissions) so issues from those rules carry a CWE
weakness instead of nil. Fix a 'falg1' typo in flag_test that prevented
the validated-flag test from binding the flag it was meant to exercise.
2026-04-27 08:27:57 +02:00
Ravi Sastry Kadali 4ead098510 Add G710 rule for open redirect via taint analysis (#1654) 2026-04-26 09:38:45 +02:00
c2dfcec7f3 Add G701-G706 rule-to-CWE mappings and CWE-117, CWE-918 entries (#1606)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: costela <94699+costela@users.noreply.github.com>
2026-03-13 12:26:41 +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 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 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 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 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
oittaa 7387d22592 Refactor rules to use callListRule base structure (#1458)
* Refactor rules to utilize callListRule base structure

- Introduced a new base structure `callListRule` in `rules/base.go` to standardize the implementation of rules that check for specific function calls.
- Updated existing rules to inherit from `callListRule`, simplifying their structure and removing redundant ID methods.
- Modified the `MetaData` field to use `RuleID` instead of `ID` for consistency across rules.
- Removed the `weakcryptohash.go` and `weakdepricatedcryptohash.go` files as their functionality has been integrated into the new structure.

* fix(tlsconfig): correct MetaData field name in generated TLS check

* refactor: standardize rule metadata and call list initialization
2026-01-09 13:55:35 +01:00
oittaa 0f6f21cb3f feat: add secrets serialization G117 (#1451)
* Rule to detect secrets serialization

* Add G117 to rules_test.go

* Fix false positives

* Map to CWE 499, update README
2026-01-04 17:21:22 +02:00
kfessandCosmin Cojocar 424fc4cd9c feature: add rule for trojan source (#1431)
* feature: add rule for trojan source

* use bufio.Scanner for memory efficiency

* Fix lint warnings

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

---------

Signed-off-by: Cosmin Cojocar <ccojocar@google.com>
Co-authored-by: Cosmin Cojocar <ccojocar@google.com>
2025-12-11 10:14:29 +01:00
Brandon AnninandccoVeille 1336dc6820 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>
2025-04-03 16:44:20 +02:00
Dimitar Banchev 0eb8143c23 Added new rule G407(hardcoded IV/nonce)
The rule is supposed to detect for the usage of hardcoded or static nonce/Iv in many encryption algorithms:

* The different modes of AES (mainly tested here)
* It should be able to work with ascon

Currently the rules doesn't check when constant variables are used.

TODO: Improve the rule, to detected for constatant variable usage
2024-08-30 19:35:07 +02:00
56f943b802 Add support to generate auto fixes using LLM (AI) (#1177)
This feature adds support to generate auto fixes for Go scanning findings using LLM (AI). In a first instance, it relies on Gemini API to get a suggestion for a solution. This can be later extended, to integrate also other AI providers.

---------

Signed-off-by: Cosmin Cojocar <ccojocar@google.com>
Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
Co-authored-by: Cosmin Cojocar <ccojocar@google.com>
2024-08-12 12:52:41 +02:00
Dimitar Banchev 9a4a741e6b Added more rules
* Rule G406 responsible for the usage of deprecated MD4 and RIPEMD160 added.
* Rules G506, G507 responsible for tracking the usage of the already mentioned libraries added.
* Slight changes in the Makefile(`make clean` wasn't removing all expected files)
* Added license to `analyzer_test.go`
2024-06-25 13:18:27 +02:00
Dimitar Banchev 58e4fccc13 Split the G401 rule into two separate ones
Now the G401 rule is split into hashing and encryption algorithms.

G401 is responsible for checking the usage of MD5 and SHA1, with corresponding CWE of 328.
And G405(New rule) is responsible for checking the usege of DES and RC4, with corresponding CWE of 327.
2024-06-24 15:25:54 +02:00
Dimitar Banchev 2e71f37efd Updated G401 corresponding CWE
The corresponding CWE from G401 rule was changed from CWE-326 -> CWE-328.
In my opinion, this CWE suits better the rule.
2024-06-24 15:25:54 +02:00
Cosmin Cojocar c3209fcaac Map the G115 rule to an CWE ID
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
2024-05-27 15:12:55 +02:00
Cosmin Cojocar 0ec6cd95d7 Refactor how ignored issues are tracked
Track ignored issues using file location instead of a AST node. There are issues linked to a different AST node than the original node used to start the scan.

Signed-off-by: Cosmin Cojocar <gcojocar@adobe.com>
2023-10-13 14:11:08 +02:00
Oleksandr Redko 09cf6efb3e Fix typos in struct fields, comments, and docs (#1023) 2023-10-05 12:59:17 +02:00
Morgen Malinoski a018cf0fbb Feature: G602 Slice Bound Checking (#973)
* Added slice bounds testing for slice expressions.

* Added checking slice index.

* Added test for reassigning slice.

* Store capacities on reslicing.

* Scope change clears map. Func name used to track slices.

* Map CallExpr to check bounds when passing to functions.

* Fixed linter errors.

* Updated rulelist with CWE mapping.

* Added comment for NewSliceBoundCheck.

* Addressed nil cap runtime error.

* Replaced usage of nil in call arg map with dummy callexprs.

* Updated comments, wrapped error return, addressed other review concerns.
2023-06-21 09:56:36 +02:00
Matthieu MOREL d6aeaad931 correct gci linter (#946)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-03-30 09:31:24 +02:00
Cosmin Cojocar d5a9c73723 Remove rule G307 which checks when an error is not handled when a file or socket connection is closed (#935)
* Remove read only types from unsafe defer rules

* Remove rule G307 which checks when an error is not handled when a file or socket connection is closed

This doesn't seem to bring much value from security perspective, and it caused a lot of controversy since
is a very common pattern in Go.

* Mentioned in documentation that rule G307 is retired

* Clean up the test for rule G307
2023-02-24 14:04:13 +01:00
Cosmin Cojocar f850069114 Use the gosec issue in the go analysers 2023-02-16 09:45:28 +01:00
Cosmin Cojocar de2c6a36fa Extract the issue in its own package 2023-02-16 09:45:28 +01:00