-
Notifications
You must be signed in to change notification settings - Fork 0
PROPERTY BASED TESTING
This document describes the property-based and fuzz testing strategy for security-critical code in nself-chat. These tests use the fast-check library to generate random inputs and verify security invariants.
Property-based tests verify that certain properties (invariants) hold true for all possible inputs:
- Determinism: Same input always produces same output
- Idempotence: Running operation multiple times has same effect as once
- Reversibility: Encrypt/decrypt roundtrips preserve original data
- Boundary Conditions: Edge cases are handled correctly
- No Exceptions: Functions never throw on valid input types
Fuzz tests use malformed, unexpected, or malicious inputs to find vulnerabilities:
- Injection Attempts: SQL, XSS, command injection patterns
- Protocol Bypasses: URL manipulation, encoding tricks
- Unicode Edge Cases: Emoji, RTL, zero-width characters
- Binary Edge Cases: Empty data, all zeros, very large inputs
Tests: 40+ property tests, 1000+ assertions
- β Accepts valid alphanumeric + underscore + hyphen (3-30 chars)
- β Rejects invalid characters
- β Rejects too short/long usernames
- β Never throws on any string input
- β Accepts valid email formats
- β Rejects emails without @ symbol
- β Rejects overly long emails (>255 chars)
- β Never throws on any string input
- β Enforces uppercase requirement
- β Enforces lowercase requirement
- β Enforces number requirement
- β Enforces special character requirement
- β Never throws on any string input
- β Always returns a string
- β
Removes all
<script>tags - β Removes onclick handlers
- β Preserves safe HTML tags
- β Never throws on any input
- β Escapes all HTML entities (<, >, &, etc.)
- β Never contains unescaped < or >
- β Always returns a string
- β Removes path traversal attempts (..)
- β Removes all forward/backslashes
- β Removes invalid filename characters (<>:"|?*)
- β Accepts HTTP/HTTPS URLs
- β Rejects javascript: protocol
- β Rejects data: protocol
- β Blocks localhost in production
- β Escapes LIKE pattern wildcards (%, _)
- β Validates SQL identifiers (no special chars)
- β Never allows unescaped wildcards
- β Removes all $operator keys
- β Preserves non-operator keys
- β Recursively sanitizes nested objects
- β Validates shell arguments (alphanumeric only)
- β Rejects shell metacharacters (&|;<>$`())
- β Escapes arguments with single quotes
- β Handles zero-width characters
- β Handles emoji and unicode symbols
- β Handles RTL override characters
- β Handles combining characters
Tests: 35+ property tests, 800+ assertions
- β Accepts HTTP and HTTPS
- β Rejects javascript: protocol
- β Rejects data: protocol
- β Rejects file: protocol
- β Rejects ftp: protocol
- β Blocks "localhost" hostname
- β Blocks 127.0.0.1
- β Blocks IPv6 localhost (::1)
- β Blocks all 127.x.x.x range
- β Blocks 10.x.x.x range
- β Blocks 192.168.x.x range
- β Blocks 172.16-31.x.x range
- β Blocks 169.254.x.x link-local range
- β Blocks 169.254.169.254 (AWS/GCP/Azure)
- β Blocks 100.100.100.200 (Alibaba Cloud)
- β Blocks metadata hostnames
- β Handles IPv6 addresses with brackets
- β Blocks private IPv6 ranges
- β Blocks IPv4-mapped IPv6 localhost
- β Blocks IPv4-mapped IPv6 private IPs
- β Detects IP in decimal format
- β Detects IP in octal format
- β Detects IP in hex format
- β Handles @ symbol tricks
- β Handles backslash tricks
- β Never throws on any string input
- β Always returns result object with valid field
- β Provides reason when validation fails
- β Consistent results on repeated calls
Tests: 30+ property tests, 700+ assertions
- β Always returns an array
- β Preserves quoted strings
- β Handles escaped quotes
- β Splits on spaces outside quotes
- β Returns null for non-commands
- β Extracts simple commands (/cmd)
- β Extracts namespaced commands (app:cmd)
- β Handles commands with arguments
- β Validates string arguments (minLength, maxLength, pattern)
- β Validates number arguments (min, max, type)
- β Validates boolean arguments (true/false/yes/no/1/0)
- β Validates user mentions (@username)
- β Validates channel references (#channel)
- β Validates choices constraints
- β Handles command injection attempts (; && | `` $())
- β Handles SQL injection attempts (' OR '1'='1)
- β
Handles XSS attempts (<script>,
)
- β Handles path traversal attempts (../)
- β Handles unicode in command names
- β Handles emoji in arguments
- β Handles RTL override characters
- β Handles zero-width characters
Tests: 25+ property tests, 500+ assertions
- β Generates bytes of requested length
- β Generates different bytes each call
- β Device IDs are 32 hex characters
- β Device IDs are unique
- β Registration IDs within 14-bit range (0-16383)
- β SHA-256 produces deterministic hashes
- β SHA-256 produces 32-byte hashes
- β Different inputs produce different hashes
- β SHA-512 produces 64-byte hashes
- β Fingerprints are consistent
- β Consistent keys from same password+salt
- β Keys are correct length (32 bytes)
- β Different passwords produce different keys
- β Different salts produce different keys
- β Verifies correct master keys
- β Rejects incorrect master keys
- β Encrypts to different ciphertext each time (random IV)
- β IVs are correct length (12 bytes)
- β Encoded data includes IV + ciphertext
- β Handles empty byte arrays
- β Handles very large byte arrays (1MB+)
- β Handles all-zero byte arrays
- β Handles all-ones byte arrays
- β Handles repeating patterns
- β Handles weak passwords
- β Handles very long passwords (10KB+)
- β Handles special characters
- β Handles null bytes
- β Handles emoji passwords
Tests: 35+ property tests, 900+ assertions
- β Masking preserves prefix/suffix
- β Email masking preserves domain
- β Phone masking preserves last 4 digits
- β Truncation respects max length
- β Detects high-entropy strings
- β Detects secret prefixes (sk_, pk_, ghp_, AKIA)
- β Does not flag normal words
- β Always returns result object
- β Never throws on any log entry
- β Redacts password fields
- β Hashes session IDs
- β Masks email addresses
- β Preserves user IDs
- β Detects JWT tokens
- β Detects Bearer tokens
- β Detects IPv4 addresses
- β Detects AWS access keys
- β Detects credit card numbers
- β Recursively sanitizes nested objects
- β Sanitizes arrays of objects
- β Handles circular references
- β Handles emoji in messages
- β Handles RTL characters
- β Handles zero-width characters
- β Handles mixed scripts
# Run all property-based tests
pnpm jest --testNamePattern="Property Tests|Fuzz Tests"
# Run with coverage
pnpm jest --coverage --testNamePattern="Property Tests|Fuzz Tests"# Input validation
pnpm jest src/lib/security/__tests__/input-validation.property.test.ts
# SSRF protection
pnpm jest src/lib/security/__tests__/ssrf-protection.property.test.ts
# Command parser
pnpm jest src/lib/plugins/slash-commands/__tests__/command-parser.property.test.ts
# E2EE crypto
pnpm jest src/lib/e2ee/__tests__/crypto.property.test.ts
# Log sanitizer
pnpm jest src/lib/privacy/__tests__/log-sanitizer.property.test.tsProperty tests are configured with different numRuns based on complexity:
- Simple properties: 2000 runs (e.g., "never throws")
- Standard properties: 1000 runs (e.g., determinism)
- Complex properties: 500 runs (e.g., nested validation)
- Expensive properties: 100 runs (e.g., async crypto operations)
- Very expensive: 10-20 runs (e.g., large data crypto)
| Test Suite | Tests | Runs per Test | Total Assertions |
|---|---|---|---|
| Input Validation | 42 | 500-2000 | 50,000+ |
| SSRF Protection | 38 | 200-1000 | 20,000+ |
| Command Parser | 32 | 500-2000 | 35,000+ |
| E2EE Crypto | 28 | 20-1000 | 15,000+ |
| Log Sanitizer | 37 | 200-2000 | 30,000+ |
| TOTAL | 177 | varies | 150,000+ |
- β No SQL injection via user input
- β No XSS via HTML sanitization
- β No command injection via shell escaping
- β No NoSQL injection via operator filtering
- β No path traversal via filename sanitization
- β No localhost access
- β No private IP access
- β No cloud metadata access
- β No protocol bypasses
- β No DNS rebinding
- β Passwords always hashed with salt
- β Secrets detected and redacted in logs
- β PII masked or hashed
- β Session IDs hashed
- β Encryption uses random IVs
- β Keys derived with PBKDF2 (100K iterations)
- β Random generation uses crypto-secure PRNG
- β Hash functions are deterministic
- β Different inputs produce different hashes
- β Key verification uses constant-time comparison
- β All user input validated
- β Type coercion is safe
- β Length limits enforced
- β Pattern matching works correctly
- β Unicode handled safely
These property-based tests are run:
- On every commit (CI pipeline)
- Before every merge (PR checks)
- Nightly (extended runs with higher iteration counts)
- Before releases (full security audit)
-
Increase test coverage:
- Add property tests for more parsers
- Test more crypto operations
- Add fuzzing for API endpoints
-
Performance testing:
- Add property tests for time complexity
- Verify no ReDoS vulnerabilities in regex
- Test memory usage under load
-
Integration testing:
- Property tests across module boundaries
- End-to-end security flows
- Real-world attack scenarios
-
Continuous fuzzing:
- Integrate with OSS-Fuzz
- Run fuzzing on CI infrastructure
- Automated security regression testing
nself-chat v0.3.0 | GitHub | Issues | Discussions | Demo
Edit this page | MIT License | Β© 2026
(See π Security section below for 2FA, PIN Lock, and security audits.)
(Search lives in π Reference below.)
- π¬ Advanced Messaging
- π E2EE Setup
- π Search Setup
- π Call Management
- πΊ Live Streaming
- π₯οΈ Screen Sharing
- πΉ Video Calling
- ποΈ Voice Calling
- π± Mobile Optimization
- π§ͺ Testing
- π i18n
- π API Overview
- π Complete Reference
- π» API Examples
- π€ Bot API
- π Auth API
- π GraphQL Schema
- π Deployment Overview
- π³ Docker
- βΈοΈ Kubernetes
- β Helm Charts
- β Production Checklist
- π Production Validation
- π’ Multi-Tenant
- ποΈ Architecture
- π Diagrams
- ποΈ Database Schema
- π Project Structure
- π TypeScript Types
- π SPORT Reference
- π 2FA
- π¬ Messaging
- π Call Management
- π Call State Machine
- π E2EE
- πΊ Live Streaming
- π± Mobile Calls
- π PIN Lock
- π Polls
- π₯οΈ Screen Sharing
- π Search
- π Social Media
- ποΈ Voice Calling
- π Security Overview
- π‘οΈ Security Audit
- β‘ Performance
- π Best Practices
- π 2FA
- π PIN Lock
- π E2EE
- π‘οΈ E2EE Audit
v1.0.0 β’ 2026