Problem/Motivation
PHP 8.2 provides attribute #[SensitiveParameter] to exclude sensitive data from backtraces
https://wiki.php.net/rfc/redact_parameters_in_back_traces
Proposed resolution
- explore where this attribute could be applied (password and private key arguments)
- discus policy on usage
Remaining tasks
- add the attribute to password argument and its hash (both interface and implementation)
- add it for non-string argument of PrivateKey
User interface changes
no
API changes
no
Data model changes
no
Release notes snippet
TBD
| Comment | File | Size | Author |
|---|---|---|---|
| #30 | 3296293-30.patch | 8.75 KB | andypost |
| #30 | interdiff.txt | 883 bytes | andypost |
Issue fork drupal-3296293
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mfbIs there anything preventing
#[\SensitiveParameter]from being added now, in 10.x, rather than waiting until 8.2 is required? It wouldn't do anything on 8.1, but could be a nice little security enhancement for those using 8.2Comment #3
geek-merlin> Is there anything preventing #[\SensitiveParameter] from being added now, in 10.x, rather than waiting until 8.2 is required? It wouldn't do anything on 8.1, but could be a nice little security enhancement for those using 8.2
The RFC states:
> 1. The \SensitiveParameter and \SensitiveParameterValue class name will no longer be available to userland code.
which, the other way round, says Yes, we can do it now. So let's do it.
Comment #4
mfbRetitling then. As far as "explore where this attribute could be applied," to start with this could be helpful for $password parameter; also the unhashed $sid which is functionally similar to password. That stuff is truly sensitive vs. other PII which I'd call less sensitive.
Comment #7
amjad1233I am not sure how I messed up, I was using DrupalPod to give it a try but I guess somehow It started a new PR. Well initial change is here https://git.drupalcode.org/issue/drupal-3296293/-/commit/615123b7ae06b98...
Comment #8
amjad1233A traditional patch
Comment #9
_utsavsharma commentedFIxed CCF for #8.
Please review.
Comment #10
solideogloria commentedComment #11
smustgrave commentedPatch needs some work for CI failures
Comment #12
smustgrave commentedRemoved #[\SensitiveParameter] from the function calls as they appeared to be causing errors in those locations.
Comment #14
smustgrave commentedrandom ckeditor5 failure.
Comment #15
mfbPresumably the
PasswordInterface $passwordargument wouldn't be sensitive, that's just the password hashing serviceComment #16
andypostFix #15 and add more places
I see no reason to add it to trait and other methods used only in tests
Comment #17
smustgrave commentedAh I gotcha. Changes look good.
Comment #18
andypostSorry derailing RTBC but I missed to remove attribute from tests - I find it helpful for debugging
Probably we need change record to notify contrib maintainers
Comment #19
jordanpagewhite commentedCould we use #[SensitiveParameter] on the $connection_options of Drupal\mysql\Driver\Database\mysql\Connection::open() to mitigate 3061567?
If that would be an acceptable addition to this patch, I would be happy to add it. It would probably be later this evening though (Pacific time).
Comment #20
solideogloria commentedComment #21
andypost@jordanpagewhite Great point, would be great to check how it works for array arguments!
Comment #22
solideogloria commentedI think adding the attribute there would be a good addition.
Comment #23
jordanpagewhite commentedIt seems that 3061567 will/is already resolved by SensitiveParameters in PHP 8.2. The actual backtrace logged is PDO::construct(), and it seems that this is already using SensitiveParameter properly. We can disregard my comment in #19. Thank you.
PDOException: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for 8b9fb7fd9a14 failed: Name or service not known in /opt/drupal/web/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php on line 79 #0 /opt/drupal/web/core/modules/mysql/src/Driver/Database/mysql/Connection.php(165): PDO->__construct('mysql:host=8b9f...', 'root', Object(SensitiveParameterValue), Array)Steps to test
Pre-step
Positive test case
Negative test case
FAILED test: This did NOT include the plain-text connection_options, but instead Object(SensitiveParameterValue).
verify that issue 3061567 still throws the PDOException that includes the plain text connection options
Comment #24
mfbAdding to the unhashed $sid as I suggested in #4
Comment #25
longwaveIs the $hash parameter sensitive?
This is the PrivateKey service, not an actual private key.
Comment #26
mfbI would say it's only necessary to match what php and symfony are doing with their password hashing functions, which is that just the password itself is tagged as SensitiveParameter, not the hash. Of course a hashed password, like lots of data, is still sensitive and there are procedures if there's a breach, just saying it doesn't need to be a "SensitiveParameter".
Comment #27
andypostWe should promote it for other module developers
Re #25 both are sensitive, private key has sensitive data ans the RFC mentioned that case, hash of password probably unreversable ATM but very probably not in future, that's why there's #3110670: Increase password hashing iterations
Comment #28
andypostComment #29
mfb@andypost The actual string private key is certainly a SensitiveParameter (as would be the hash salt setting if that is a parameter anywhere), but I don't see a need for the PrivateKey service to be a SensitiveParameter; can you explain? That's just a service which doesn't contain any data.
Comment #30
andypostI was wrong about PrivateKey, checked with fresh head and here's patch
Comment #31
mfbSymfony will now apply SensitiveParameter to $sessionId as of https://github.com/symfony/symfony/pull/49016 so now we just need to get this issue committed :) I'm still ambivalent about adding it to hashes since php and symfony do not, but leaked password hashes are both unfortunate and embarrassing so, works for me.
Comment #32
solideogloria commentedThanks for your work on this. Attributes is a cool feature to see finally in PHP (as well as this attribute specifically). I'm excited every time I read the release notes for a new PHP version.
Comment #33
smustgrave commentedOnly moving back to NW for the change record
The change it self looks good!
Comment #34
jordanpagewhite commentedI made a first draft/attempt at a change record. https://www.drupal.org/node/3339665
Comment #35
smustgrave commentedNot sure what more the change record should include
Comment #37
longwaveCommitted and pushed 90c51b9047 to 10.1.x. Thanks!
Also tweaked the change record a little and published it.
Comment #38
longwave