-
Notifications
You must be signed in to change notification settings - Fork 61
feat: support echo the request and response in mock server #820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -178,6 +178,16 @@ | |
| fmt.Println("after patch:", string(requestBody)) | ||
| } | ||
|
|
||
| if proxy.Echo { | ||
| fmt.Println("Original request header:") | ||
| for k, v := range req.Header { | ||
| fmt.Println(k, ":", v) | ||
| } | ||
| fmt.Println("Original request path:", req.URL) | ||
| fmt.Println("Original request payload:") | ||
| fmt.Println(string(requestBody)) | ||
Check noticeCode scanning / SonarCloud Logging should not be vulnerable to injection attacks Low
Change this code to not log user-controlled data. See more on SonarQube Cloud
|
||
| } | ||
|
|
||
| targetReq, err := http.NewRequestWithContext(req.Context(), req.Method, api, bytes.NewBuffer(requestBody)) | ||
| if err != nil { | ||
| w.WriteHeader(http.StatusInternalServerError) | ||
|
|
@@ -206,6 +216,12 @@ | |
| for k, v := range resp.Header { | ||
| w.Header().Add(k, v[0]) | ||
| } | ||
|
|
||
| if proxy.Echo { | ||
| fmt.Println("Original response payload:") | ||
| fmt.Println(string(data)) | ||
| } | ||
|
|
||
| w.Write(data) | ||
| }) | ||
| } | ||
|
|
@@ -580,6 +596,15 @@ | |
| } | ||
| } | ||
|
|
||
| if wh.Request.BodyFromFile != "" { | ||
| if data, readErr := os.ReadFile(wh.Request.BodyFromFile); readErr != nil { | ||
| memLogger.Error(readErr, "failed to read file", "file", wh.Request.BodyFromFile) | ||
| return | ||
| } else { | ||
| wh.Request.Body = string(data) | ||
| } | ||
| } | ||
|
|
||
| var payload io.Reader | ||
| payload, err = render.RenderAsReader("mock webhook server payload", wh.Request.Body, wh) | ||
| if err != nil { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information High
Copilot Autofix
AI about 2 months ago
To fix the problem, we should prevent logging sensitive HTTP headers. The best practice is to either omit logging headers entirely, or to redact/obfuscate sensitive header values before logging them. When logging headers, we should maintain a denylist of sensitive header names (e.g.,
Authorization,Cookie,Set-Cookie,Proxy-Authorization) and mask their values if they're present.Specifically, in
pkg/mock/in_memory.go, within the loop starting at line 183, we should update the logging so that before printing each header, we check if it is sensitive; if so, print its value as<redacted>, else print its actual value. This can be done by a simple helper function that matches header names case-insensitively.Minimal changes are needed and no functionality should be lost (other than leaking secrets). We'll define the sensitive headers list in this code region and use it for redaction.