IT貓撲網:您身邊最放心的安全下載站! 最新更新|軟件分類|軟件專題|手機版|論壇轉貼|軟件發(fā)布

您當前所在位置: 首頁網絡編程Asp編程 → Ewebeditor及fckeditork單引號的問題

Ewebeditor及fckeditork單引號的問題

時間:2015-06-28 00:00:00 來源:IT貓撲網 作者:網管聯盟 我要評論(0)

Ewebeditor及fckeditork,90%的網站都是采用這兩種編輯器作為產品或者內容的說明部分的編輯窗口,近日,一客戶的外貿站點基本上快完工了,因客戶產品分類多,故而讓客戶自己在后臺添加產品,但是客戶反映,在后臺添加產品時,如果產品說明內容太過復雜的話,產品怎么也添加不入數據庫中。

當時,我們也好生郁悶,這到底怎么回事,我們親自測試后臺添加任意的產品或者文字都能成功,偏偏他就不行,在網站搜索了相關的如"Ewebeditor 不能添加到數據庫",似乎找到了一點答案,因Ewebeditor自身沒對單引號過濾,導致了添加不到數據庫的問題。于是乎,我們把編輯器換成了fckeditork,可是還是不行,那是Ewebeditor及fckeditork自帶的不完善導致的嗎?為什么一個簡單的單引號會引發(fā)不能添加到數據庫呢,想到這里,我們想到了分析下入庫代碼,我們采用的是SQL=insert into product(title,content) values(' " &request("title")& "' ,' "&request("content")& " ' )的寫法,于是我們找到客戶當時COPY進編輯器里的內容,發(fā)現,果然這內容中包括有單引號,原來,正是由于客戶提交到編輯器里的內容中含有單引號,導致我們的SQL語句變化了,相當于原來是SQL=insert into product(title,content) values('內容' ,'內容' )變成了SQL=insert into product(title,content) values(' 內容' ,' 內容'' ),我們細看就知道,就因為這content里多了個單引號,SQL語句發(fā)生的嚴重的寫法錯誤,但是,我們也奇怪,既然他寫法錯誤,為什么SQL語句不給出錯誤提示呢,竟然也會提示操作成功,想到這里,我們想到了2003年那幾年,普遍的小黑客喜歡用的' or' =' or' 的后臺入侵法,是乎正是利用了SQL執(zhí)行時,沒過濾單引號的BUG,導致SQL怎么執(zhí)行,結果都返回真,呵呵,沒想到,原以為寫程序盡量圖個簡單明了,也是個錯啊。好了,問題找到了,以后,凡是SQL入庫前,我們都把字段過濾后再傳值,就不會再出這樣的問題了,下面是一個非常完善的SQL安全過濾函數,大家直接拿去就可以調用了。

Function HTMLEncode(Str)
?If Isnull(Str) Then
???? HTMLEncode = ""
???? Exit Function
?End If
?Str = Replace(Str,Chr(0),"", 1, -1, 1)
?Str = Replace(Str, """", """, 1, -1, 1)
?Str = Replace(Str,"<","<", 1, -1, 1)
?Str = Replace(Str,">",">", 1, -1, 1)
?Str = Replace(Str, "script", "script", 1, -1, 0)
?Str = Replace(Str, "SCRIPT", "SCRIPT", 1, -1, 0)
?Str = Replace(Str, "Script", "Script", 1, -1, 0)
?Str = Replace(Str, "script", "Script", 1, -1, 1)
?Str = Replace(Str, "object", "object", 1, -1, 0)
?Str = Replace(Str, "OBJECT", "OBJECT", 1, -1, 0)
?Str = Replace(Str, "Object", "Object", 1, -1, 0)
?Str = Replace(Str, "object", "Object", 1, -1, 1)
?Str = Replace(Str, "applet", "applet", 1, -1, 0)
?Str = Replace(Str, "APPLET", "APPLET", 1, -1, 0)
?Str = Replace(Str, "Applet", "Applet", 1, -1, 0)
?Str = Replace(Str, "applet", "Applet", 1, -1, 1)
?Str = Replace(Str, "[", "[")
?Str = Replace(Str, "]", "]")
?Str = Replace(Str, """", "", 1, -1, 1)
?Str = Replace(Str, "=", "=", 1, -1, 1)
?Str = Replace(Str, "'", "''", 1, -1, 1)
?Str = Replace(Str, "select", "select", 1, -1, 1)
?Str = Replace(Str, "execute", "execute", 1, -1, 1)
?Str = Replace(Str, "exec", "exec", 1, -1, 1)
?Str = Replace(Str, "join", "join", 1, -1, 1)
?Str = Replace(Str, "union", "union", 1, -1, 1)
?Str = Replace(Str, "where", "where", 1, -1, 1)
?Str = Replace(Str, "insert", "insert", 1, -1, 1)
?Str = Replace(Str, "delete", "delete", 1, -1, 1)
?Str = Replace(Str, "update", "update", 1, -1, 1)
?Str = Replace(Str, "like", "like", 1, -1, 1)
?Str = Replace(Str, "drop", "drop", 1, -1, 1)
?Str = Replace(Str, "create", "create", 1, -1, 1)
?Str = Replace(Str, "rename", "rename", 1, -1, 1)
?Str = Replace(Str, "count", "count", 1, -1, 1)
?Str = Replace(Str, "chr", "chr", 1, -1, 1)
?Str = Replace(Str, "mid", "mid", 1, -1, 1)
?Str = Replace(Str, "truncate", "truncate", 1, -1, 1)
?Str = Replace(Str, "nchar", "nchar", 1, -1, 1)
?Str = Replace(Str, "char", "char", 1, -1, 1)
?Str = Replace(Str, "alter", "alter", 1, -1, 1)
?Str = Replace(Str, "cast", "cast", 1, -1, 1)
?Str = Replace(Str, "exists", "exists", 1, -1, 1)
?Str = Replace(Str,Chr(13),"
", 1, -1, 1)
?HTMLEncode = Replace(Str,"'","''", 1, -1, 1)
End Function

文章首發(fā):http://www.seohf.com/seonews/view654.html 如需轉載,請注明出處。

關鍵詞標簽:Ewebeditor,fckeditor

相關閱讀

文章評論
發(fā)表評論

熱門文章 ASP編程代碼:隱藏圖片的真實地址 ASP編程代碼:隱藏圖片的真實地址 ASP教程:0177:800401f3錯誤解決 ASP教程:0177:800401f3錯誤解決 ASP代碼中如何屏蔽ip地址 禁止某IP段訪問網站 ASP代碼中如何屏蔽ip地址 禁止某IP段訪問網站 錯誤80004005信息處理方法 錯誤80004005信息處理方法

相關下載

    人氣排行 ASP下標越界的解決方法 ASP代碼中如何屏蔽ip地址 禁止某IP段訪問網站 “文件共享鎖定數溢出” 原因及解決方法 無法寫入數據庫的解決方法 ASP教程:0177:800401f3錯誤解決 ASP常用函數列表 如何用ASP來獲取客戶端真實IP的地址 ASP用FSO生成HTML簡單實例+詳解[原創(chuàng)]