Skip to content

Latest commit

 

History

History
82 lines (63 loc) · 5.25 KB

File metadata and controls

82 lines (63 loc) · 5.25 KB

Mitigation Strategies Analysis for betamaxteam/betamax

Description:

  1. Identify Sensitive Data: List all sensitive data in HTTP interactions (API keys, passwords, tokens, PII, etc.).
  2. Environment Variables/Secure Config: Store actual values in environment variables or a secure configuration store.
  3. Code Modification: Read sensitive values from environment variables/config store in your code. Use variable names, not literal values.
  4. Betamax Configuration: Use define_cassette_placeholder in your Betamax configuration (e.g., pytest fixture). For each sensitive element, define a placeholder (e.g., <API_KEY>). The value passed to define_cassette_placeholder should be the environment variable name (or secure config key), not the secret value. Provide a safe default if the variable isn't set.
  5. Test Execution: Betamax replaces the environment variable name with the placeholder in the cassette during recording. The secret never appears.
  6. Playback: Betamax replaces the placeholder with the environment variable's value (or the default) during playback.

Threats Mitigated:

  • Exposure of Secrets in Version Control: (Severity: Critical)
  • Exposure of Secrets in Build Artifacts: (Severity: Critical)
  • Exposure of Secrets to Unauthorized Personnel: (Severity: High)
  • Accidental Disclosure of Secrets: (Severity: High)

Impact:

  • Exposure of Secrets in Version Control: Risk reduced to Near Zero.
  • Exposure of Secrets in Build Artifacts: Risk reduced to Near Zero.
  • Exposure of Secrets to Unauthorized Personnel: Risk significantly reduced.
  • Accidental Disclosure of Secrets: Risk significantly reduced.

Currently Implemented: [e.g., "Implemented in tests/conftest.py for API keys and database credentials."]

Missing Implementation: [e.g., "Not yet implemented for PII in user profile responses. Need placeholders for email/phone."]

Description:

  1. Identify Sensitive Data: (Same as above).
  2. Implement before_record Hook: Create a function called by Betamax after recording, before saving the cassette. It receives the interaction and current_cassette objects.
  3. Redaction Logic: In the before_record hook, implement logic to identify and redact sensitive data:
    • Check request headers (e.g., Authorization, Cookie).
    • Parse request/response bodies (JSON, XML) and replace sensitive values.
    • Modify URLs with sensitive parameters.
    • Replace data with placeholders (e.g., <REDACTED>) or generic values.
  4. Betamax Configuration: Configure Betamax to use your before_record hook.
  5. Test Execution: Betamax calls your hook after each interaction, modifying data in memory before writing to the cassette.

Threats Mitigated:

  • Exposure of Secrets in Version Control: (Severity: High)
  • Exposure of Secrets in Build Artifacts: (Severity: High)
  • Exposure of Secrets to Unauthorized Personnel: (Severity: Medium)
  • Accidental Disclosure of Secrets: (Severity: Medium)

Impact:

  • Exposure of Secrets in Version Control: Risk reduced, but a small vulnerability window exists.
  • Exposure of Secrets in Build Artifacts: Risk reduced, but a small vulnerability window exists.
  • Exposure of Secrets to Unauthorized Personnel: Risk moderately reduced.
  • Accidental Disclosure of Secrets: Risk moderately reduced.

Currently Implemented: [e.g., "Implemented in tests/utils/betamax_hooks.py to redact Authorization headers."]

Missing Implementation: [e.g., "Need scrubbing for request/response bodies to handle sensitive data in JSON."]

Mitigation Strategy: 3. Strict Request Matching

Description:

  1. Betamax Configuration: In your Betamax configuration, set default_cassette_options to include match_requests_on.
  2. Specify Matching Criteria: Set match_requests_on to a list of all relevant request attributes for matching:
    • 'method' (GET, POST, PUT, etc.)
    • 'uri' (the full URL)
    • 'headers' (request headers)
    • 'body' (request body)
  3. Test Execution: Betamax uses a recorded interaction only if all specified attributes match the current request exactly during playback.

Threats Mitigated:

  • Unexpected Behavior Due to API Changes: (Severity: High)
  • Security Vulnerabilities Due to API Changes: (Severity: Medium)
  • Incorrect Test Results: (Severity: Medium)

Impact:

  • Unexpected Behavior Due to API Changes: Risk significantly reduced.
  • Security Vulnerabilities Due to API Changes: Risk moderately reduced.
  • Incorrect Test Results: Risk significantly reduced.

Currently Implemented: [e.g., "Implemented globally in tests/conftest.py to match on method, URI, and headers."]

Missing Implementation: [e.g., "Need to add 'body' to match_requests_on for full request matching."]