Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions developer_manual/basics/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,42 @@ You can combine message interpolation with exception logging -- Nextcloud
handles both.


Keeping secrets out of stack traces
-----------------------------------

Exception stack traces can include method arguments. Mark parameters that
accept secrets (passwords, tokens, credentials, and similar) with PHP's
standard `#[\SensitiveParameter] <https://www.php.net/manual/en/class.sensitiveparameter.php>`_
attribute so their values do not end up in the log:

.. code-block:: php

<?php
namespace OCA\MyApp\Service;

class AuthService {
public function login(
string $user,
#[\SensitiveParameter]
string $password,
): void {
// ...
}
}

Since Nextcloud 36 the logger replaces these values in stack traces with the
same placeholder it uses for other sensitive data, and also removes them where
they are passed on to other calls further down the trace.

.. deprecated:: 36
``IRegistrationContext::registerSensitiveMethods()`` is deprecated in favor
of the ``#[\SensitiveParameter]`` attribute.

.. note::
This only covers **stack traces**. Never put passwords, tokens, or personal
data into a log message (or its context array) yourself.


Custom log file
---------------

Expand Down