How pratheep-bit/frapast works
Purpose and entry points
frapAST is a Python 3.10+ static security scanner specialized for Frappe/ERPNext applications. It combines framework-aware indexing, AST rules, reachability context, severity scoring, optional runtime proof, and report exports.
Primary entry points are the package launcher and CLI: scanner/__main__.py, scanner/cli.py. The local dashboard is served by scanner/web/server.py; containerized execution is supported by Dockerfile and docker-compose.yml.
Scan orchestration and shared records
The CLI resolves target repositories/configuration, runs the analysis pipeline, optionally persists a findings ledger, and selects terminal, structured, or web-facing output. Shared finding/index record shapes are centralized in scanner/shared/records.py, while configuration is handled in scanner/config.py.
The main boundary is from an arbitrary Frappe application filesystem into normalized indexes and findings. Persistent tracking uses the ledger layer: scanner/ledger_io.py, scanner/ledger_schema.py.
Framework-aware indexing
Three analysis domains model Frappe-specific inputs:
• DocType JSON schemas and field metadata: scanner/schema/engine.py, scanner/schema/models.py.
• hooks.py declarations such as document events, scheduler events, and overridden methods: scanner/hooks/engine.py, scanner/hooks/models.py.
• Python modules parsed through the Python AST to discover symbols, endpoints, calls, imports, and relevant source constructs: scanner/python/engine.py, scanner/python/models.py.
These stages avoid dependence on a running Frappe instance for static scanning, while accepting source and schema conventions established by the target app.
Reachability and rule detection
The call-graph builder connects indexed symbols through direct calls plus Frappe dispatch mechanisms—string RPC dispatch, hook dispatch, and dynamic document methods: scanner/callgraph/builder.py, scanner/callgraph/models.py.
The rule engine evaluates graph-connected indexed code against YAML-defined detectors and their schema: scanner/rules/engine.py, scanner/rules/schema.yaml, scanner/rules/FR-PERM-001.yaml. Rules cover authorization, SQL injection, hooks, workflow integrity, correctness, and related Frappe risks. This is the core static-analysis boundary: indexes/call graph in, deduplicated candidate findings out.
Classification, suppression, and tracking
Severity is assigned through a composite model incorporating privilege, impact, blast radius, and proof tier: scanner/severity/engine.py, scanner/severity/models.py, scanner/severity/taxonomy.py. The taxonomy data maps findings into the broader security classification system: scanner/taxonomy/taxonomy_registry.yaml, scanner/taxonomy/FR-SQLI-001.yaml.
False-positive handling is a separate categorization flow in scanner/fp/engine.py, and regression artifact generation lives in scanner/regression/generator.py. Ledger validation/integrity tools protect persisted findings from malformed or inconsistent state: scanner/validate_ledger.py, scanner/verify_ledger_integrity.py.
Optional runtime proof
Proof operates after static detection and can upgrade, fail, skip, or error a candidate without deleting the underlying static evidence. The orchestrator coordinates Tier 1 local reproducer execution and Tier 2 bench verification: scanner/proof/orchestrator.py, scanner/proof/bench_runner.py.
Tier 2 crosses the only significant external-service boundary: HTTP/RPC communication with a configured local or remote Frappe bench via scanner/proof/http_client.py and synthesized requests in scanner/proof/http_synthesis.py. Tier 1 uses isolated local subprocess-style reproducer execution rather than a hosted service.
Delivery surfaces and CI
Reporting converts findings into terminal-friendly and machine-readable JSON, YAML, SARIF, and Markdown outputs: scanner/reporting/engine.py, scanner/reporting/sarif.py, scanner/reporting/formatters.py. GitHub Actions integration is represented by action.yml and .github/workflows/scanner-ci.yml.
The optional local-only dashboard provides scan/proof workflows, exports, and progress UI: scanner/web/server.py, scanner/web/static/app.js, scanner/ui/flow.py. It is a local Python HTTP service, not a cloud application; its intended browser boundary is loopback access.
Main entry points: cli.py CLI launcher · server.py Local dashboard · orchestrator.py Proof orchestrator · engine.py False-positive handling
Components 20
Entry & Control
- CLI launcher
scanner/cli.py - Scan configuration
scanner/config.py - Shared records · Normalized index and finding record shapes.
scanner/shared/records.py
Static Indexing
- DocType indexer
scanner/schema/engine.py - Hooks indexer
scanner/hooks/engine.py - Python AST indexer · Discovers symbols, endpoints, calls, imports, and source constructs.
scanner/python/engine.py - Normalized indexes
Detection & Enrichment
- Frappe call graph · Adds direct calls, RPC, hook, and document-method dispatch.
scanner/callgraph/builder.py - Rule engine · YAML-defined security detectors produce deduplicated candidates.
scanner/rules/engine.py - Severity scoring · Combines privilege, impact, blast radius, and proof tier.
scanner/severity/engine.py - Security taxonomy
scanner/taxonomy/taxonomy_registry.yaml - False-positive handling
scanner/fp/engine.py - Findings ledger · Persists tracked findings with schema and integrity validation.
scanner/ledger_io.py
Proof, Reporting & UI
- Proof orchestrator · Retains static evidence while marking proof outcomes.
scanner/proof/orchestrator.py - Report exports · Terminal, JSON, YAML, SARIF, and Markdown outputs.
scanner/reporting/engine.py - Local dashboard · Local scan, proof, export, and progress interface.
scanner/web/server.py - GitHub Actions
action.yml
Other components
- Frappe app source · Arbitrary application source and framework conventions.
- Frappe bench · Configured local or remote verification target.
- Local browser
Connections 28
- CLI launcher → Scan configuration: loads
- CLI launcher → Frappe app source: scans
- CLI launcher → DocType indexer: orchestrates
- CLI launcher → Hooks indexer: orchestrates
- CLI launcher → Python AST indexer: orchestrates
- Frappe app source → DocType indexer: DocType JSON
- Frappe app source → Hooks indexer: hooks.py
- Frappe app source → Python AST indexer: Python modules
- DocType indexer → Normalized indexes: schema metadata
- Hooks indexer → Normalized indexes: event declarations
- Python AST indexer → Normalized indexes: AST symbols
- Normalized indexes → Frappe call graph: indexed constructs
- Frappe call graph → Rule engine: reachability context
- Normalized indexes → Rule engine: source metadata
- Rule engine → Severity scoring: candidate findings
- Security taxonomy → Severity scoring: classification mapping
- Severity scoring → False-positive handling: scored findings
- False-positive handling → Findings ledger: tracked findings
- False-positive handling → Proof orchestrator: static candidates
- Proof orchestrator → Frappe bench: Tier 2 HTTP/RPC
- Proof orchestrator → Findings ledger: proof outcomes
- Findings ledger → Report exports: findings
- CLI launcher → Report exports: selects output
- Local dashboard → CLI launcher: starts scans
- Local dashboard → Proof orchestrator: runs proof
- Local dashboard → Report exports: exports
- Local browser → Local dashboard: loopback access
- GitHub Actions → CLI launcher: runs scanner