Closed (fixed)
Project:
Drupal core
Version:
9.1.x-dev
Component:
base system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
12 Jun 2020 at 08:10 UTC
Updated:
10 Sep 2020 at 03:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
alexpottComment #3
manisha111 commentedComment #4
manisha111 commentedComment #5
manisha111 commentedComment #7
manisha111 commentedComment #8
alexpottWe need to provide a BC layer for this setting. so we need to support SANITIZE_WHITELIST whilst also supporting SANITIZE_INPUT_CONFIG. To do that we need to add a BC later to the Settings get method.
Also I'm not sure about the name SANITIZE_INPUT_CONFIG - I think we can do better. The new name doesn't yet say a list of what it is.
I'm not sure about the name
$sanitize_request_input. To me that sounds like a boolean and not a list. How about $allowed_keys or $safe_keys. I cause whatever we come with needs to chime with the constant / settings key.Comment #9
dww#8.1:
SANITIZE_INPUT_SAFE_KEYS?#8.2: Yes, I think this whole file needs s/whitelist/safe_keys/. That's what I came up with on a dreditor review before reading #8.
Comment #10
manisha111 commentedPatch updated according to comment #8 and #9. Please review.
Comment #11
dwwGreat, thanks. Getting closer, but a few more things to fix before RTBC:
Drat, that means people can have 'sanitize_input_whitelist' in their site settings. :( We're going to need a BC layer, and to trigger_error() if we see the legacy key, etc. This is more complicated than just renaming things in this one file.
A) Simplify first sentence to: "An array of keys to consider safe."
B) "See default.settings.php" -- good idea! ;) I just checked core/assets/scaffold/files/default.settings.php and see no mention of this setting nor of "whitelist" at all. Weird. Probably we should remove that part of this comment, since there's nothing to see.
core/lib/Drupal/Core/Security/RequestSanitizer.php is the only file in all of core that mentions the string 'sanitize_input_whitelist'.
But, checking for the constant, that *is* used. So we also need to fix DrupalKernel.php as part of this patch. Kind of surprising that failing to do so results in no test failures. :(Edit: Whoops, it's the first hunk of the patch file. ;) Not sure how I missed that.
"An array of keys to consider safe."
s/array/string[]/
Comment #12
cburschkaThe new sentence no longer describes what the parameter does, but rather what the function does.
Maybe this should be
An array of allowed keys.orAn array of keys considered safe.?(Edit: Already mentioned in parent comment)
Comment #13
alexpottWe need to change this here to do have a BC layer to get settings using the old constant / settings key.
We need to keep and deprecate the old constant.
Comment #14
pavnish commentedWorking on it.
Comment #15
pavnish commentedOh sorry i am looking another issue wrong assignment .I opened two issue same time and assigned wrong.
Apologies for the same it will be great if someone can look on this.
Thanks
Pavnish
Comment #16
cburschkaOooh. Yeah, that BC looks trickier than I thought, since the setting is in
settings.phprather than configuration.I can see several approaches:
1. Deprecate RequestSanitizer::SANITIZE_WHITELIST, but leave its value unchanged. Add a validation method Settings::validate() which runs on initialization. It checks for the presence of the old key, emits a warning if needed, then checks for the presence of the new key, and copies the value of the old key to the new key if needed.
2. Deprecate RequestSanitizer::SANITIZER_WHITELIST, and also set it to the new value
'sanitize_input_safe_keys'.The second will provide BC unless people inlined the value directly instead of using the constant... but we can add the ::validate() step in order to support that as well.
The first provides BC in all cases, and also ensures that the deprecation is both marked by PhpDoc and emitted in the log, which may be desirable for rarely changed files like
settings.phpthat developers may not check for deprecations.Comment #17
cburschkaOption 1.
Comment #18
cburschkaMissed a spot.
Comment #19
cburschkaComment #20
alexpottI think this is neat. Let's call it handleDeprecations() as that's more descriptive. I don't think we should say this checks for errors - it's not doing that.
One thing that is kind of funky is I think we we want code that does Settings::get(RequestSanitizer:: SANITIZE_WHITELIST, []) to return the same as Settings::get(RequestSanitizer::SANITIZE_INPUT_SAFE_KEYS, []) - so if 'sanitize_input_safe_keys' is set I think we need to set 'sanitize_input_whitelist' to the same value.
Also this very much needs a testing.
Comment #21
cburschkaThis should cover it.
1. If neither key is set, nothing happens.
2. If only the old key is set, it's copied into the new key and there is a deprecation notice.
3. If only the new key is set, it's copied into the old key.
4. If (strangely) both keys are set, the new key overwrites the old to ensure consistency.
Comment #22
alexpott@cburschka looks good - now we need to add tests and a change record.
I think we need to come up with something clearer than this. Not sure what yet. Like
The setting name that configures the safe keys that will not be removed from a request.also I think we should point out that we only need to list keys that we want to keep that begin with a #.Comment #23
dwwDraft CR: https://www.drupal.org/node/3163148
Still needs deprecation tests, I guess.
Comment #24
alexpottPostponing on #3163226: Add the ability to deprecate a Settings name
Comment #25
dwwAssuming #3163226-13: Add the ability to deprecate a Settings name is committed more or less as-is, here's a reroll of #21 on top of that. "do-not-test" since it won't work until the other is committed. But I wanted to show how this would work once that's done.
Thanks,
-Derek
Comment #26
dww#25 provides the tests we were missing here, so untagging.
Also, preemptively fix a few CS bugs in #25. ;)
Comment #27
dwwAlthough #3163226: Add the ability to deprecate a Settings name is in, let's leave this Postponed on #3151094: Replace use of whitelist/blacklist in \Drupal\Core\Template classes and their tests to hash out if/how we want to do deprecation testing for real deprecated settings.
Thanks,
-Derek
Comment #28
dwwIf it turns out we agree that we don't need separate (duplicate?) test coverage of the deprecated settings API, this should be all we need.
It'll still conflict with #3151094: Replace use of whitelist/blacklist in \Drupal\Core\Template classes and their tests for the change to the
Settings::$deprecatedSettingsarray, but that'll be easy to resolve on whichever issue lands 2nd.Comment #29
dwwReroll now that #3151094: Replace use of whitelist/blacklist in \Drupal\Core\Template classes and their tests is in, and that our plan for testing real deprecated settings is clear. Interdiff is confused by the (expected) merge conflict, so here's a raw diff of the patch files.
This will need to remove the
@runInSeparateProcessif #3164161: Move the @runInSeparateProcess annotation to the SettingsTest class so it covers all test methods lands first, or that issue will need a re-roll to remove it if this lands first. ;) Cross referencing via related issues.Almost there! ;)
Thanks,
-Derek
Comment #30
dwwComment #31
quietone commentedAccording to #29, if #3164161: Move the @runInSeparateProcess annotation to the SettingsTest class so it covers all test methods is committed first, this will need a reroll. Tagging as such and setting to NW.
Comment #32
dwwGreat, thanks.
Comment #33
dww2 patches for consideration:
Instead of replicating almost this entire function with the existing one, how about converting all the real deprecation tests into a single method with a @dataProvider?
Realized this wants to end with a period. Previous patch includes this fix, too. But in case 1 is controversial, 3151093-33.period.patch is #32 with only this fixed.
Thoughts?
Thanks!
-Derek
Comment #34
longwave#33 dataprovider version looks good to me, as you say the code is identical so why repeat it, we can put it all in one place and remove individual parts or or all of it in one go when Drupal 10 opens.
Comment #36
longwaveComment #38
catchCommitted ae59215 and pushed to 9.1.x. Thanks!
The fact we already use 'dangerous keys' in the code makes 'safe keys' a very good choice.
Comment #39
dwwSweet, thanks! I published the CR.
+1
Cheers,
-Derek
p.s. I notice you opted for the @dataProvider patch. I hope @alexpott agrees. ;)