ASP技巧:Ewebeditor及fckeditork單引號(hào)的問(wèn)題
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
Ewebeditor及fckeditork,90%的網(wǎng)站都是采用這兩種編輯器作為產(chǎn)品或者內(nèi)容的說(shuō)明部分的編輯窗口,近日,一客戶的外貿(mào)站點(diǎn)基本上快完工了,因客戶產(chǎn)品分類多,故而讓客戶自己在后臺(tái)添加產(chǎn)品,但是客戶反映,在后臺(tái)添加產(chǎn)品時(shí),如果產(chǎn)品說(shuō)明內(nèi)容太過(guò)復(fù)雜的話,產(chǎn)品怎么也添加不入數(shù)據(jù)庫(kù)中。 當(dāng)時(shí),我們也好生郁悶,這到底怎么回事,我們親自測(cè)試后臺(tái)添加任意的產(chǎn)品或者文字都能成功,偏偏他就不行,在網(wǎng)站搜索了相關(guān)的如“Ewebeditor 不能添加到數(shù)據(jù)庫(kù)”,似乎找到了一點(diǎn)答案,因Ewebeditor自身沒(méi)對(duì)單引號(hào)過(guò)濾,導(dǎo)致了添加不到數(shù)據(jù)庫(kù)的問(wèn)題。于是乎,我們把編輯器換成了fckeditork,可是還是不行,那是Ewebeditor及fckeditork自帶的不完善導(dǎo)致的嗎?為什么一個(gè)簡(jiǎn)單的單引號(hào)會(huì)引發(fā)不能添加到數(shù)據(jù)庫(kù)呢,想到這里,我們想到了分析下入庫(kù)代碼,我們采用的是SQL=insert into product(title,content) values(' " &request("title")& "' ,' "&request("content")& " ' )的寫(xiě)法,于是我們找到客戶當(dāng)時(shí)COPY進(jìn)編輯器里的內(nèi)容,發(fā)現(xiàn),果然這內(nèi)容中包括有單引號(hào),原來(lái),正是由于客戶提交到編輯器里的內(nèi)容中含有單引號(hào),導(dǎo)致我們的SQL語(yǔ)句變化了,相當(dāng)于原來(lái)是SQL=insert into product(title,content) values('內(nèi)容' ,'內(nèi)容' )變成了SQL=insert into product(title,content) values(' 內(nèi)容' ,' 內(nèi)容'' ),我們細(xì)看就知道,就因?yàn)檫@content里多了個(gè)單引號(hào),SQL語(yǔ)句發(fā)生的嚴(yán)重的寫(xiě)法錯(cuò)誤,但是,我們也奇怪,既然他寫(xiě)法錯(cuò)誤,為什么SQL語(yǔ)句不給出錯(cuò)誤提示呢,竟然也會(huì)提示操作成功,想到這里,我們想到了2003年那幾年,普遍的小黑客喜歡用的' or' =' or' 的后臺(tái)入侵法,是乎正是利用了SQL執(zhí)行時(shí),沒(méi)過(guò)濾單引號(hào)的BUG,導(dǎo)致SQL怎么執(zhí)行,結(jié)果都返回真,呵呵,沒(méi)想到,原以為寫(xiě)程序盡量圖個(gè)簡(jiǎn)單明了,也是個(gè)錯(cuò)啊。好了,問(wèn)題找到了,以后,凡是SQL入庫(kù)前,我們都把字段過(guò)濾后再傳值,就不會(huì)再出這樣的問(wèn)題了,下面是一個(gè)非常完善的SQL安全過(guò)濾函數(shù),大家直接拿去就可以調(diào)用了。 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),"<br>", 1, -1, 1) HTMLEncode = Replace(Str,"'","''", 1, -1, 1) End Function 該文章在 2010/8/19 22:33:22 編輯過(guò) |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |