Browse text file within CF to determine if there are any <scripts>'s inside
We have run into a security situation where we need to browse through all text files that users are going to load into an Attachments directory using <cffile> before we allow anyone to have access to these files because of the danger of cross site scripting (xss).
We have tested the potential for something like “<cfscript> document.location.replace(“http://www.badsite.com”) </cfscript> being run within a browser when the user opens the file in their browser moving the user to this site, which could open them up to downloading a Trojan onto their PC. This just happened to him a couple of few weeks ago and his hard drive was destroyed. (I suppose there is a way to block xss within IE, FireFox, etc., but I can’t count on every user having xss blocked so I have to do it for them.)
Although I haven’t done it yet, it appears that you can use the <cfloop> function to open a file and loop through it line by line so that you could process this file in CF 8 to ensure that “<cfscript>” is not contained anywhere within the file. I’m going to do a proof of concept later today or tomorrow. If this works, then I’m OK for all my systems that run CF8 or CF9, but that is it.
What I really need is a way that would be compatible with previous versions of CF as well. My first instinct was to try something with the FileOpen function within <cfscript> but there does not seem to be anyway to easily parse a file once I have it open in <cfscript>. I’ve done a ton of JavaScript code and I know that <cfscript> is somewhat of a subset of that, but the documentation I’ve found on <cfscript> is so poorly written as to be almost useless. (Forta’s CF8 books give it very short shrift even in the downloadable PDF.)
Does anyone know of a third way to do this that would be compatible with CF6 through CF9???
Thank you in advance for your suggestions.
:-}
Len
