Problem/Motivation
In #2966327: Limit what can be called by a callback in render arrays to reduce the risk of RCE we added TrustedCallbackInterface to protect against arbitrary user-supplied callbacks
However DateTime element has both #date_date_callbacks and #date_time_callbacks which can execute arbitrary functions
Steps to reproduce
Alter a date time element and add to either #date_date_callbacks or #date_time_callbacks e.g
$form['some_field']['widget'][0]['value']['#date_time_callbacks'][] = 'die';
Proposed resolution
Use the same trusted callback interface (\Drupal\Core\Render\Renderer::doCallback) that is used elsewhere.
Remaining tasks
Commit
User interface changes
API changes
Callbacks for #date_date_callbacks and #date_time_callbacks must implement TrustedCallbackInterface
Data model changes
Release notes snippet
Comments
Comment #2
larowlanComment #3
larowlanComment #4
larowlanI ran out of time to finish this, but in the spirit of sloppy sam, here's what I've got so far
basically need to finish off the test
Comment #5
larowlanComment #6
kim.pepperFixes the phpcs issues.
Comment #8
larowlanComment #9
larowlanComment #10
larowlanAdded a change notice
Comment #11
kim.pepperPatch looks great.
Comment #12
larowlanI need to update the patch to use the specific change-notice, rather than the generic one
Comment #13
larowlanUpdated the change notice links, leaving at RTBC because that's a trivial change
Comment #14
larowlanComment #15
larowlanComment #16
xjmJust some nits.
Formidable namespace!
Missing data type. It's presumably a string?
Missing parens on the method name.
These docs are a little weak; can we spell out what these flags are used for?
Looks like it's a
string[][]so we can be specific about that.Thanks!
Comment #17
xjmShould be 9.3.x I think since it's raising new deprecations for arbitrary untrusted callbacks.
Comment #18
larowlanFixed 1-4, I don't agree on 5, dataProviders can return anything - so leaving it generic in case of future refactoring
Comment #19
phenaproximaFixed spelling error.
Comment #20
tim.plunkettNitpick, message should have
drupal:9.3.0anddrupal:10.0.0Are there any other places this should be used in the future? If so, any follow-ups worth opening?
Comment #21
phenaproximaNice catch @tim.plunkett. Fixed the deprecation message.
Comment #22
tim.plunkettThanks, looks good! Other than #20.2, which shouldn't block commit, all feedback has been addressed.
Comment #24
phenaproximaWhoops, had botched the previous patch (forgot to add the new file). Fixed in this patch, and restoring RTBC.
Comment #26
phenaproximaUggghhhh
Comment #27
larowlanYeah, follow ups include
#3218381: #file_value_callbacks bypass the TrustedCallbackInterface protections
#2966711: Limit what can be called by a callback in form arrays
Comment #28
xjmFWIW I disagree with this; we can almost always be more specific than
arrayand the array depth and content is useful information for using the data provider. The test method that it's a data provider for is also now (correctly) typehinted, so if we did expand the provider the contract would be broken and we wouldn't miss fixing the docs and typehint.Leaving RTBC to discuss.
Comment #29
larowlanNow with more docs
Comment #31
xjmCommitted to 9.3.x only since it includes a new, dynamic deprecation; and published the CR. Thanks!
Comment #33
alexpottThis issue has caused a serious regression - see #3250335: #date_date_callbacks is broken in Drupal 9.3 - the feature no longer works.
Comment #34
alexpottAnother potentially tricky issue is that we missed a bit of
date_date_callbackbecause the same mechanism is used by \Drupal\Core\Datetime\Element\Datelist - see #3250349: \Drupal\Core\Datetime\Element\Datelist::processDatelist() does not use trusted callbacks - #date_date_callbacks only partially converted to TrustedCallbackInterface in 9.3.x