scanBinaryExpression checks for tautologies and suspicious patterns.
(expr *ast.BinaryExpression, result *ScanResult, context string)
| 748 | |
| 749 | // scanBinaryExpression checks for tautologies and suspicious patterns. |
| 750 | func (s *Scanner) scanBinaryExpression(expr *ast.BinaryExpression, result *ScanResult, context string) { |
| 751 | if expr == nil { |
| 752 | return |
| 753 | } |
| 754 | |
| 755 | // Check for tautologies (always true conditions) |
| 756 | if s.isTautology(expr) { |
| 757 | finding := Finding{ |
| 758 | Severity: SeverityCritical, |
| 759 | Pattern: PatternTautology, |
| 760 | Description: "Always-true condition detected (tautology)", |
| 761 | Risk: "Authentication bypass, data extraction", |
| 762 | Suggestion: "Remove or replace with proper condition", |
| 763 | } |
| 764 | if s.shouldInclude(finding.Severity) { |
| 765 | result.Findings = append(result.Findings, finding) |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | // Check for OR-based injection patterns |
| 770 | if strings.ToUpper(expr.Operator) == "OR" { |
| 771 | s.checkOrInjection(expr, result) |
| 772 | } |
| 773 | |
| 774 | // Recursively check sub-expressions |
| 775 | s.scanExpression(expr.Left, result, context) |
| 776 | s.scanExpression(expr.Right, result, context) |
| 777 | } |
| 778 | |
| 779 | // isTautology checks if an expression is always true. |
| 780 | func (s *Scanner) isTautology(expr *ast.BinaryExpression) bool { |
no test coverage detected