-
Notifications
You must be signed in to change notification settings - Fork 53
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
fix: mock body render missing context #630
Conversation
|
There are 1 test cases, failed count 0:
Reported by api-testing. |
} else { | ||
if h.item.Response.BodyData, err = render.RenderAsBytes("start-item", h.item.Response.Body, h.item); err != nil { | ||
fmt.Printf("failed to render body: %v", err) | ||
} |
Check warning
Code scanning / CodeQL
Reflected cross-site scripting Medium
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 4 days ago
To fix the reflected cross-site scripting vulnerability, we need to ensure that any user-controlled data is properly sanitized or escaped before being written to the HTTP response. In this case, we can use the html.EscapeString
function from the html
package to escape any potentially dangerous characters in the response body.
- We will modify the
writeResponse
function to escape thedata
before writing it to the response. - This change will be made in the
pkg/mock/in_memory.go
file. - We need to import the
html
package to use thehtml.EscapeString
function.
-
Copy modified line R41 -
Copy modified lines R367-R368
@@ -40,2 +40,3 @@ | ||
"github.com/gorilla/mux" | ||
"html" | ||
) | ||
@@ -365,3 +366,4 @@ | ||
if err == nil { | ||
w.Write(data) | ||
escapedData := html.EscapeString(string(data)) | ||
w.Write([]byte(escapedData)) | ||
} else { |
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesCodacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more |
What type of PR is this?
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #