Problem/Motivation
Currently if an element contains an invalid #access value, it will be silently evaluated to true.
This could make some security bugs hard to detect.
Steps to reproduce
Add something like this to an element:
'#access' => new \stdClass(),
The element is displayed and processed.
Proposed resolution
We could log a warning if the value is not a boolean or an AccessResultInterface object.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3526250
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
prudloff commentedComment #3
cilefen commentedI think an exception throw is the best way to notify the developer..
Comment #6
kalpanajaiswal commentedI have created a patch to adda warning.
Comment #7
prudloff commentedI agree but I wonder if it could be a breaking change if some custom code relies on passing something that is currently evaluated to true?
Comment #8
kalpanajaiswal commentedComment #10
prudloff commentedI added a deprecation that we can later turn into an exception.
Comment #11
prudloff commentedComment #12
prudloff commentedNote that the current behavior is inconsistent between FormBuilder::isElementAccessible() and Renderer::doRender().
If #access on a form input is a string:
Renderer::doRender() will display the input (because it hides it only if #access === FALSE).
FormBuilder::isElementAccessible() will not process the input (because it processes only if #access === TRUE).
This would be fixed by only allowing valid values.
Comment #13
smustgrave commentedHad this ticket open for a few days but wanted to make sure still good to do deprecations in 11.3 and we are good!
Code wise pretty straight forward. Test coverage is there https://git.drupalcode.org/issue/drupal-3526250/-/jobs/7195672
LGTM
Comment #14
quietone commentedI think a better title would say that this is a deprecation. I didn't see any comment that the change record has been reviewed, that is really part of the process to set an issue to RTBC.
I took a look and thought it could use some wording changes and an 'after' example. I have made those changes.
Comment #15
geek-merlinCode and CR LGTM too. Great work!
Comment #16
longwaveToo late for 11.3.0, sorry. Can't decide whether this can go in 11.4 for removal in 12, or if we should wait until Drupal 13 - though this feels like a programming error so perhaps 12 is ok?
Comment #17
prudloff commentedI updated the deprecation with 11.4/13.0.
Comment #18
dcam commentedAll instances of the deprecation and removal versions have been updated to 11.4.0 and 13.0.0, respectively. So I'm setting this back to RTBC.
Comment #21
catchI'm not sure this is a case where we want a silenced @trigger_error - it would only affect code with automated tests with deprecations switched on, which is less and less likely when it's most likely to affect custom site-specific code.
Given we won't start throwing an exception until 13.0.0, let's open a follow-up to trigger E_USER_WARNING for this case from 12.0 onwards.
The MR itself is fine so I have gone ahead and committed to main and 11.x.
Moving to needs work for the follow-up to be opened.
Comment #24
prudloff commentedI created a followup: #3593606: Trigger warning when #access has an invalid value