Commit Graph
20 Commits
Author SHA1 Message Date
Ravi Sastry Kadali b4c4d0b589 Fix: Bump go-version: 1.25.8 to 1.25.9 in ci (#1632) 2026-04-10 10:23:28 +02:00
Ravi Sastry Kadali baf0dcfbec fix(taint): gate *http.Request auto-taint on entry-point detection (#1630)
* fix(taint): gate *http.Request auto-taint on entry-point detection (#1629)

isParameterTainted unconditionally tainted any *http.Request parameter by
type, even when the function had known callers passing constant-URL requests.

Check the CHA call graph first: only auto-taint when the function has no
in-edges (true external entry point). When callers exist, fall through to
the existing caller-verification loop instead.
Fixes #1629

* Address Barry AI Security Analysis

* improve code coverage

* fix lint

* taint mechanism, framework agnostic

* address lint warning
2026-04-08 11:31:24 +02:00
Ravi Sastry Kadali 844b1703bf fix(G706): scope slog sinks to msg arg only to prevent false positives on structured attributes (#1623)
slog attribute values are auto-escaped by TextHandler/JSONHandler; only the message arg is a real injection vector.

Fixes: #1622
2026-03-25 21:46:59 +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
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
Ravi Sastry Kadali cbf46b8771 fix(analyzer): per-package rule instantiation eliminates concurrent map crash (#1589)
Analyzer.Process fans out package walks across goroutines that previously
shared a single rule set. Rules with mutable per-package state — specifically
readfile (G304), whose cleanedVar/joinedVar maps are written and read across
goroutines — raced fatally under concurrency. The fix stores the RuleBuilder
functions after LoadRules and calls buildPackageRuleset() at the start of each
checkRules invocation, giving every concurrent worker its own freshly allocated
rule instances with no shared mutable state and no locks required. Stale map
entries no longer leak across package boundaries, closing a secondary
false-negative bug as a side-effect.

fixes: 1586
2026-03-09 14:57:13 +01:00
Ravi Sastry Kadali 271492bcd9 fix: G704 false positive on const URL (#1551) 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
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
Ravi Sastry Kadali 000384e510 fix: broken taint analysis causing false positives (#1506)
* fix: broken taint analysis causing false positives

* add tests and improve code coverage
2026-02-14 12:24:33 +01:00
Ravi Sastry Kadali 616192c9d9 fix: panic on float constants in overflow analyzer (#1505) 2026-02-14 12:16:41 +01:00
Ravi Sastry Kadali 79956a3b4c fix: panic when scanning multi-module repos from root (#1504)
* fix: panic when scanning multi-module repos from root

* address linting
2026-02-14 12:15:02 +01:00
Ravi Sastry Kadali 5736e8b88b fix: G602 false positive for array element access (#1499)
Fixes #1495
2026-02-13 11:53:55 +01:00
Ravi Sastry Kadali 398ad549bb feat: Support for adding taint analysis engine (#1486)
* feat: add taint analysis engine for data flow security

Implements SSA-based taint analysis to detect security vulnerabilities:
- G701: SQL injection via string concatenation
- G702: Command injection via user input
- G703: Path traversal via user input
- G704: SSRF via user-controlled URLs
- G705: XSS via unescaped user input
- G706: Log injection via user input

Uses golang.org/x/tools for SSA/call graph analysis with CHA.
Zero external dependencies beyond existing gosec imports.
2026-02-10 15:47:11 +01:00
Ravi Sastry Kadali eb252ba8d7 Fix G602 analyzer panic that kills gosec process (#1491)
* update go version to 1.25.7

* Fix G602 analyzer panic that kills gosec process

* guard against nil block

* add tests for nil guard fixes
2026-02-07 11:30:59 +01:00
Ravi Sastry Kadali 20d71a0cc1 update go version to 1.25.7 (#1492) 2026-02-07 11:29:32 +01:00
Ravi Sastry Kadali d24bbf7d14 Fix SARIF artifactChanges null validation error (#1483)
Only create Fix object when autofix is non-empty to avoid null artifactChanges.
Fixes #1482.
2026-01-25 12:33:21 +01:00
Ravi Sastry Kadali 516260af4e Fix #1240: nosec comments now work with trailing open brackets (#1475)
Add line-based fallback for nosec comment detection when ast.CommentMap
fails to associate comments correctly. This fixes the case where #nosec
comments at the end of lines with open brackets were being ignored.

Refactor duplicate parsing logic into parseNoSecDirective helper function
to reduce code complexity and improve maintainability.
2026-01-23 10:59:42 +01:00
Ravi Sastry KadaliandOittaa be0fd6dcfd Debug Build Profiling Support: Code improvement suggestions for PR#1471 (#1476)
* feat: add debug build profiling support

Add CPU and memory profiling capabilities for debug builds using Go build
tags. Profiling code is completely excluded from release builds.

Changes:
- Add profiling_debug.go with -cpuprofile and -memprofile flags (build tag: debug)
- Add build-debug and build-debug-race Makefile targets
- Refactor main() to run() pattern for proper defer handling
- Replace logger.Fatal() with logger.Printf() + return for clean exits
- Pass logger to profiling for consistent [gosec] log prefix

Usage:
  make build-debug
  ./gosec-debug -cpuprofile cpu.prof -memprofile mem.prof ./...

* Refactor profiling: encapsulate state and improve error handling

- Encapsulate profiling state in Profiler struct to eliminate package-level mutable state
- Add proper error handling with error returns instead of silent failures
- Add exit code constants (exitSuccess/exitFailure) to replace magic numbers
- Fix Makefile clean target to remove gosec-debug binary
- Add nil logger guard for safety

* Use exit constants in all return statements

Replace remaining magic numbers (0, 1) with exitSuccess and exitFailure
constants throughout the run() function for consistency.

---------

Co-authored-by: Oittaa <eero@oittaa.net>
2026-01-23 10:38:04 +01:00
Ravi Sastry Kadali 9f202122a7 feat: support path-based rule exclusions via exclude-rules (#1465)
* add path-based rule exclusions

Implements #1287

* Ssupport for excluding specific rules from specific paths, enabling large monorepos to apply different security rules to different components (e.g., CLI tools vs services).

* fix formatting issuue with path filter test to pass gci
2026-01-15 11:59:43 +01:00