Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

otel: redact sensitive query parameters before recording http.url

未关闭
#4,655 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@sai5880 已经在做这个了。

开始于 2026年10月21日。

  • #4659 来自 @sai5880 —— 未关闭

评估

难度
4/5
预计耗时
1-2 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go

调研方向

Start with otel/transport.go and the existing URL tests in otel/transport_test.go, then read sensitiveParams and sanitizeURL in github/github.go. Add coverage for query credentials and URL userinfo, ensuring the URL recorded in http.url is redacted without changing the request URL sent by the transport. Done means the span no longer exposes those secrets and the existing query free URL behavior remains covered.

由索引模型根据 Issue 内容生成。

描述

Summary

The OpenTelemetry transport records the full request URL, including query string and userinfo, in the http.url span attribute. go-github already treats certain query parameters as sensitive and redacts them on error paths, but the OTel instrumentation bypasses that redaction, so those values are exported to tracing/APM backends.

Location

  • otel/transport.go:61-66 (attribute set)
  • github/github.go:1964 (sensitiveParams)
  • github/github.go:1966-1984 (sanitizeURL)

At HEAD (2190e6a):

	// Inject Attributes
	span.SetAttributes(
		attribute.String("http.method", req.Method),
		attribute.String("http.url", req.URL.String()),
		attribute.String("http.host", req.URL.Host),
	)

Details

req.URL.String() is the raw request URL. For requests that carry credentials in the query string, or that include userinfo, the resulting span attribute contains the secret verbatim:

http.url = https://api.github.com/user/repos?access_token=ghp_abc123&page=1
http.url = https://user:[email protected]/user

The github package already classifies exactly these parameters as sensitive:

var sensitiveParams = []string{"client_secret", "access_token", "token"}

// sanitizeURL redacts sensitive parameters from the URL which may be
// exposed to the user.
func sanitizeURL(uri *url.URL) *url.URL {
	...
	for _, p := range sensitiveParams {
		if len(params.Get(p)) > 0 {
			params.Set(p, "REDACTED")
			redacted = true
		}
	}
	...
}

That helper is applied at github/github.go:1482, 1777, 1849, 1907, 1948 and 1949, i.e. only in error and redirect handling. The OTel transport is a separate package and never applies it. Note also that sanitizeURL handles query parameters only; it does not strip url.User, which URL.String() renders as user:password@host.

otel/transport_test.go asserts http.url for a query-free URL (https://api.github.com/users/google), so nothing currently guards this behavior.

Impact

Any application that wraps the go-github client with otel.NewTransport and calls endpoints that pass credentials via query parameters (for example OAuth token exchange with client_secret, or legacy calls passing access_token) writes those secrets into every span attribute set. Span attributes are typically exported to a tracing backend, sampled into logs, and retained for days, which turns a short-lived token into a long-lived copy in a third-party system. It also defeats the existing redaction guarantee, since the same URL appears redacted in an error message and unredacted in the span for the same request.

Signed URL parameters (for example pre-signed download links returned by some endpoints and then re-requested) are likewise recorded in full.

Suggested fix

Reuse one shared sanitation helper instead of duplicating the parameter list:

  1. Export a helper from the github package (for example github.SanitizeURL or a small github.RedactURL returning a string) that applies sensitiveParams and, ideally, also clears url.User. Have the existing sanitizeURL and the OTel transport both call it.
  2. In otel/transport.go, record the sanitized value, or record only scheme, host and path:
	u := *req.URL
	u.User = nil
	u.RawQuery = "" // or apply the shared redaction helper
	span.SetAttributes(
		attribute.String("http.method", req.Method),
		attribute.String("http.url", u.String()),
		attribute.String("http.host", req.URL.Host),
	)

Note that simply calling the existing sanitizeURL is not safe from otel: it mutates uri.RawQuery in place (see the open issue about this mutation), which would rewrite the request URL that is actually sent. Copy the URL first, or fix the mutation separately.

Also worth considering url.full from the current OpenTelemetry semantic conventions, which supersedes http.url, and documenting that recorded URLs are redacted.

Add a regression test:

req := httptest.NewRequest("GET", "https://api.github.com/user?access_token=secret", nil)
// ... RoundTrip, then assert:
// attrs["http.url"].AsString() == "https://api.github.com/user?access_token=REDACTED"

Verification

Static review only. I read otel/transport.go, otel/transport_test.go, and the sensitiveParams / sanitizeURL code in github/github.go at commit 2190e6a (2026-10-21). No runtime proof of concept was executed and no exporter was run; the exposure follows directly from req.URL.String() being placed into a span attribute with no redaction step.

主要语言
Go
星标
11.3k
派生
2.6k
平均合并
2 天 8 小时
30 天内合并 PR
38

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

google/go-github 的其他 Issue

查看 google/go-github 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。