Skip to content

feat: Add secret redaction via TEST_SERVER_SECRETS#4

Merged
amirh merged 3 commits intomainfrom
amirh/secrets1
May 9, 2025
Merged

feat: Add secret redaction via TEST_SERVER_SECRETS#4
amirh merged 3 commits intomainfrom
amirh/secrets1

Conversation

@amirh
Copy link
Copy Markdown
Collaborator

@amirh amirh commented May 8, 2025

This commit introduces a new feature to redact sensitive information from recorded requests and responses based on a list of secrets provided via the environment variable.

Secrets specified in (comma-separated) will be replaced with REDACTED in the request path, headers, and body during both recording and replaying. This redaction happens before the request checksum is computed, ensuring that recordings with secrets can still be replayed correctly.

@amirh amirh requested review from Annhiluc and hkt74 May 8, 2025 02:49
}

// Redact replaces occurrences of specified secrets in the response.
func (r *RecordedResponse) Redact(secrets []string) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems similar to the Redact() defined above for the request. Any chance for code deduplication?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I moved the redaction logic to its own object.

@amirh amirh force-pushed the amirh/secrets1 branch from 19ac48f to cbc3c36 Compare May 8, 2025 22:57
@amirh amirh requested a review from Annhiluc May 8, 2025 22:58
}

recordedRequest.RedactHeaders(r.config.RedactRequestHeaders)
r.redactor.Headers(recordedRequest.Header)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are line 104 and 106 duplicate?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, the previous line here was actually redacting headers by key, fixed.

expectedHeaders http.Header
}{
{
name: "Redact secret in single header value",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it support redact by header keys?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Headers by key are redacted by request/response.RedactHeaders.
Since this object is one per server, while the redacted headers are one list per endpoint it doesn't help much to do it in redactor object.
The secrets list is one per server so it fits here.

amirh added 3 commits May 9, 2025 07:08
This commit introduces a new feature to redact sensitive information from recorded requests and responses based on a list of secrets provided via the  environment variable.

Secrets specified in  (comma-separated) will be replaced with REDACTED in the request path, headers, and body during both recording and replaying. This redaction happens before the request checksum is computed, ensuring that recordings with secrets can still be replayed correctly.
@amirh amirh force-pushed the amirh/secrets1 branch from cbc3c36 to dcd7d1f Compare May 9, 2025 14:09
@amirh amirh requested a review from hkt74 May 9, 2025 14:09
@amirh amirh merged commit 90abfe3 into main May 9, 2025
2 checks passed
@amirh amirh deleted the amirh/secrets1 branch May 9, 2025 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants