Modify ↓

#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 strips secret, password, verifier and code (the latter as a whole parameter name only, so that e.g. a postcode is kept), in addition to token, key and connectId, 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 HttpClient logs it at trace level through stripUrl(): that covers client_secret, code, code_verifier, refresh_token and password of OAuth 2.0 token requests; other bodies are logged as before;
  • new stripHeaders() replaces the values of Authorization and Proxy-Authorization with ...stripped..., but keeps the scheme, so that the log still says what kind of authentication was used (Authorization=Bearer ...stripped...), and replaces the values of Cookie and Set-Cookie entirely; HttpClient logs 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.

Attachments (1)

http-log-credentials.patch​ (23.2 KB ) - added by wangi 27 minutes ago.

Download all attachments as: .zip

Change History (1)

by wangi, 27 minutes ago

Attachment: http-log-credentials.patch​ added

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain team.
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from team to the specified user.
Next status will be 'needinfo'. The owner will be changed from team to wangi.
as duplicate The resolution will be set to duplicate. Next status will be 'closed'. The specified ticket will be cross-referenced with this ticket.
The owner will be changed from team to anonymous. Next status will be 'assigned'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.