mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Don't log params in exception messages #6295
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Danack on GitHub (Sep 5, 2019).
Originally assigned to: @Ocramius on GitHub.
Feature Request
Summary
Currently it seems that parameter values are used as part of the message that is generated when at least some exceptions are thrown.
For example, due to a programming error where a user was being inserted, instead of being updated, this found it's way into my log files:
The problem is that this message contains secrets, that for technical, legal, and ethical reasons shouldn't be put into log files.
The request is to either by default, or as an optional setting, not include parameter values in the message, and possibly to add the capability to retrieve them via a
getParamsmethod on each exception.And because someone might find it interesting, a philosophical reasoning: https://en.wikipedia.org/wiki/Principle_of_least_astonishment
@Ocramius commented on GitHub (Sep 5, 2019):
Disagree on this: this can happen with any kind of exception produced by any technical layer.
It is generally normal to throw exceptions and provide some context (trace, message, identifiers, values) to facilitate interactions with debugging and logging.
If these exceptions happen to 100% contain sensitive information (f.e. "exception: password XYZ is too short!") then you should most certainly not include the sensitive information in the exception message, but here we are talking about an infrastructure layer that just pushes information from consumer to SQL domain.
This also applies to any kind of transport layer that may contain part of a message in a log (f.e. "could not decode message XYZ", "malformed header: XYZ" - will it contain a password? nobody knows!). Some sort of exfiltration into logs will always occur.
Therefore, closing here based on following rationale:
If we were to change this approach, we'd have to re-evaluate exception design in the whole ecosystem, and not just here. Maybe worth bringing up in internals, to allow having a separate
$contexton exceptions (much like it happens inc4421fcac1/Psr/Log/LoggerInterface.php (L30)? )Similarly related to https://github.com/doctrine/dbal/issues/2899#issuecomment-339675090
@Ocramius commented on GitHub (Sep 5, 2019):
Note: I realise that PCI compliance and similar systems can make you fail an audit if a user enters a credit card in a comment field, and you end up saving it by accident (and good luck with finding out!).
It is not up to technical layers to adhere to these requirements.
@Danack commented on GitHub (Sep 5, 2019):
So it should default to being treated as sensitive, not as insensitive.
Which is why I don't log parameters in stack traces either.
That's why I don't put messages from transport layers into my general logging system.
I think I disagree with both of those statements. Or at the very least, it should be possible to use software in a way that user data has to be deliberately exported, rather than it being an accidental disclosure.
Obviously I can work around this pretty easily by just snipping all exception messages after the phrase 'with params', so can't justify getting involved in Doctrine internals to pursue this, however this seems like a design flaw to me.
@Ocramius commented on GitHub (Sep 5, 2019):
@Danack I'd say that if this needs to be fixed, it needs to be fixed by removing any
sprintf()in the entire design of all libraries involved here.I don't think that's a sensible choice: I understand the frustration, but I think this goes more deep into the separation of contextual information (see Sentry and their scrubbing approach) passed to a logger, and the lack of this construct in the design of the
ThrowableAPI.@martijn80 commented on GitHub (May 22, 2022):
Php8.2 upcoming SensitiveParameterValue feature could be of help here.
See https://wiki.php.net/rfc/redact_parameters_in_back_traces