您将哪些安全脚本/代码添加到 application.cfm 中?
我正在重做我们公司的代码,我希望有一个清晰、易于阅读且相当安全的 application.cfm。
不,我们没有使用 application.cfc。所以我们不要讨论这个问题了。
只是想知道为了安全起见您会添加哪些脚本。
我正在使用 Coldfusion 8 标准,sql 2008。
这是我当前使用的脚本之一,但我想听听其他一些 Coldfusion 程序员的意见。
<cfset temp = cleanScopes('form,url') />
<!--- another method to clean url/form data from http://www.garyrgilbert.com/tools/coldfusion/cleanScopes.cfm.txt --->
<cffunction name="cleanScopes" access="public" returntype="void">
<cfargument name="scopesToClean" type="string" required="yes">
<cfargument name="charlist" type="string" required="no" default="">
<cfscript>
reTags ="<[^/>]*>|</.*>";
</cfscript>
<cfloop list="#scopestoClean#" index="scopeName">
<cfif not findnocase("multipart/form-data",cgi.CONTENT_TYPE)>
<cfscript>
s=Evaluate(scopeName);
for(field in s)
if (isSimpleValue(s[field])){
if(reTags neq '')
do { prev=s[field];
s[field]=REReplaceNoCase(s[field],reTags,"","ALL");
} while (prev NEQ s[field]);
structUpdate(s,field,prev);
if (charlist neq '')
s[field] = replacelist(s[field],charlist,'');
}
</cfscript>
</cfif>
</cfloop>
<cfreturn>
</cffunction>
感谢您抽出时间。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议不要试图以全球时尚的方式捕捉一切。无论您的全局保护代码变得多么复杂和错综复杂,都不可避免地会有一些事情被遗漏。
相反,“正确”(就其价值而言)方法是在输出期间清理页面(或电子邮件等)上呈现的所有内容,这些内容最初是作为用户输入而存在的。
也就是说,请查看 OWASP。他们拥有出色的库来防御各种攻击,包括您提到的各种攻击(sqli、xss、crlf)。我的一位同事最近将其中一些库封装到了 CFC 中,我们可以在应用程序中使用它,并在我们的开发者博客上解释了如何使用它:
然而,如果你坚持采用全球解决方案,为什么要重新发明轮子呢?为什么不尝试一下FuseGuard之类的东西。这个价格可能低于用于拼凑、调试和处理突破本地系统的安全问题所花费的开发时间的成本。
I would advise against attempting to catch everything in a global fashion. There will inevitably be a few things that slip through the cracks, no matter how complex and convoluted your global protection code gets.
Instead, the "correct" (for what it's worth) method is to sanitize all content being presented on a page (or in an email, etc) -- during output -- that began its life as user input.
That said, take a look at OWASP. They have excellent libraries for protecting from all kinds of attacks, including the various ones you mention (sqli, xss, crlf). A coworker of mine recently wrapped up some of those libraries into a CFC that we can use in our applications, and explained how to use it on our developers blog:
However, if you insist on a global solution, why reinvent the wheel? Why not try out something like FuseGuard. The price is probably less than the cost of the development-hours that would be spent cobbling together, debugging, and dealing with security problems that break through your home-grown system.
就我个人而言,我不太确定这种“全球”方法是最好的。我检查接受外部数据的所有模型中的所有传入数据,并针对每种情况使用特定的验证规则。所以额外的层看起来有点多余。
此类脚本不会保护您将字符串放入传递到 URL 的数字 ID 中——您必须以任何方式检查它。您必须以任何方式在视图中使用 HTMLEditFormat/XMLFormat,等等。
CFScript 的 PS 列表循环:
Personally, I'm not really sure this "global" approach is the best. I check all incoming data in all models that accept external data, with specific validation rules for each situation. So additional layer looks overkill.
Such scripts wont protect you from putting string into the numeric id passed into the URL -- you have to check it any way. You have to use HTMLEditFormat/XMLFormat in the views any way, and so on.
P.S. List loop for CFScript: