How Go's url.Error writes query strings to logs and how to mask them
When a Go http.Client request fails before a response arrives, such as on a timeout or connection refused, it returns a url.Error[1] whose URL field holds the full request address, including the query string[2]. The standard library removes only a password from that address, so logging this error as is also writes the query values to the log; during a check before switching to a real account, the author found 4,899 lines with account numbers in one log file (two test accounts). The author cut the query from the error's URL, rebuilt the same url.Error to keep cause identification, kept only diagnostic fields for non-200 response bodies, and wrote masking[3] tests that list the values that must not appear and the paths and causes that must remain.
Read the original velog.ioDiscussion on GeekNews
Discussion
Commenters mainly discuss the cost of removing the whole query. One suggests keeping only an allowlist of keys so that failure analysis still works, and the author replies that dropping the whole query also removes the conditions of other lookups from the logs, and asks how others handle this.
Sources
-
KRGeekNews KO
Go url.Error가 쿼리 문자열을 로그에 남기는 경로와 마스킹 방법


