Opened 28 minutes ago
#25141 new defect
[PATCH] Debug logs & status report contain credentials
| Reported by: | wangi | Owned by: | team |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | Core | Version: | |
| Keywords: | credentials authorization oauth | Cc: |
Description
The debug logs and status report contain credentials: Authorization header, cookies, OAuth client secret, API keys. With --debug, HttpClient logs the request and response headers as they are:
FINE: REQUEST HEADERS: {Accept=application/xml, */*;q=0.8, Accept-Encoding=gzip, deflate, Authorization=Bearer <the OAuth 2.0 access token>}
So the log holds the credentials of every authenticated request: the OAuth 2.0 bearer token, or with basic authentication the base64 of user name and password, which is the password in all but name. Proxy-Authorization is logged the same way, and the response headers show session cookies in Set-Cookie. With --trace, the body of a request is logged as it is too; for an OAuth 2.0 token request that is the client secret, the authorization code and its verifier, or a refresh token.
Debug and trace logs are what users can be asked for when something goes wrong, and they end up in public tickets: searching Trac for "REQUEST HEADERS" finds over a dozen tickets with such logs, not counting attached log files, which Trac search does not cover. Some of the logs posted had the token removed by hand, but not all. We shouldn't allow such leaks to be easy.
The status report shows every preference value as it is but for user names, passwords and access tokens, which are left out; so an API key written into the URL of a custom imagery entry, for example, is posted with every bug report.
Remote Control logs every request it receives at info level, so the redirect of an OAuth 2.0 authorization, with its authorization code, is in every log, not only debug ones. The code is short-lived and useless without the PKCE verifier, but it does not belong there either.
#21756 stripped credentials from the URLs in the log (r18407), and r18652 moved that into TextUtils.stripUrl(); the headers and the body were not covered. The attached patch keeps all of it in TextUtils:
stripUrl()also stripssecret,password,verifierandcode(the latter as a whole parameter name only, so that e.g. a postcode is kept), in addition totoken,keyandconnectId, and a value now ends at white space too, so that the rest of a log line is kept;- a form-encoded request body has the syntax of a query, so
HttpClientlogs it at trace level throughstripUrl(): that coversclient_secret,code,code_verifier,refresh_tokenandpasswordof OAuth 2.0 token requests; other bodies are logged as before; - new
stripHeaders()replaces the values ofAuthorizationandProxy-Authorizationwith...stripped..., but keeps the scheme, so that the log still says what kind of authentication was used (Authorization=Bearer ...stripped...), and replaces the values ofCookieandSet-Cookieentirely;HttpClientlogs request and response headers through it; - the URL of a request with a body is logged through
stripUrl(), as the other requests already were, and so is the request line received by Remote Control; - the status report passes each string of a preference value through
stripUrl(), inside lists and maps too.
New TextUtilsTest covers both functions. HttpClientCredentialsLoggingTest makes requests to a local WireMock server at trace level with a bearer token, a session cookie and a token request, and checks that none of them appear in the log while the scheme does; a new case in RemoteControlTest sends an authorization redirect and checks that the code is not logged; new ShowStatusReportActionTest checks the preference values, among them a custom imagery entry. Each fails if the corresponding logging call goes back to logging the values. Checkstyle and PMD are clean for the change.


