Kalamari
Lightweight Headless Browser for Security Testing
Features | Installation | Quick Start | API Reference | Lonkero Integration
What is Kalamari?
Kalamari is a pure Rust headless browser designed specifically for XSS scanning, web crawling, and security testing. Unlike traditional headless browsers that require Chrome/Chromium binaries (~200MB+), Kalamari is entirely self-contained with minimal dependencies.
Built as a drop-in replacement for Chrome headless in security scanners like Lonkero.
Features
Core Browser
- Lightweight - ~10MB binary vs Chrome's 200MB+ footprint
- Fast Startup - No browser process to spawn, instant initialization
- Full DOM API - createElement, MutationObserver, localStorage, sessionStorage
- Cookie Management - Complete cookie jar with domain scoping and auth tokens
- Network Interception - CDP-like request/response capture with middleware chain
Security Testing
- XSS Detection - Built-in alert/confirm/prompt/eval interception
- Stored XSS Flow - Complete stored XSS detection with form submission
- CSP Analysis - Parse Content-Security-Policy, identify bypasses
- DOM Clobbering - Detect clobbering vectors and form hijacking
- SRI Checking - Identify missing/weak subresource integrity
Framework Support
- SPA Route Detection - Extract routes from Vue, React, Angular bundles
- WebSocket Discovery - Find WebSocket endpoints in JavaScript
- Framework Detectors - Identify v-html, dangerouslySetInnerHTML, ng-bind-html sinks
Performance
- Browser Pool - Parallel scanning with page pooling
- Metrics Collection - Request latencies, page counts, XSS triggers
- Real Timer Queue - Production-grade setTimeout/setInterval with unique IDs, clearTimeout/clearInterval, and flush_timers() for async JS control
- Console Capture - Real console.log/error/warn/info/debug capture for debugging
Lonkero Integration
Kalamari addresses all key integration requirements for Lonkero:
| Feature | Chrome-based | Kalamari |
|---|---|---|
| Binary size | ~200MB | ~10MB |
| Memory/page | ~100-300MB | ~10-20MB |
| Startup time | 1-3s | Instant |
| XSS detection | External | Built-in |
| Request interception | CDP Fetch | RequestInterceptor trait |
| Iframe support | Native | Recursive processing |
| MutationObserver | Native | JS stub |
| PDF generation | Native | Feature-gated |
| Auth session | Manual | AuthSession extractor |
| SPA routes | Manual | ScriptAnalyzer |
| WebSocket discovery | Manual | ScriptAnalyzer |
| Timer control | Native | TimerQueue |
| CSP analysis | Manual | CspAnalyzer |
| Parallel scanning | Thread pool | BrowserPool |
Installation
Add to your Cargo.toml:
[]
= "0.1"
# With optional features
= { = "0.1", = ["pdf", "websocket"] }
Or install the CLI:
Quick Start
Basic Usage
use ;
async
XSS Scanning
use ;
async
Stored XSS Detection
use ;
let test = new
.field
.reflect_at
.reflect_at;
let tester = new;
// Execute test via page methods
CSP Analysis
use ;
let analyzer = new;
let csp = "default-src 'self'; script-src 'self' 'unsafe-inline'";
let analysis = analyzer.parse;
println!;
println!;
for bypass in &analysis.bypasses
Parallel Scanning with Browser Pool
use BrowserPool;
use Arc;
async
Request Interception
use ;
async
Auth Session Extraction
use ;
async
SPA Route Detection
use ;
let analyzer = new;
let scripts = page.get_script_sources;
for script in &scripts
Framework Detection
use FrameworkDetector;
let detector = new;
let html = page.content?;
let scripts = page.get_script_sources;
let script_contents: = scripts.iter.map.collect;
let frameworks = detector.detect_all;
for fw in frameworks
CLI Usage
# Fetch a URL and display info
# Check for XSS vulnerabilities
# Crawl a website
# Extract forms
Architecture
┌──────────────────────────────────────────────────────────────┐
│ KALAMARI BROWSER │
├──────────────────────────────────────────────────────────────┤
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────────┐ │
│ │ HTTP Layer │ │ DOM Engine │ │ JS Runtime │ │
│ │ (reqwest) │──│ (html5ever) │──│ (boa_engine) │ │
│ └──────────────┘ └──────────────┘ └──────────────────┘ │
│ │ │ │ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────────┐ │
│ │ Interceptor │ │ Iframe │ │ XSS Detection │ │
│ │ Chain │ │ Handler │ │ (alert hooks) │ │
│ └──────────────┘ └──────────────┘ └──────────────────┘ │
│ │ │ │ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────────┐ │
│ │ Cookie │ │ Form │ │ Security │ │
│ │ Jar │ │ Extractor │ │ (CSP, SRI) │ │
│ └──────────────┘ └──────────────┘ └──────────────────┘ │
└──────────────────────────────────────────────────────────────┘
API Reference
Browser Module
| Type | Description |
|---|---|
Browser |
Main browser instance |
Page |
Individual page/tab |
BrowserPool |
Pool for parallel scanning |
BrowserMetrics |
Performance metrics |
Security Module
| Type | Description |
|---|---|
CspAnalyzer |
CSP parsing and bypass detection |
SriChecker |
Subresource integrity validation |
DomClobberDetector |
DOM clobbering detection |
XSS Module
| Type | Description |
|---|---|
XssDetector |
XSS trigger detection |
StoredXssTest |
Stored XSS test configuration |
PayloadGenerator |
XSS payload generation |
Network Module
| Type | Description |
|---|---|
RequestInterceptor |
Request/response middleware |
NetworkEvent |
Captured network events |
AuthHeaderInjector |
Auth header injection |
Feature Flags
| Feature | Description | Dependencies |
|---|---|---|
default |
Core functionality | None |
websocket |
WebSocket support | tokio-tungstenite |
pdf |
PDF generation (pure Rust) | printpdf |
full |
All features | All above |
Dependencies
| Crate | Purpose |
|---|---|
boa_engine |
JavaScript execution (pure Rust) |
html5ever |
HTML parsing (spec-compliant) |
reqwest |
HTTP client (rustls TLS) |
tokio |
Async runtime |
Limitations
Kalamari is optimized for security testing, not full browser emulation:
- No visual rendering - CSS layout/painting not implemented
- No WebGL/Canvas - Graphics APIs not supported
- Timer execution - setTimeout/setInterval use real TimerQueue with unique IDs; use
flush_timers()orexecute_ready_timers()to execute - No plugins - Flash, PDF viewer, etc. not supported
License
Copyright (c) 2026 Bountyy Oy. All rights reserved.
This software is licensed under the Bountyy Oy Source-Available License. You may view, study, and use the software for personal, non-commercial purposes. Commercial use requires a separate license agreement.
See LICENSE for full terms. For licensing inquiries: info@bountyy.fi