MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / scanBinaryExpression

Method scanBinaryExpression

pkg/sql/security/scanner.go:750–777  ·  view source on GitHub ↗

scanBinaryExpression checks for tautologies and suspicious patterns.

(expr *ast.BinaryExpression, result *ScanResult, context string)

Source from the content-addressed store, hash-verified

748
749// scanBinaryExpression checks for tautologies and suspicious patterns.
750func (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.
780func (s *Scanner) isTautology(expr *ast.BinaryExpression) bool {

Callers 1

scanExpressionMethod · 0.95

Calls 4

isTautologyMethod · 0.95
shouldIncludeMethod · 0.95
checkOrInjectionMethod · 0.95
scanExpressionMethod · 0.95

Tested by

no test coverage detected