Skip to content

aiskillstore/marketplace / skills/0x8506/vibe-security

vibe-security

Verified

Security intelligence for code analysis. Detects SQL injection, XSS, CSRF, authentication issues, crypto failures, and more. Actions: scan, analyze, fix, audit, check, review, secure, validate, sanitize, protect. Languages: JavaScript, TypeScript, Python, PHP, Java, Go, Ruby. Frameworks: Express, Django, Flask, Laravel, Spring, Rails. Vulnerabilities: SQL injection, XSS, CSRF, authentication bypass, authorization issues, command injection, path traversal, insecure deserialization, weak crypto, sensitive data exposure. Topics: input validation, output encoding, parameterized queries, password hashing, session management, CORS, CSP, security headers, rate limiting, dependency scanning.

FileKindSize
SKILL.mdskill md14.2 KB
data/advanced-patterns.csvother3.0 KB
data/compliance-mapping.csvother2.1 KB
data/fix-templates.csvother2.4 KB
data/frameworks.csvother1.1 KB
data/iac-security.csvother2.2 KB
data/languages-extended.csvother1.7 KB
data/patterns.csvother1.5 KB
data/rules.csvother1.5 KB
data/supply-chain.csvother839 B
data/vulnerabilities.csvother1.4 KB
scripts/ast_analyzer.pyexecutablescript9.2 KB
scripts/autofix_engine.pyexecutablescript11.7 KB
scripts/core.pyexecutablescript4.0 KB
scripts/cve_integration.pyexecutablescript9.9 KB
scripts/dataflow_analyzer.pyexecutablescript10.6 KB
scripts/fix_engine.pyexecutablescript13.8 KB
scripts/reporter.pyexecutablescript13.5 KB
scripts/search.pyexecutablescript3.0 KB
skill-report.jsonconfig152.3 KB

scripts/ast_analyzer.py

View on GitHub
#!/usr/bin/env python3
"""
AST-based semantic analysis for security vulnerabilities
Provides more accurate detection than regex patterns
"""
import ast
import json
from typing import List, Dict, Any, Optional
from pathlib import Path


class SecurityVisitor(ast.NodeVisitor):
    """AST visitor to detect security issues in Python code"""
    
    def __init__(self):
        self.issues = []
        self.tainted_vars = set()
        
    def visit_Call(self, node: ast.Call) -> None:
        """Detect dangerous function calls"""
        if isinstance(node.func, ast.Name):
            # Check for dangerous builtins
            if node.func.id in ['eval', 'exec', '__import__']:
                self.issues.append({
                    'type': 'code-injection',
                    'severity': 'critical',
                    'line': node.lineno,
                    'function': node.func.id,
                    'message': f'Dangerous use of {node.func.id}()'
                })
            
            # Check for pickle
            if node.func.id == 'loads' and len(node.args) > 0:
                self.issues.append({
                    'type': 'deserialization',
                    'severity': 'critical',
                    'line': node.lineno,
                    'message': 'Potentially unsafe deserialization'
                })
        
        elif isinstance(node.func, ast.Attribute):
            # Check for os.system
            if node.func.attr == 'system':
                self.issues.append({
                    'type': 'command-injection',
                    'severity': 'critical',
                    'line': node.lineno,
                    'message': 'Use of os.system() - prefer subprocess'
                })
            
            # Check for SQL execute with f-strings
            if node.func.attr == 'execute' and len(node.args) > 0:
                if isinstance(node.args[0], ast.JoinedStr):
                    self.issues.append({
                        'type': 'sql-injection',
                        'severity': 'critical',
                        'line': node.lineno,
                        'message': 'SQL query uses f-string - use parameterized queries'
                    })
        
        self.generic_visit(node)
    
    def visit_Assign(self, node: ast.Assign) -> None:
        """Track variable assignments for taint analysis"""
        for target in node.targets:
            if isinstance(target, ast.Name):
                # Check if assigned value comes from user input
                if self._is_user_input(node.value):
                    self.tainted_vars.add(target.id)
        
        self.generic_visit(node)
    
    def _is_user_input(self, node: ast.AST) -> bool:
        """Check if a node represents user input"""
        if isinstance(node, ast.Call):
            if isinstance(node.func, ast.Name):
                return node.func.id in ['input', 'raw_input']
            if isinstance(node.func, ast.Attribute):
                return node.func.attr in ['get', 'post', 'request']
        return False


