Random thought - cfparam could be more helpful if ...
# cfml-general
r
Random thought - cfparam could be more helpful if it would set default value when variable not match defined type. Use case - bots trying to put garbage to URL parameters to create error or SQL injection, single <cfparam> line would look nicer that cascade of <cfif>s
👍 1
m
A closure could be interesting, too. Sor example to validate the value automatically to a regex or a list of allowed values.
b
I think flexibility is important for a tag such as cfparam. It is crucial that it leaves room for the developer to add extra validation. If and when needed. Software development will always be an arms-race between us, developers on the inside, and intruders from the outside. The use case that you propose is just one out of a myriad different attempts the intruder may make to breach our defences. A tag cannot anticipate them all. It can only hope to have the most vital drawbridges in place.
r
All I want that tag won't throw an error, but defaulted a value instead, just like it does for empty value. That will save couple of keypunches and leave code clean. CFPARAM itself is just a 'syntax sugar' for "cfif not isdefined and not len eq 0 blabla", but a nice one.
b
I don't think I'd want that behavior. Type validation to me should be a hard stop, not a change-the-value-behind-the-scenes sort of thing. Sounds unexpected and hard to debug.
For ex, if I order a happy meal with a large molten lava to drink, I'd like them to tell me that's not a valid drink order. I WOULDN'T want them to just default it to a Coke instead without asking me
And likewise, if a bot enters
Copy code
<http://mysite.com?numericId=abcdefg|mysite.com?numericId=abcdefg>
I'd be find with them hitting an error page. There's no need to try to load any default record based on a default id. They just get an exception and the page stops loading.
r
behaviour of cfparam can be flagged, adding thowonerror="true" attribute for example. I hate to see logs sh*t-loaded with - literally - 10000s of errors produced by attempted SQL injections. One day they tried to exploit date param and sorting URL param - which produced error, but I would like to gracefully turn error params into default params. No big deal, CFIF for the win, but CFPARAM could save some screenspace
s
custom tag/function with the same argument signature wouldn't be any more screenspace?
b
That's really a failure in CF's logging strategy
JBoss Undertow, for example, has a rule where they never log request-level errors of severity INFO or higher. They ONLY log those as DEBUG or TRACE. And the specific purpose of that is to prevent DOS attacks where causing a huge number of errors could fill up logs on a hard drive
Just because a user gets an error on a page, doesn't mean it needs to be logged by the server. I'm curious if the cfparam tag was directly logging those errors or if your app didn't have proper app-wide error handling to intercept it