我们正在努力避免 ColdFusion 应用程序中的 XSS 攻击。在我们的 cfapplication
标签中添加<cfset this.scriptprotect=”all”>
后,它仅适用于现在更改为 InvalidTag
的表单输入值。但是,它不适用于 URL 查询字符串键值。我还想知道,为什么 cfapplication
标签下的scriptprotect
不适用于 URL <script
URL 中的密钥插入?
我遇到了 https://gist.github.com/learncfinaweek/4121370;我正在所有页面中包含规范化以进行 URL 验证。我想知道应该执行哪些验证以避免规范化功能后的攻击。
你不能只依赖 CF 进行 XSS(或 sql 注入(攻击。你可以在 application.cfc 中编写自己的代码,以便在每个作用域中查找 XSS/SQL 注入攻击,并在 onRequest()
或 onRequestStart()
方法中运行该代码,具体取决于应用的设置方式。下面是一个示例(请不要在不知道它到底做什么的情况下使用此代码,并且您已经对其进行了广泛的测试。这是我从应用程序中抓取的一些代码,但可能会得到误报,而且我对所有测试都没有 100% 的信心(:
此代码将在 application.cfc 中
public boolean function onRequestStart (
required string targetPage) {
try {
if (checkForAttack()) {
location url="/" addtoken=false;
return true;
}
... do other stuff ...
} catch (any e) {
onError(e, "onRequestStart");
}
return true;
} // onRequestStart()
private boolean function checkForAttack() {
// check for any kind of sql injection or xss attack
var attackFound = false;
// you could change these tests, or add more tests
var tests = ["4445434C415245", "cast(s|%20)*(%28|()", "(;|%3B)(s|%20)*DECLARE", /*"exec(s|%20)*(",*/ "schema.columns|table_name|column_name|drop(s|%20)+table|insert(s|%20)+into|.tables", ".[sysobjects]", ".sysobjects"];
var ctTests = ArrayLen(tests);
var ix = 0;
var key = "";
if (isDefined("CGI.query_string") && CGI.query_string != "") {
for (ix = 1; ix <= ctTests; ix++) {
if (REFindNocase(tests[ix], CGI.query_string) > 0) {
CGI.query_string = "";
attackFound = true;
break;
}
}
}
if (isDefined("URL")) {
for (key in URL) {
for (ix = 1; ix <= ctTests; ix++) {
if (REFindNocase(tests[ix], URL[key]) > 0) {
attackFound = true;
URL[key] = "";
}
}
}
}
if (isDefined("Form")) {
for (key in Form) {
for (ix = 1; ix <= ctTests; ix++) {
if (reFindNocase(tests[ix], Form[key]) > 0) {
attackFound = true;
Form[key] = "";
}
}
}
}
if (IsDefined("Cookie")) {
for (key in Cookie) {
for (ix = 1; ix <= ctTests; ix++) {
if (REFindNocase(tests[ix], Cookie[key]) > 0) {
attackFound = true;
Cookie[key] = "";
}
}
}
}
return attackFound;
} // checkForAttack()