Skip to content

fix(logging): keep credentials out of log calls - #2076

Merged
JohnVillalovos merged 1 commit into
LibreBooking:mainfrom
lucs7:fix/log-call-secrets
Dec 5, 2026
Merged

JohnVillalovos merged 1 commit into
LibreBooking:mainfrom
lucs7:fix/log-call-secrets

Conversation

@lucs7

@lucs7 lucs7 commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

Several Log:: calls write credentials or payer data to app.log, some at
the default error level. This PR removes them and adds a test that keeps
them out.

What counts as a secret

Credentials must never reach the log: passwords, CSRF and session tokens,
API and subscription keys, captcha answers and payment payloads. Usernames
and email addresses are not treated as secrets. An administrator can already
see them for every account, so logging them exposes nothing new.

Removed from log messages

  • CSRF tokens: "Possible CSRF attack" logged both the submitted and the
    expected token at error. It now logs whether the token was missing or
    mismatched, plus the user id.
  • API session tokens (sign-in and sign-out), the Slack token, calendar
    subscription keys and the expected captcha answer.
  • The values of a skipped user-import row, which include the plaintext
    password. Only the row number is logged now; the reason is already logged
    by UserImportCsvRow.
  • PayPal and Stripe request and response bodies. They are replaced by the
    order, charge or refund id and its status.

User ids instead of email addresses

Where a message identified a user by email address, it now uses the user id.
That keeps messages consistent; it is not a secrecy measure. Messages with no
user id available (guest reservations, password reset requests, outgoing
email) no longer name the address.

Guard test

LogCallHygieneTest already checks that every Log:: call uses a literal
format string. This PR adds testLogCallsPassNoSecrets, which fails when an
argument is named like a token, password, secret or key, or serializes a
payment payload with json_encode. It also rejects arguments named like an
email address, to keep the user-id convention above.

The check goes by variable and member names, so it catches the common
mistakes rather than every possible leak.

No behaviour changes apart from the log contents.

Copilot AI lite review requested due to automatic review settings November 29, 2026 12:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An active moderate finding shows the logging hygiene guard misses method-derived email and message-body data, so sensitive values can still be logged without the test failing.

1 open issue
What changed in this PR

This pull request hardens application logging by removing credentials, tokens, personal data, and payment payloads from log messages, standardizing calls around literal format strings, and adding a tokenizer-based hygiene regression test.

Changes:

  • Replaces sensitive log values with safer identifiers, statuses, or aggregate counts.
  • Converts interpolated and concatenated log messages to fixed format strings.
  • Adds coverage for detecting non-literal formats and selected sensitive log arguments.
File Description
WebServices/​AuthenticationWebService.php Removes session tokens from authentication and sign-out logs.
tests/​lib/​Common/​Logging/​LogCallHygieneTest.php Adds tokenizer-based checks for unsafe log formats and sensitive arguments.
Presenters/​Reservation/​ReservationEmailPresenter.php Removes recipient email addresses from reservation logs.
Presenters/​Reservation/​GuestReservationPresenter.php Removes guest email logging from reservation creation logs.
Presenters/​Integrate/​SlackPresenter.php Removes the submitted Slack token from logs.
Presenters/​Install/​ConfigurePresenter.php Replaces configuration editor email logging with a user ID.
Presenters/​GuestParticipationPresenter.php Removes participant email logging from invitation messages.
Presenters/​ForgotPwdPresenter.php Removes password-reset email details from logs.
Presenters/​Admin/​ManageThemePresenter.php Converts uploaded-file log messages to fixed formats.
Presenters/​Admin/​ManageResourcesPresenter.php Converts resource image path logging to a fixed format.
Presenters/​Admin/​ManageConfigurationPresenter.php Replaces configuration editor email logging and fixes dynamic log formats.
plugins/​Authentication/​Saml/​adSAML.php Converts a concatenated SAML error message to a literal format.
plugins/​Authentication/​Ldap/​Ldap2Wrapper.php Converts LDAP error messages to fixed format strings.
plugins/​Authentication/​CAS/​CAS.php Replaces the CAS logout email with a user ID.
plugins/​Authentication/​ActiveDirectory/​AdLdapWrapper.php Converts Active Directory exception logging to a fixed format.
Pages/​Page.php Removes submitted and expected CSRF token values from logs.
Pages/​Ajax/​AutoCompletePage.php Converts autocomplete log messages to fixed formats.
lib/​WebService/​WebServiceSecurity.php Removes web-service session tokens from request logs.
lib/​Email/​EmailService.php Replaces logged email addresses with safer delivery information.
lib/​Database/​MySQL/​MySqlConnection.php Converts SQL log construction to fixed format arguments.
lib/​Common/​Validators/​URI/​URIScriptValidator.php Converts URI redirect logging to a fixed format.
lib/​Common/​Validators/​URI/​ParamsValidator.php Converts parameter-validation logging to fixed formats.
lib/​Application/​Schedule/​CalendarSubscriptionValidator.php Removes calendar subscription keys from logs.
lib/​Application/​Reservation/​Notification/​OwnerEmailNotification.php Replaces owner email logging with a user ID.
lib/​Application/​Authentication/​WebServiceAuthentication.php Removes web-service session token logging.
lib/​Application/​Authentication/​PostRegistration.php Replaces registration email logging with user identifiers.
lib/​Application/​Authentication/​GuestUserService.php Removes guest email logging from account-creation messages.
lib/​Application/​Authentication/​CaptchaService.php Removes submitted and expected CAPTCHA values from logs.
lib/​Application/​Admin/​UserImportCsv.php Stops logging imported row contents, including plaintext passwords.
Domain/​Values/​UserPreferences.php Converts preference-name logging to fixed formats.
Domain/​ScheduleLayout.php Consolidates period logging using a fixed format.
Domain/​PaymentGateway.php Replaces PayPal and Stripe payload logging with IDs and statuses.
Domain/​Access/​ReservationRepository.php Converts reservation repository messages to fixed format strings.

