Commit Graph
9 Commits
Author SHA1 Message Date
Ravi Sastry Kadali 4ead098510 Add G710 rule for open redirect via taint analysis (#1654) 2026-04-26 09:38:45 +02: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
Ravi Sastry Kadali befce8de5d fix(G118): eliminate false positive for package-level cancel variables (#1602)
* fix(G118): eliminate false positive for package-level cancel variables

  G118 was incorrectly reporting context cancellation function not called
  when the cancel function was assigned to a package-level variable (e.g.,
  in init()) and called in a separate function (e.g., signal handler).

  Root cause: isCancelCalled() lacked special handling for *ssa.Global
  (package-level variables), causing cross-function tracking to fail.

  Solution: Add dedicated tracking for package-level globals, similar to
  the struct field handling added in PR #1596. The fix includes:
  - Check in *ssa.Store case to detect global variable assignments
  - isGlobalCalledInAnyFunc() helper to search all functions for calls
  - isValueCalled() generalized helper for BFS value tracking

* additional test
2026-03-12 17:16: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
Ravi Sastry Kadali 889546214c fix(G118): eliminate false positive when cancel is called via struct field in a closure (#1596)
* fix(G118): eliminate false positive when cancel stored in struct field post-construction

When a cancel function is assigned to a struct field after construction
(e.g. s.cancel = cancel), the SSA FieldAddr for the store is a distinct
value from any FieldAddr created later for defer s.cancel() or inside a
closure. The existing isCancelCalledViaStructField only matched receiver
methods and missed these patterns.

Add isFieldCalledInAnyFunc which scans all SSA functions (including
closures) for a FieldAddr with matching struct pointer type and field
index, then checks whether the loaded value is called. As a side effect,
this also resolves the known false positive for nested struct field access.

fixes: 1595

* update rules documentation
2026-03-10 17:21:24 +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
dannyc-grafana e21b4d42cf Rule documentation updates (#1272) 2024-12-17 09:40:45 +01:00