Problem/Motivation
$condition->condition('foobar', [1]);
works.
$condition->condition('foobar', [1, 2]);
doesn't.
Proposed resolution
There are a few options:
- Add an exception for array and no operator. At least there are no surprises.
Add back automated IN support.( automatic IN query support was one of several contributing factors that made SA-CORE-2014-005 easily exploitable. ).Roll the entire #2358079: Require a specific placeholder format in db_query() in order to trigger argument expansion, and require explicit 'IN' parameter for conditions back.
Remaining tasks
Decide.
User interface changes
none
API changes
Improve consistency
Data model changes
none
| Comment | File | Size | Author |
|---|---|---|---|
| #52 | 2823910-52.patch | 2.37 KB | neclimdul |
| #38 | 2823910-37.patch | 3.62 KB | daffie |
Comments
Comment #2
pwolanin commentedSo, it looks to me as though the condition code is lacking validation.
I agree there should be no surprise. Both should work or both shoudl fail - bet we also don't validate BETWEEN conditions which should take an array of exactly 2 elements
Comment #3
dawehnerJust a quick comment regarding the tone of the issue summary: http://xjmdrupal.org/blog/someone-worked-hard-on-it
Comment #4
chx commentedI know the Drupal thought police is working hard and I have made myself scarce from the issue queue for it but really? Really? We can't call useless, developer hostile features out for what they are? I have not namecalled anyone, we can't even criticize the code any more?
Comment #5
dawehner@chx
This is purely about being nice to people and enable people to participate in the discussion. Here is an alternative version of the issue summary. It contains less sentences, which don't add anything to the issue itself,
while making it clearer for people to understand what is going on.
Comment #6
chx commentedw/e
Comment #7
chx commentedComment #8
chx commentedComment #9
chx commentedComment #10
dawehnerThank you
Comment #11
pwolanin commentedFor my part I think solution 1 makes the most sense.
I say that based on the fact that automatic IN query support was one of several contributing factors that made SA-CORE-2014-005 easily exploitable. The developer should know whether they are looking up a single value or a list.
Comment #12
pwolanin commentedHere's a rough start at adding more validation.
It's a little tricky since we access such random things for every parameter.
Comment #14
pwolanin commentedComment #15
pwolanin commentedHmm, NULL is not scalar. Silly PHP.
Comment #17
pwolanin commentedNice - uncovered a bug in UserStorage class
Comment #30
smustgrave commentedThis came up as a daily Bug smash target
This appears like it could be still relevant in D9.5 (Correct me if I'm wrong)
Rerolled but leaving in NW as tests are needed.
Error generating interdiff as the starting patch was done a while ago. Started with #17
Comment #31
amber himes matzAdding “needs tests” tag.
Comment #32
smustgrave commentedAlso before fixing the existing tests is the validation still needed?
Comment #33
daffie commentedAdded the testing that was needed and made the change more simple.
Comment #34
daffie commentedStyle guide fix.
Comment #35
daffie commentedSmall improvement.
Comment #38
daffie commentedFixed the test failure for Drupal\Tests\Core\Database\ConditionTest.
Comment #40
smustgrave commentedFYI please try to include interdiffs, just helps.
Ran the tests local without the fix and confirmed they failed
Failed asserting that exception of type "Drupal\Core\Database\InvalidQueryException" is thrown.
I like the idea of throwing an exception.
Since this doesn't work I don't think it needs a change record. But will leave for committer to decide that.
Comment #42
daffie commentedBack to RTBC.
Comment #44
daffie commentedComment #45
larowlanThis needs a change notice and a release note snippet, as the behaviour change could break sites. And for that reason we'll only commit it to 10.1.x.
I'll have a go at both.
Additionally, test providers should use keyed arrays to convey additional information in the case of a fail, that can be fixed on commit though.
Comment #46
larowlanI added a change notice and added the behaviour change to the draft release notes.
Comment #48
larowlanFixed on commit
Published the change record
Comment #49
larowlanComment #51
neclimdulI'm that person who's site was broken. I have a view argument that works in 10.0 but throws this exception in 10.1. Wouldn't that sort of behavior normally be deprecated instead of break sites on a minor release?
Compromise, if count > 1, throw exception, else trigger deprecation?
Comment #52
neclimdulPatch with the deprecation middle ground.
Comment #54
neclimdultrying to fix the regression and provide a proper deprecation in 10.1.
Comment #55
ghost of drupal pastThat was in
queryand it is no reason to cripple the query builder. There was no need to do that then or now. We have added more Drupalisms and degraded DX for no reason whatsoever. The job of the query builder is to do the sensible thing and it can easily do so seeing an array -- it's much harder for the string thing. So my vote is: a serious analysis should be made whether #2 is really detrimental to security for I believe it is not.Comment #56
catchSince removing automatic IN() support didn't happen in this issue, putting it back should be its own issue rather than keeping going in this one.
I do think the main issue with
SA-CORE-2014-005was committing patches from needs work at midnight on Christmas eve more than trying to support array expansion as such.#52 looks good to me. I wonder a bit if we want to trigger_error() E_USER_WARNING when count > 1 too, but if there are no known cases of this being relied upon, the exception is still clearer.
Comment #59
larowlanCommitted and pushed to 11.x and cherry-picked to 10.1.x
Thanks for testing the new release before it comes out @neclimdul 💪