Review effort: Lite

@lucs7
lucs7 force-pushed the fix/log-call-secrets branch from 4488014 to bdc5a38 Compare November 29, 2026 12:28
@lucs7
lucs7 requested review from JohnVillalovos and a lite review from Copilot November 29, 2026 12:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The change spans authentication, imports, URI validation, SQL, and PayPal/Stripe flows, while key redacted outputs and third-party exception behavior cannot be runtime-verified automatically, so representative log flows require human validation.

No open issues 🎉

1 resolved since last review

Review effort: Lite

@JohnVillalovos
JohnVillalovos force-pushed the fix/log-call-secrets branch 2 times, most recently from 02c92fd to 0529127 Compare November 30, 2026 01:24
@JohnVillalovos JohnVillalovos changed the title fix(logging): keep secrets and personal data out of log calls fix(logging): keep credentials out of log calls Nov 30, 2026
@JohnVillalovos
JohnVillalovos requested an adaptive review from Copilot November 30, 2026 01:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Subscription credentials, API session tokens, and payment payloads remain exposed through request metadata and SQL logging, while regression guards miss known sensitive-data bypasses.

7 open issues

Review effort: Max (adaptive)

Comment thread Domain/PaymentGateway.php Resolved
Comment thread lib/Application/Admin/UserImportCsv.php Resolved
@JohnVillalovos

Copy link
Copy Markdown
Collaborator

@lucs7 I'm fine with hiding credentials. I'm a bit less sure about hiding email addresses. What is the benefit of that? As only the system administrator can access the log files.

Remove values that must not reach the logs:

- CSRF tokens (logged at error level by default), API session tokens,
  the Slack token, calendar subscription keys and the expected captcha
  answer
- PayPal and Stripe request and response bodies, replaced by the
  order, charge or refund id and status; for PayPal also the HTTP
  status and PayPal's error name and debug id, so a rejected request
  can still be diagnosed
- the values of a skipped user import row, which include the plaintext
  password; the row number and the missing field are logged instead
- the query string of the request URL and referrer, which can carry
  the calendar subscription key or an activation code

Usernames and email addresses are not treated as secrets:
administrators can see them for every account anyway.

Extend the Log:: call test to reject arguments named like a token,
password, secret or key, in any case and through ?->, and JSON-encoded
payment payloads, also as \json_encode() or with named arguments.

Assisted-by: Claude:claude-opus-5-5
Assisted-by: Claude:claude-fable-5-2
@lucs7

lucs7 commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

@lucs7 I'm fine with hiding credentials. I'm a bit less sure about hiding email addresses. What is the benefit of that? As only the system administrator can access the log files.

Agreed, I've dropped the email changes. The PR now only removes credentials: CSRF and session tokens, the Slack token, calendar subscription keys, the captcha answer, payment payloads and the user-import row with its plaintext password. Usernames and email addresses stay in the log as before.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$userId = $server->GetHeader(WebServiceHeaders::USER_ID);

Log::Debug('Handling secure request. url=%s, userId=%s, sessionToken=%s', $_SERVER['REQUEST_URI'], $userId, $sessionToken);
Log::Debug('Handling secure request. url=%s, userId=%s', $_SERVER['REQUEST_URI'], $userId);
Comment on lines +19 to +21
private const SECRET_VARIABLES = '/^\$(token|sessionToken|csrfToken|password|newPassword|currentPassword|secret|apiKey|providedKey)$/i';
/** Properties or methods whose value must never be logged, matched case-insensitively. */
private const SECRET_MEMBERS = ['sessiontoken', 'csrftoken', 'password'];

@JohnVillalovos JohnVillalovos left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. It may not be perfect but a good improvement

Thanks @lucs7

@JohnVillalovos
JohnVillalovos merged commit 4ba6d17 into LibreBooking:main Dec 5, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants