Railo vs ColdFusion cfqueryparam and SQL HashBtytes
While testing an application against Adobe ColdFusion vs Railo 4.2.1; everything went quite well except for a simple piece of inline SQL for an a legacy appication with a bit HashBytes encryption.
Nothing too fancy there, just comparing Hashed String with an inputted string, like so:
.... where hashedkey =HashBytes('SHA1', <cfqueryparam cfsqltype="cf_sql_varchar" value="#variables.unhashedkey#">)
Except...
The input of HashBytes is a binary. Adobe CF, created the hashedkey (elsewhere) with a cfqueryparam type of cf_sql_varchar but not cast/ converted as a binary.
There was no cf_sql_nvarchar which was added in CF10,
Railo came back with a different results here running this code on each environment:
<cfquery name="qryInteresting" datasource="datasource">
select hashbytes('SHA1', 'poodle') nocfqueryparam
, hashbytes('SHA1', cast('poodle' as varchar(50) ) ) nocfqueryparamCastVarchar
, hashbytes('SHA1', <cfqueryparam cfsqltype="cf_sql_varchar" value="poodle">) cfqueryparam
, hashbytes('SHA1', cast('poodle' as binary(20) ) ) castasbinary
</cfquery>
<cfoutput>
Without CFQUERYPARAM# toBase64(toString(charsetEncode( qryInteresting.nocfqueryparam, "utf-8")))#<br>
With CFQUERYPARAM: # toBase64(toString(charsetEncode( qryInteresting.cfqueryparam, "utf-8")))#<br>
Cast as Binary: # toBase64(toString(charsetEncode( qryInteresting.castasbinary, "utf-8")))#<br>
</cfoutput>
Adobe CF (9)
Without CFQUERYPARAM77+977+9D++/vSJz77+9bu+/vUXvv71oEEHvv73vv73vv71lLg0=
With nocfqueryparamCastVarchar: 77+977+9D++/vSJz77+9bu+/vUXvv71oEEHvv73vv73vv71lLg0=
With CFQUERYPARAM: 77+977+9D++/vSJz77+9bu+/vUXvv71oEEHvv73vv73vv71lLg0=
Cast as Binary: 77+977+9KGjvv70e77+9azFi77+9agnvv71277+977+9
Railo:
Without CFQUERYPARAM77+977+9D++/vSJz77+9bu+/vUXvv71oEEHvv73vv73vv71lLg0=
With nocfqueryparamCastVarchar: 77+977+9D++/vSJz77+9bu+/vUXvv71oEEHvv73vv73vv71lLg0=
With CFQUERYPARAM: 77+9MX01Du+/ve+/vWcKK++/ve+/ve+/ve+/vWZJ77+9URQr
Cast as Binary: 77+977+9KGjvv70e77+9azFi77+9agnvv71277+977+9
So the only on that comes back different is hashbytes('SHA1', <cfqueryparam cfsqltype="cf_sql_varchar" value="poodle">) which was the part of the code! Interesting, the workaround is there in Railo to make cast the column as so, but I couldn't figure out why the difference:
hashbytes('SHA1', cast(<cfqueryparam cfsqltype="cf_sql_varchar" value="poodle"> as varchar(50) )
PS poodle is clearly not the encypted sting, just the very first thing that came into my head when writing the explanation.
Comments
Post a Comment