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

Function securityScanInternal

pkg/mcp/tools.go:159–189  ·  view source on GitHub ↗

securityScanInternal scans a SQL string for injection patterns and other threats.

(sql string)

Source from the content-addressed store, hash-verified

157
158// securityScanInternal scans a SQL string for injection patterns and other threats.
159func securityScanInternal(sql string) (map[string]any, error) {
160 if sql == "" {
161 return nil, fmt.Errorf("parameter 'sql' is required and must not be empty")
162 }
163
164 scanner := security.NewScanner()
165 result := scanner.ScanSQL(sql)
166
167 findings := make([]map[string]any, 0, len(result.Findings))
168 for _, f := range result.Findings {
169 findings = append(findings, map[string]any{
170 "severity": string(f.Severity),
171 "pattern": string(f.Pattern),
172 "description": f.Description,
173 "risk": f.Risk,
174 "suggestion": f.Suggestion,
175 })
176 }
177
178 return map[string]any{
179 "is_clean": result.IsClean(),
180 "has_critical": result.HasCritical(),
181 "has_high": result.HasHighOrAbove(),
182 "total_count": result.TotalCount,
183 "critical_count": result.CriticalCount,
184 "high_count": result.HighCount,
185 "medium_count": result.MediumCount,
186 "low_count": result.LowCount,
187 "findings": findings,
188 }, nil
189}
190
191// lintSQLInternal runs the full linter rule set against a SQL string.
192func lintSQLInternal(sql string) (map[string]any, error) {

Calls 6

ScanSQLMethod · 0.95
NewScannerFunction · 0.92
IsCleanMethod · 0.80
HasCriticalMethod · 0.80
HasHighOrAboveMethod · 0.80
ErrorfMethod · 0.65