Skip to content

feat: Support for adding taint analysis engine#1486

Open
ravisastryk wants to merge 7 commits intosecurego:masterfrom
ravisastryk:feature/taint-analysis-engine
Open

feat: Support for adding taint analysis engine#1486
ravisastryk wants to merge 7 commits intosecurego:masterfrom
ravisastryk:feature/taint-analysis-engine

Conversation

@ravisastryk
Copy link
Contributor

Taint Analysis Engine for gosec

Implements a minimal, zero-dependency taint analysis engine for gosec that tracks data flow from sources (user input) to sinks (dangerous functions) to detect security vulnerabilities.

Issue: #1160 - Request for taint analysis support in gosec

New Security Rules

Rule ID Vulnerability CWE Severity
G701 SQL Injection CWE-89 HIGH
G702 Command Injection CWE-78 CRITICAL
G703 Path Traversal CWE-22 HIGH
G704 SSRF CWE-918 HIGH
G705 XSS CWE-79 MEDIUM
G706 Log Injection CWE-117 LOW

Changes

  • Uses only golang.org/x/tools packages that gosec already depends on
  • Leverages Static Single Assignment form for precise data flow tracking
  • Uses Class Hierarchy Analysis (CHA) for sound call graph construction
  • Easy to add new sources and sinks via configuration

Example Detection

SQL Injection (G701):

func handler(db *sql.DB, r *http.Request) {
    name := r.URL.Query().Get("name")  // SOURCE: user input
    query := "SELECT * FROM users WHERE name = '" + name + "'"
    db.Query(query)  // SINK: G701 detected here
}

Command Injection (G702):

func handler(w http.ResponseWriter, r *http.Request) {
    cmd := r.URL.Query().Get("cmd")  // SOURCE: user input
    exec.Command("sh", "-c", cmd).Run()  // SINK: G702 detected here
}

@ravisastryk ravisastryk force-pushed the feature/taint-analysis-engine branch from 242671d to 105052f Compare January 28, 2026 03:44
@ravisastryk ravisastryk changed the title feat: add taint analysis engine for data flow security feat: Support for adding taint analysis engine Jan 28, 2026
@codecov-commenter
Copy link

codecov-commenter commented Jan 28, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 57.05128% with 201 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.66%. Comparing base (1216c9b) to head (bf5d054).
⚠️ Report is 178 commits behind head on master.

Files with missing lines Patch % Lines
analyzers/taint/taint.go 17.36% 156 Missing and 1 partial ⚠️
analyzers/taint/analyzer.go 25.42% 43 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1486      +/-   ##
==========================================
+ Coverage   68.49%   68.66%   +0.16%     
==========================================
  Files          75       94      +19     
  Lines        4384     7200    +2816     
==========================================
+ Hits         3003     4944    +1941     
- Misses       1233     2026     +793     
- Partials      148      230      +82     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ravisastryk ravisastryk marked this pull request as ready for review January 28, 2026 03:51
@ravisastryk
Copy link
Contributor Author

@ccojocar Please review when you get a chance. TIA

@ravisastryk ravisastryk force-pushed the feature/taint-analysis-engine branch 4 times, most recently from a653518 to a5dd1eb Compare January 28, 2026 06:23
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.
@ravisastryk ravisastryk force-pushed the feature/taint-analysis-engine branch from a5dd1eb to bf684e2 Compare January 28, 2026 06:33
@ccojocar
Copy link
Member

Thanks for submitting this. I will need some time to review it. Which AI code generator are you using?

@ravisastryk
Copy link
Contributor Author

Thanks for submitting this. I will need some time to review it. Which AI code generator are you using?

Thank you for asking @ccojocar. Claude helped with initial scaffolding, and I handled the refinements and final implementation to improve further. Please take your time reviewing. I am interested to see this reach a wider audience and encourage broader gosec adoption. Thank you for your time again.


// Source defines where tainted data originates.
// Format: "package/path.TypeOrFunc" or "*package/path.Type" for pointer types.
type Source struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a go doc comment on each field?

// Format: "package/path.TypeOrFunc" or "*package/path.Type" for pointer types.
type Source struct {
Package string // e.g., "net/http"
Name string // e.g., "Request" or "Get"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this function/method name? Can you make the name more clear?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name is the type or function name that produces tainted data (e.g., "Request" for type, "Get" for function). I have updated the documentation


// Sink defines a dangerous function that should not receive tainted data.
// Format: "(*package/path.Type).Method" or "package/path.Func"
type Sink struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add go doc on each field.

}

// Result represents a detected taint flow from source to sink.
type Result struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a go doc on each field.


// Analyzer performs taint analysis on SSA programs.
type Analyzer struct {
config Config
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use a pointer for config.

{Package: "net/http", Method: "Get"},
{Package: "net/http", Method: "Post"},
{Package: "net/http", Method: "Head"},
{Package: "net/http", Method: "PostForm"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http.NewRequest missing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

net.Dial, net.DialTImeout, net.LookupHost

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

net/http/httputil.ReverseProxy:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

net/http/httputil NewSingleHostReverseProxy

// XSS returns a configuration for detecting Cross-Site Scripting vulnerabilities.
func XSS() Config {
return Config{
Sources: []Source{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see sources above for a more complete list

{Package: "net/http", Name: "Request", Pointer: true},
{Package: "net/url", Name: "Values"},
},
Sinks: []Sink{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

template.HTML, template.HTMLAttr, template.JS, template.CSS missing

func LogInjection() Config {
return Config{
Sources: []Source{
{Package: "net/http", Name: "Request", Pointer: true},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above for a more complete list of sources

{Package: "log", Method: "Println"},
{Package: "log", Method: "Fatal"},
{Package: "log", Method: "Fatalf"},
{Package: "log", Method: "Fatalln"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.Panic, log/slog.Info, Error, Warn

@ravisastryk
Copy link
Contributor Author

Thank you @ccojocar for your thorough review! I believe I have addressed most of your suggestions. Can you please re-review when you get a chance? Any other suggestions are welcome!

@ravisastryk ravisastryk requested a review from ccojocar February 1, 2026 08:03
@ravisastryk
Copy link
Contributor Author

@ccojocar Friendly reminder! Can you please re-review when you get a chance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants