This extension implements a multi-layered security system for storing sensitive API keys (OpenAI, Anthropic, OpenRouter) using industry best practices and OWASP 2024/2025 guidelines.

High-Level Architecture

+------------------------------------------------------------------+
|                        User Interface                             |
+--------------------------------+---------------------------------+
                                 |
                                 v
+------------------------------------------------------------------+
|                      API Key Manager                              |
|  +--------------+  +---------------+  +----------------------+    |
|  |  Password    |  |    Rate       |  |    API Key           |    |
|  |  Validator   |  |   Limiter     |  |    Validator         |    |
|  +--------------+  +---------------+  +----------------------+    |
+--------------------------------+---------------------------------+
                                 |
            +--------------------+--------------------+
            v                    v                    v
+-------------------+ +--------------+ +----------------------+
|  Crypto Service   | |   Device     | |   Session Cache      |
|  (AES-GCM +       | |   Binding    | |   (chrome.storage    |
|   PBKDF2 800k)    | |   Service    | |    .session)         |
+---------+---------+ +------+-------+ +----------------------+
          |                  |
          v                  v
+------------------------------------------------------------------+
|              Secure Storage (chrome.storage.local)                |
|                    [Encrypted API Keys]                           |
+------------------------------------------------------------------+

Security Layers

Layer 1: Encryption at Rest

Layer 2: Device Binding

Layer 3: Rate Limiting

Layer 4: Session Caching

Layer 5: Password Requirements

Security Features

Timing Attack Protection

All decryption operations enforce a minimum execution time of 400ms to prevent timing-based password guessing attacks, even when keys don't exist.

Error Message Safety

External Communication Blocking

Session Management

Password Security

Validation Rules

  1. Length: 12-128 characters
  2. Character Types: Must contain at least 3 of:
    • Uppercase letters (A-Z)
    • Lowercase letters (a-z)
    • Numbers (0-9)
    • Special characters (!@#$%^&*)
  3. Quality Checks:
    • Not in common password list
    • No more than 3 consecutive identical characters
    • No sequential patterns (keyboard walks, alphabetical sequences)

Password Strength Scoring

Score Range Rating Description
0-29 Weak Does not meet minimum requirements
30-49 Fair Meets minimum but could be stronger
50-69 Good Strong password
70-100 Strong Excellent password

API Key Validation

Supported Providers

Provider Format Validation
OpenAI sk-*, sk-proj-*, sk-svcacct-* Regex pattern matching
Anthropic sk-ant-* Strict pattern matching
OpenRouter sk-or-v1-* 64-character suffix verification

Display Masking

API keys are masked when displayed: sk-pro********abc1

Content Security Policy

The extension enforces strict CSP to prevent injection attacks:

script-src 'self';              // Only allow scripts from extension
object-src 'none';              // Block plugins
base-uri 'none';                // Prevent base tag hijacking
connect-src 'self' [APIs];      // Restrict network requests
form-action 'none';             // Prevent form submissions
frame-ancestors 'none';         // Prevent framing

Cryptographic Implementation

Encryption Process

  1. Generate random 256-bit salt
  2. Generate random 96-bit IV
  3. Derive encryption key using PBKDF2:
    • Input: compound password (user password + device secret)
    • Salt: random salt
    • Iterations: 800,000
    • Hash: SHA-256
    • Output: 256-bit AES key
  4. Encrypt plaintext using AES-256-GCM
  5. Combine: salt || iv || ciphertext || auth_tag
  6. Encode as base64 for storage

Decryption Process

  1. Decode base64 ciphertext
  2. Extract: salt, IV, ciphertext, auth tag
  3. Derive decryption key using same PBKDF2 parameters
  4. Decrypt and verify authentication tag
  5. Return plaintext or throw DECRYPTION_ERROR

Threat Model & Mitigations

Threat: Brute Force Password Attack

Mitigation:
  • 800,000 PBKDF2 iterations (computationally expensive)
  • Rate limiting with exponential backoff
  • Account lockout after 5 attempts

Threat: Timing Attacks

Mitigation:
  • Minimum 400ms operation time for all decryption attempts
  • Constant-time comparisons where possible
  • PBKDF2 naturally normalizes timing

Threat: Key Extraction (Physical Access)

Mitigation:
  • Device binding prevents cross-machine usage
  • Keys never stored in plaintext
  • Session cache cleared on browser close

Threat: Extension Reinstallation

Mitigation:
  • New device salt generated on reinstall
  • Old keys become unrecoverable (by design)
  • User warnings about data loss

Threat: Content Script Injection

Mitigation:
  • Session storage set to TRUSTED_CONTEXTS only
  • External messaging blocked
  • Strict CSP prevents code injection

Threat: Man-in-the-Middle (API Calls)

Mitigation:
  • All API endpoints use HTTPS (enforced by CSP)
  • Host permissions restricted to specific domains

Compliance & Standards

This implementation follows:

Security Audit Checklist

Known Limitations

  1. JavaScript Memory: Cannot guarantee secure memory clearing due to language limitations. Garbage collector may leave traces of decrypted keys in memory.
  2. Browser Extensions: Extension storage can be accessed by users with physical access to the machine through browser developer tools (though keys are encrypted).
  3. Key Recovery: If a user forgets their password, there is no recovery mechanism. This is by design - no backdoors.
  4. Device Reinstall: Reinstalling the extension makes old encrypted keys permanently unrecoverable.
  5. Session Persistence Trade-off: When session persistence is enabled, the ephemeral session key is stored (encrypted) in session storage rather than memory-only. While still protected by encryption and device binding, this slightly reduces security in exchange for convenience.

Reporting Security Issues

If you discover a security vulnerability in this implementation, please report it via:

Please do not disclose security issues publicly until they have been addressed.

References

IMPORTANT: USE AT YOUR OWN RISK

While this extension implements industry-standard cryptographic practices and follows OWASP 2024/2025 security guidelines, no security system is completely infallible. By using this extension to store API keys, you acknowledge and accept the inherent security risks. You are solely responsible for choosing strong passwords, maintaining secure computing environments, monitoring API key usage, and rotating API keys regularly.