class JavaScriptSecurityAnalyzer:
    """JavaScript/TypeScript security analyzer using regex + heuristics"""
    
    def __init__(self, code: str):
        self.code = code
        self.lines = code.split('\n')
        self.issues = []
    
    def analyze(self) -> List[Dict[str, Any]]:
        """Analyze JavaScript code for security issues"""
        self._check_sql_injection()
        self._check_xss()
        self._check_command_injection()
        self._check_eval()
        self._check_dangerous_functions()
        return self.issues
    
    def _check_sql_injection(self):
        """Detect SQL injection patterns"""
        for i, line in enumerate(self.lines, 1):
            # Template literals in queries
            if 'query' in line.lower() and '${' in line:
                self.issues.append({
                    'type': 'sql-injection',
                    'severity': 'critical',
                    'line': i,
                    'message': 'SQL query uses template literal - use parameterized queries',
                    'code': line.strip()
                })
            # String concatenation in queries
            if 'query' in line.lower() and ('+' in line or 'concat' in line.lower()):
                self.issues.append({
                    'type': 'sql-injection',
                    'severity': 'critical',
                    'line': i,
                    'message': 'SQL query uses string concatenation',
                    'code': line.strip()
                })
    
    def _check_xss(self):
        """Detect XSS vulnerabilities"""
        for i, line in enumerate(self.lines, 1):
            if '.innerHTML' in line and '=' in line:
                self.issues.append({
                    'type': 'xss',
                    'severity': 'high',
                    'line': i,
                    'message': 'Potential XSS via innerHTML - use textContent or sanitize',
                    'code': line.strip()
                })
            if 'dangerouslySetInnerHTML' in line:
                self.issues.append({
                    'type': 'xss',
                    'severity': 'high',
                    'line': i,
                    'message': 'React dangerouslySetInnerHTML detected - ensure sanitization',
                    'code': line.strip()
                })
    
    def _check_command_injection(self):
        """Detect command injection patterns"""
        dangerous_functions = ['exec', 'spawn', 'execSync', 'spawnSync']
        for i, line in enumerate(self.lines, 1):
            for func in dangerous_functions:
                if func in line and ('${' in line or '+' in line):
                    self.issues.append({
                        'type': 'command-injection',
                        'severity': 'critical',
                        'line': i,
                        'message': f'Command execution with {func}() and dynamic input',
                        'code': line.strip()
                    })
    
    def _check_eval(self):
        """Detect use of eval"""
        for i, line in enumerate(self.lines, 1):
            if 'eval(' in line:
                self.issues.append({
                    'type': 'code-injection',
                    'severity': 'critical',
                    'line': i,
                    'message': 'Use of eval() is dangerous - find alternative approach',
                    'code': line.strip()
                })
    
    def _check_dangerous_functions(self):
        """Check for other dangerous patterns"""
        patterns = {
            'new Function(': ('code-injection', 'critical', 'Dynamic function creation'),
            'crypto.createHash(\'md5\')': ('weak-crypto', 'high', 'MD5 is cryptographically broken'),
            'Math.random()': ('weak-random', 'medium', 'Math.random() not suitable for security'),
        }
        
        for i, line in enumerate(self.lines, 1):
            for pattern, (vuln_type, severity, message) in patterns.items():
                if pattern in line:
                    self.issues.append({
                        'type': vuln_type,
                        'severity': severity,
                        'line': i,
                        'message': message,
                        'code': line.strip()
                    })


def analyze_file(filepath: str, language: str = None) -> Dict[str, Any]:
    """
    Analyze a file for security vulnerabilities using AST when possible
    
    Args:
        filepath: Path to the file to analyze
        language: Programming language (auto-detected if None)
    
    Returns:
        Dictionary with analysis results
    """
    path = Path(filepath)
    
    if not path.exists():
        return {'error': 'File not found'}
    
    # Auto-detect language
    if language is None:
        ext = path.suffix.lower()
        language_map = {
            '.py': 'python',
            '.js': 'javascript',
            '.ts': 'typescript',
            '.jsx': 'javascript',
            '.tsx': 'typescript'
        }
        language = language_map.get(ext, 'unknown')
    
    code = path.read_text()
    
    # Use appropriate analyzer
    if language == 'python':
        try:
            tree = ast.parse(code)
            visitor = SecurityVisitor()
            visitor.visit(tree)
            return {
                'file': str(path),
                'language': language,
                'method': 'ast',
                'issues': visitor.issues
            }
        except SyntaxError as e:
            return {
                'error': f'Syntax error: {e}',
                'file': str(path)
            }
    
    elif language in ['javascript', 'typescript']:
        analyzer = JavaScriptSecurityAnalyzer(code)
        issues = analyzer.analyze()
        return {
            'file': str(path),
            'language': language,
            'method': 'heuristic',
            'issues': issues
        }
    
    return {
        'file': str(path),
        'language': language,
        'error': 'Language not supported for AST analysis'
    }


if __name__ == '__main__':
    import sys
    
    if len(sys.argv) < 2:
        print('Usage: python ast_analyzer.py <file>')
        sys.exit(1)
    
    result = analyze_file(sys.argv[1])
    print(json.dumps(result, indent=2))
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall