Skip to content

Security: windowsworldcartoon/NetNavigator

Security

SECURITY.md

Network Scanner Security Implementation

Overview

This document outlines the comprehensive security measures implemented in the Network Scanner tab.


Security Layers

1. Input Validation & Sanitization

Strict Type Checking

  • All inputs validated for correct type (string, number)
  • No loose equality or implicit type coercion

IP Address Validation

  • Regex pattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$
  • Validates strict IPv4 format (e.g., 192.168.1.1)
  • Rejects incomplete IPs, non-numeric characters

Subnet Mask Validation

  • Whitelist of valid subnet masks only
    • 255.0.0.0
    • 255.255.0.0
    • 255.255.255.0
    • 255.255.255.128, .192, .224, .240, .248, .252, .254, .255

Port Validation

  • Range: 1-65535 (valid port range)
  • Start port <= end port requirement
  • Type validated as integer

Timeout Validation

  • Range: 100-5000 milliseconds
  • Prevents DOS with extremely high/low values

Thread Count Validation

  • Range: 1-50 threads
  • Prevents resource exhaustion

Hostname/Domain Validation

  • Regex pattern for valid domain names
  • Prevents special characters
  • Max length: 255 characters

2. Injection Prevention

Command Injection Detection

Blocks dangerous patterns:

  • Shell metacharacters: ;, &, |, `, $, (, )
  • Path traversal: ../
  • System paths: /etc/, /proc/
  • Windows commands: cmd.exe, powershell, bash

CSV Formula Injection Prevention

  • Escapes leading characters: =, +, -, @
  • Escapes double quotes with ""
  • Prevents CSV injection attacks

3. Output Encoding & XSS Prevention

Safe DOM Rendering

  • Uses textContent instead of innerHTML for user-controlled data
  • Manually constructs DOM with createElement()
  • HTML escaping function:
    &  &amp;
    <  &lt;
    >  &gt;
    " → &quot;
    '  &#039;

Result Display Protection

  • All hostnames escaped before rendering
  • All IP addresses escaped (defense in depth)
  • Port numbers converted to string and joined safely

4. Rate Limiting

Scanner Rate Limiter

  • Window: 1 second
  • Max Requests: 5 per second per user
  • Prevents: DOS attacks, spam scanning

Rate Limit Check

if (!SecurityManager.checkRateLimit('scanner')) {
    // Reject scan request
    // Log security event
}

5. Security Logging & Audit Trail

Logged Events

  1. SCAN_INITIATED - Scan started with parameters
  2. SCAN_RESULTS_DISPLAYED - Results shown to user
  3. CSV_EXPORT - Data exported
  4. INVALID_INPUT - Bad input received (reason logged)
  5. INJECTION_ATTEMPT - Malicious pattern detected
  6. RATE_LIMIT_EXCEEDED - Too many requests
  7. SCAN_ERROR - Error occurred during scan
  8. CSV_EXPORT_ERROR - Export failed
  9. SCANNER_RATE_LIMIT - Rate limit triggered

Audit Log Details

Each entry contains:

  • Timestamp (ISO 8601)
  • Event type
  • Details (JSON stringified)
  • User agent
  • Limited to 1000 most recent entries

Access Audit Log

SecurityManager.getAuditLog() // Returns filtered log
SecurityManager.clearAuditLog() // Clears log

6. Error Handling

Sanitized Error Messages

  • Error text escaped before display
  • No stack traces shown to user
  • Detailed errors logged only in console/audit

Error Display Format

  • Safe HTML construction
  • Clear error styling
  • No dangerous content rendering

7. Data Protection

CSV Export Security

  • Values escaped for formula injection
  • Quotes properly escaped
  • Safe file download with cleanup
  • Blob-based download prevents URL exposure

Result Data

  • No sensitive system paths exposed
  • Port numbers only (no service names)
  • Hostnames (if resolved) are safe
  • MAC addresses disabled for security

8. Resource Limits

Scan Configuration Limits

  • IP Range: Full subnet (256 IPs)
  • Port Range: 1-65535 (customizable per-scan)
  • Threads: 1-50 (parallel scanning)
  • Timeout: 100-5000ms per IP
  • Max Results: Unlimited (filtered UI display)

Memory Protection

  • Audit log capped at 1000 entries
  • Results held in memory only during session
  • File downloads use Blob API
  • URL objects properly revoked

9. Network Security Features

Optional Features (User Configurable)

  • ✓ Ping hosts (ICMP)
  • ✓ Check common ports
  • ☐ Resolve hostnames (DNS)
  • ☐ Get MAC addresses (disabled)

Each feature requires explicit user consent


10. UI Security

Input Field Protection

  • Trimmed whitespace
  • Type validation on form inputs
  • Disabled buttons during active scan
  • Clear visual feedback

Visual Security Indicators

  • Online/offline status badges
  • Color-coded results
  • Progress bar with percentage
  • Real-time statistics

Implementation Checklist

  • Strict input validation
  • Type checking
  • Regex pattern matching
  • Whitelist approach (subnet masks)
  • Command injection prevention
  • CSV formula injection prevention
  • XSS prevention (textContent, createElement)
  • HTML escaping
  • Rate limiting
  • Audit logging
  • Error sanitization
  • Resource limits
  • Safe file downloads
  • Memory management
  • User consent for features

Testing Recommendations

Input Fuzzing

// Test injection attempts
testInputs = [
    '192.168.1.1; rm -rf /',
    '192.168.1.1` cat /etc/passwd `',
    '192.168.1.1$(whoami)',
    '=2+5',  // CSV injection
    '<img src=x onerror=alert()>'  // XSS
];

Rate Limit Testing

// Trigger rate limiting
for (let i = 0; i < 10; i++) {
    scanBtn.click(); // Should be blocked after 5
}

Audit Log Testing

// Verify logging
console.log(SecurityManager.getAuditLog());

Security Best Practices Followed

  1. Defense in Depth - Multiple validation layers
  2. Whitelist Approach - Allow only known-good values
  3. Fail Secure - Errors reject input, not accept it
  4. Minimal Disclosure - Users see safe, generic error messages
  5. Audit Trail - All security events logged
  6. Input Validation - Strict before processing
  7. Output Encoding - Safe before display
  8. Resource Limits - Prevent DOS attacks
  9. User Consent - Optional features require user choice
  10. Code Review Ready - Clear, documented security code

Compliance

This implementation follows:

  • OWASP Top 10 protection principles
  • CWE (Common Weakness Enumeration) guidelines
  • Electron Security Best Practices
  • CSP (Content Security Policy) concepts

Maintenance

Regular Reviews

  • Review audit logs weekly
  • Check for attack patterns
  • Update validation patterns quarterly
  • Test injection attempts monthly

Update Checklist

  • Keep Node.js updated
  • Keep Electron updated
  • Update security patterns
  • Review new CVEs
  • Test with new attack vectors

Support

For security issues or vulnerabilities:

  1. Document the issue
  2. Check audit logs
  3. Review validation logic
  4. Test with safe inputs
  5. Contact maintainers

Do not publicly disclose security vulnerabilities.

There aren’t any published security advisories