Mitigation Strategy: 1. Placeholder Replacement (Before Recording)
Description:
- Identify Sensitive Data: List all sensitive data in HTTP interactions (API keys, passwords, tokens, PII, etc.).
- Environment Variables/Secure Config: Store actual values in environment variables or a secure configuration store.
- Code Modification: Read sensitive values from environment variables/config store in your code. Use variable names, not literal values.
- 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 todefine_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. - Test Execution: Betamax replaces the environment variable name with the placeholder in the cassette during recording. The secret never appears.
- 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."]
Mitigation Strategy: 2. Cassette Scrubbing (After Recording)
Description:
- Identify Sensitive Data: (Same as above).
- Implement
before_record
Hook: Create a function called by Betamax after recording, before saving the cassette. It receives theinteraction
andcurrent_cassette
objects. - 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.
- Check request headers (e.g.,
- Betamax Configuration: Configure Betamax to use your
before_record
hook. - 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:
- Betamax Configuration: In your Betamax configuration, set
default_cassette_options
to includematch_requests_on
. - 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)
- 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."]