CodeQL flags r.Host reaching slog in the forward proxy's debug/warn lines

Đang mở
#1,612 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@evaline-ju đang làm issue này rồi.

Từ ngày 30/10/2026.

  • #1616 của @evaline-ju — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
70/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
backend, security

Hướng nghiên cứu

Start in core/listener/forwardproxy/server.go and inspect the listed slog call sites around lines 546, 739, 742, 820, 848, 2045, 2049, 2099, 2163, 2261 and 2340. Add a sanitizedHost(r) helper that removes newlines and carriage returns from r.Host, then use it at each logging site. Run the forwardproxy package tests, e.g. go test ./core/listener/forwardproxy, and confirm every flagged call now logs the sanitized host.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Problem

CodeQL (go/log-injection, medium) flags r.Host reaching slog.* calls in core/listener/forwardproxy/server.go. The alert surfaced on #1599 (alert #323) but the flagged flow is pre-existing — the PR's changes shifted line numbers; the vulnerable statements are unchanged.

Call sites on main where r.Host is passed as a log attribute without sanitization:

  • core/listener/forwardproxy/server.go:546 (buffered request body)
  • :739 (client went away before the upstream answered)
  • :742 (upstream request failed)
  • :820 (text/event-stream responses will use the buffered path)
  • :848 (text/event-stream response with a ReadsBody plugin that is not a StreamingResponder)
  • :2045 (response body read error)
  • :2049 (response body too large)
  • :2099 (streaming response ended by client hangup)
  • :2163 (ResponseWriter does not support flushing)
  • :2261 (streaming write error)
  • :2340 (streaming write error)

r.Host on an HTTP request is set from the Host header (or request-line authority for CONNECT), so a client can embed newlines or other control characters and inject forged log lines.

Status

CodeQL only reports flows that pass through PR-changed lines, so these alerts fire sporadically — any PR that edits code on a path to one of these log sites will raise them again. Same mechanic as #1533, different source and sink.

Fix

Either:

  1. Sanitize at the source — a sanitizedHost(r) helper that strips \n/\r from r.Host, used at every log site. CodeQL recognises strings.ReplaceAll as a log-injection sanitizer (per #1533).
  2. Add a path-scoped query-filters entry in .github/codeql/codeql-config.yml with a written reason, if the maintainers judge the sites low-risk enough to suppress.

Option 1 is the honest fix and keeps the alerts from recurring.

Found while reviewing CodeQL alert #323 on #1599.

Ngôn ngữ chính
Go
Star
21
Fork
43
Merge trung bình
13 giờ 32 phút
Pull request đã merge (30 ngày)
256

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rossoctl/cortex

Tất cả issue của rossoctl/cortex

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.