Scan analyzes a parsed SQL AST for SQL injection patterns and vulnerabilities. It performs deep traversal of the AST to detect suspicious patterns including tautologies, dangerous functions, UNION-based injection, and other attack vectors. The method is safe for concurrent use as it does not modify
(tree *ast.AST)
| 560 | // fmt.Printf("[%s] %s\n", finding.Severity, finding.Description) |
| 561 | // } |
| 562 | func (s *Scanner) Scan(tree *ast.AST) *ScanResult { |
| 563 | result := &ScanResult{ |
| 564 | Findings: make([]Finding, 0), |
| 565 | } |
| 566 | |
| 567 | if tree == nil { |
| 568 | return result |
| 569 | } |
| 570 | |
| 571 | for _, stmt := range tree.Statements { |
| 572 | s.scanStatement(stmt, result) |
| 573 | } |
| 574 | |
| 575 | // Update counts |
| 576 | s.updateCounts(result) |
| 577 | |
| 578 | return result |
| 579 | } |
| 580 | |
| 581 | // ScanSQL analyzes raw SQL string for injection patterns using regex-based detection. |
| 582 | // This method is useful for detecting patterns that might not be visible in the AST, |