Skip to content

Fix: Improper Neutralization of Input During Escaping of Output Reflected cross-site scripting #22207

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

opsysdebug
Copy link

@opsysdebug opsysdebug commented Jul 26, 2025

return r.ResponseWriter.Write(data)

Directly writing user input (an HTTP request parameter) to an HTTP response without properly sanitizing the input first, allows for a cross-site scripting vulnerability.This kind of vulnerability is also called reflected cross-site scripting, to distinguish it from other types of cross-site scripting.

fix the reflected XSS vulnerability, we should ensure that any user-controlled data written to an HTTP response is properly escaped for HTML context. In this case, the Write method of ResponseRecorder should escape the data if it is being used to write log output that may contain user input. The best way to do this is to use Go's html.EscapeString function to sanitize the data before writing it to the response. Since Write receives a byte slice, we should convert it to a string, escape it, and then write the escaped string as bytes. This change should be made in src/lib/response_recorder.go, specifically in the Write method. need to import the html package in this file to use html.EscapeString.

Please indicate you've done the following:

  • Well Written Title and Summary of the PR
  • Label the PR as needed. "release-note/ignore-for-release, release-note/new-feature, release-note/update, release-note/enhancement, release-note/community, release-note/breaking-change, release-note/docs, release-note/infra, release-note/deprecation"
  • Accepted the DCO. Commits without the DCO will delay acceptance.
  • Made sure tests are passing and test coverage is added if needed.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed in website repository.

Signed-off-by: Zeroday BYTE <[email protected]>
@opsysdebug opsysdebug requested a review from a team as a code owner July 26, 2025 00:11
@MinerYang MinerYang requested a review from wy65701436 July 28, 2025 08:24
@reasonerjt reasonerjt assigned wy65701436 and unassigned Vad1mo Jul 28, 2025
@reasonerjt
Copy link
Contributor

Considering the usage case of ResponseRecorder, which is mainly for capturing the response of Harbor's API.
Is there really a case to potentially form this attack?

@reasonerjt
Copy link
Contributor

@wy65701436 Could you please double check and follow up?

Copy link

codecov bot commented Jul 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.69%. Comparing base (c8c11b4) to head (ad8d7d3).
⚠️ Report is 521 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #22207      +/-   ##
==========================================
+ Coverage   45.36%   46.69%   +1.32%     
==========================================
  Files         244      252       +8     
  Lines       13333    14248     +915     
  Branches     2719     2925     +206     
==========================================
+ Hits         6049     6653     +604     
- Misses       6983     7242     +259     
- Partials      301      353      +52     
Flag Coverage Δ
unittests 46.69% <ø> (+1.32%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 178 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants