How kratospidey/phisdomjs works
1. Project purpose and top-level shape
- phisdom is a phishing-page detection system centered on three signal families: URL, DOM/markup, and JavaScript.
- The repo is organized as a research-to-production pipeline: data collection and normalization, feature extraction, model training, calibration/fusion, evaluation, and export/validation.
2. Core Python package boundary
- The main runtime code lives under src/phisdom.
- This package is the stable API boundary for feature extraction, dataset handling, model definitions, calibration, metrics, and a small CLI demo.
- The rest of the repo is mostly orchestration: scripts, configs, tooling, and validation harnesses.
3. Data and ingestion layer
- src/phisdom/data handles dataset schema, normalization, loaders, multimodal joins, and modality-specific helpers.
- The repository keeps durable state in data/, including split definitions, seed data, and caches for DNS, RDAP, and TLS lookups.
- This implies the pipeline enriches URLs/domains with network and registration metadata before modeling.
4. Feature extraction layer
- src/phisdom/features contains URL feature extraction and related extractors.
- The README confirms URL features include character n-grams, entropy, and length.
- Separate alphabet/token resources under alphabets/ suggest frozen vocabularies or token sets used by text/URL/JS pipelines.
5. Modeling layer: per-modality heads
- src/phisdom/models/heads.py and the training scripts indicate independent modality-specific classifiers:
- train_url_head.py
- train_text_head.py
- train_markup.py
- train_js_head.py
- plus specialized variants like train_dom_gcn.py
- This is a “many experts” architecture: each modality can be trained, evaluated, and calibrated separately.
6. Fusion and ensemble layer
- src/phisdom/models/fusion.py, fusion_new.py, and fusion_old.py show multiple generations of ensemble logic.
- Scripts such as fuse_heads.py, meta_fuse_heads.py, train_fusion_xattn.py, and compare_stacking.py suggest the system combines modality outputs using stacking, cross-attention, or other learned fusion strategies.
- This fusion layer is the main decision boundary for final phishing scores.
7. Calibration and thresholding
- Calibration is a first-class subsystem in both src/phisdom/calibration.py and src/phisdom/models/calibration.py.
- The repo includes scripts for refitting and exporting calibrated models and operating thresholds.
- This indicates the architecture separates raw model scores from deployment-ready probabilities and decision thresholds.
8. Pipeline orchestration and batch jobs
- The scripts/ directory is the operational backbone.
- It covers crawling, ingestion, dataset merging, split creation, augmentation, head training, fusion fitting, evaluation, plotting, reporting, and CI checks.
- Notable stages include crawl_*, fetch_feeds.py, ingest_phish_only.py, make_splits.py, augment_*, evaluate_enhanced.py, report_eval.py, and export_predictions.py.
9. Crawler and external-data boundary
- configs/feeds.yaml and the crawl_* scripts indicate external feed ingestion and browser-based page collection.
- Makefile knobs like CRAWL_CONCURRENCY, TLS_TIMEOUT, DNS_TIMEOUT, MOBILE_PROFILE, and GPU show the crawler is an explicit subsystem with tunable runtime behavior.
- The system also supports mobile-profile reloading to detect cloaking deltas, so crawl-time behavior is part of the signal.
10. Data quality, augmentation, and repair
- Several scripts focus on dataset integrity: verify_splits.py, repair_ids.py, backfill_*, auto_backfill.py, and audit_*.
- Augmentation and hard-negative generation are also built in (augment_js.py, augment_with_hard_negatives.py, prepare_hard_negatives.py).
- This suggests the repo treats label quality, missing fields, and modality gaps as core architectural concerns rather than afterthoughts.
11. Evaluation, diagnostics, and CI gates
- tests/ contains unit and integration coverage for calibration, fusion, normalization, token assembly, metrics, and pipeline correctness.
- Validation scripts like validate_pipeline.py, validate_all_fixes.py, and scripts/ci_gate.py indicate a formal quality gate around dataset and model changes.
- The repository also includes anomaly detection and coverage-audit scripts to find blind spots in modality availability and JS coverage.
12. Utilities, exports, and packaging
- src/phisdom/utils holds alignment, split handling, and prediction standardization helpers.
- tools/ contains operational utilities such as URL normalization and DOM-graph backfilling.
- Packaging is standard Python tooling (pyproject.toml, requirements.txt), with a lightweight CLI entrypoint in src/phisdom/cli.py for demo/inference use.
13. Mental model for an architecture diagram
- The cleanest diagram is a left-to-right flow:
- External feeds / crawled pages / cached metadata
- → normalization and enrichment
- → modality-specific feature extraction
- → per-head training/inference
- → fusion + calibration
- → evaluation, export, and CI validation
- The key boundary is between the offline data/training pipeline and the model-serving-facing scoring path, with calibration and threshold export bridging them.
Main entry points: fusion.py Fusion · heads.py Heads · multimodal.py Multimodal · calibration.py Calibration
Components 23
Data & ingest
External feeds, crawls, caches, and dataset assembly.
Core runtime
Stable Python package for data, features, models, metrics, and CLI.
- Normalize · Schema normalization, alignment, and multimodal joins.
src/phisdom/data/normalize.py - Schema · Canonical record layout for samples and labels.
src/phisdom/data/schema.py - Loader · Dataset loading and batching entrypoint for training and inference.
src/phisdom/data/loader.py - Multimodal · Combines URL, DOM/markup, text, and JS views into one sample.
src/phisdom/data/multimodal.py - URL features · Character n-grams, entropy, length, and related URL signals.
src/phisdom/features/url.py - Extractors · Shared feature extraction interfaces and helpers.
src/phisdom/features/extractors.py - Heads · Independent per-modality classifiers and head definitions.
src/phisdom/models/heads.py - DOM GCN · Specialized DOM/markup graph-based head variant.
scripts/train_dom_gcn.py - Fusion · Learned combination of modality outputs across fusion generations.
src/phisdom/models/fusion.py - Calibration · Probability calibration and thresholding for deployment-ready scores.
src/phisdom/calibration.py - Metrics · Shared metrics and scoring utilities.
src/phisdom/metrics.py - CLI · Lightweight command-line entrypoint for runtime usage.
src/phisdom/cli.py
Training pipeline
Operational scripts for crawl, train, fuse, calibrate, and export.
- Crawl · Browser-based crawling and external-page acquisition.
scripts/crawl_playwright.py - Ingest · Feed fetching, phish-only ingestion, and dataset merging.
scripts/ingest_phish_only.py - Train heads · Per-modality training scripts for URL, text, markup, and JS heads.
scripts/train_url_head.py - Fuse · Stacking, cross-attention, and meta-fusion training scripts.
scripts/train_fusion_xattn.py - Evaluate · Evaluation, plotting, anomaly review, and KPI reporting.
scripts/evaluate_enhanced.py - Export · Prediction export and operating-threshold export for downstream use.
scripts/export_predictions.py
Validation
Tests, audits, and CI gates for pipeline and model correctness.
Connections 24
- Feeds → Crawl: seed crawl · Feed definitions drive collection jobs.
- Crawl → Ingest: raw pages · Crawled pages are normalized into datasets.
- Caches → Normalize: enrich · Lookup caches supply DNS/RDAP/TLS metadata.
- Dataset → Normalize: inputs · Seed records and split definitions enter normalization.
- Normalize → Schema: shape · Normalization enforces the canonical record schema.
- Schema → Loader: load · Schema-backed records are loaded for runtime use.
- Loader → Multimodal: join · Loader assembles multimodal examples.
- Multimodal → URL features: URL path · URL view feeds URL feature extraction.
- Multimodal → Extractors: shared view · Common extractor interfaces operate on multimodal samples.
- URL features → Heads: features · URL features train or score the URL head.
- Extractors → Heads: features · Extractor outputs feed modality-specific heads.
- Heads → DOM GCN: specialize · DOM/markup head variants are trained separately when needed.
- Heads → Fusion: logits · Per-modality predictions are fused into a final score.
- DOM GCN → Fusion: graph logits · DOM graph outputs can participate in fusion.
- Fusion → Calibration: calibrate · Fusion scores are calibrated before export or thresholding.
- Calibration → Metrics: score · Calibrated outputs feed evaluation metrics.
- Metrics → Evaluate: report · Metrics power evaluation scripts and plots.
- Calibration → Export: thresholds · Calibration produces operating thresholds for deployment.
- Fusion → Export: predictions · Final scores are exported for downstream consumers.
- Train heads → Heads: fit · Training scripts produce the per-modality heads.
- Fuse → Fusion: fit · Fusion scripts train ensemble logic.
- Evaluate → CI gate: gate · Evaluation results are checked by validation gates.
- Tests → CI gate: assert · Tests backstop the validation pipeline.
- CLI → Fusion: infer · CLI can run scoring through the fused model path.