Updated: Comment #N
Problem/Motivation
#2141041: CsrfTokenGenerator::validate() should do an identical compare added string casting to Crypt::hmacBase64(), this just masks a problem in calling code by brushing it under the carpet. base64_encode() can also accept any scalar values - these don't have to be strings. This function could easily be being passed something other than what you expect (and what it expects). This casting could also lead to some weird bugs in peoples code that they will find very difficult to debug.
Proposed resolution
Throw an exception if strings are not passed to this function.
Remaining tasks
patch, review, updated tests.
User interface changes
None
API changes
None, unless you are passing some other datatypes to Crypt::hmacBase64()!
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | 2145881.14.patch | 7.29 KB | alexpott |
| #14 | 8-14-interdiff.txt | 1.51 KB | alexpott |
| #8 | interdiff-2145881-8.txt | 3.1 KB | damiankloip |
| #8 | 2145881-8.patch | 6.67 KB | damiankloip |
Comments
Comment #1
damiankloip commentedComment #2
damiankloip commentedSo how about something like this?
I also changed the tests in the csrfTokenTest too, to assert the exceptions.
Comment #3
damien tournoud commentedI suggested this during the making of the security release, but that was deemed too intrusive for Drupal 6 and 7.
On visual inspection, the patch looks good to me.
Comment #5
damiankloip commentedI guess drupal_get_js() should make sure it's not passing NULL to drupal_get_token().
Comment #6
dawehnerAwesome test coverage!!
Comment #7
tim.plunkettSo we're losing coverage for these three?
Comment #8
damiankloip commentedWe don't lose here really, but how about this, then we get the best of both worlds? keeping the old tests (with strings as the token value) as moving the invalid parameters (exceptions thrown) to another test.
Comment #9
damiankloip commentedComment #10
tim.plunkettThanks!
Comment #11
tim.plunkett...
Comment #12
damien tournoud commented^ This looks like sweeping a bug under the carpet?
Comment #13
damiankloip commentedPotentially, can we open a follow up? As it's not really the fault of this patch. What's the bug? Theme key not being set in tests?
Comment #14
alexpott#12so lets not do that!
Comment #15
damiankloip commentedNice work Alex. Rtbc for the code on top of the original rtbc!
Comment #16
xjm14: 2145881.14.patch queued for re-testing.
Comment #17
damiankloip commented14: 2145881.14.patch queued for re-testing.
Comment #18
catchCommitted/pushed to 8.x, thanks!