ASP: securely writes data to the database, reads data normally, and displays data in different scenarios
Source: Internet
Author: User
For example, if the field styledesc is used, the data must be 50 bits and char characters. Can I limit only 50 bits,
All characters can be entered. As long as it is char-type, it can be used as long as the database permits
In this way, securely write data to the database and read and display data normally in different scenarios and applications.
What should I do?
The following are my summary points. It is very likely that this is incorrect. Please correct me.
If the user input can be any character, (except for the input restrictions of a specific field, such as the input length, input type = ).
That is, try not to limit the input.
For a string 'str', the output direction is as follows:
1. Output to HTML, Function fn_chk_to_html (Str)
2. Output to Script (such as javascript), Function fn_chk_to_script (Str)
3. Output to the SQL statement, and this SQL statement uses ''to enclose the string 'str.
Function fn_chk_to_ SQL _mark (Str)
4. Output to the SQL statement, and this SQL statement does not include Str. Function fn_chk_to_ SQL _go (Str)
5. Output to URL. Function fn_chk_to_url (Str)
<% Function fn_chk_to_html (Str)
'Example: <input text = "<% = request (" styledesc ") %>">
If Isnull (Str) Then
ChkSql = ""
Exit Function
End If
Str = trim (Str)
Str = Replace (Str, Chr (0), "", 1,-1, 1)
Str = Replace (Str, "," & quot; ", 1,-1, 1)
Str = Replace (Str, "'", "& #039;", 1,-1, 1)
Str = Replace (Str, "<", "& lt;", 1,-1, 1)
Str = Replace (Str, ">", "& gt;", 1,-1, 1)
Str = Replace (Str, vbCrlf, "<br>", 1,-1, 1)
Fn_chk_to_html = Str
End Function
%>
<% Function fn_chk_to_script (Str)
'Response. write "<script> alert ('" & request ("styledesc") & "'); </script>"
If Isnull (Str) Then
ChkSql = ""
Exit Function
End If
Str = trim (Str)
Str = Replace (Str, "", "", 1,-1, 1)
Str = Replace (Str, ",", 1,-1, 1)
Str = Replace (Str, "'", "'", 1,-1, 1)
Str = Replace (Str, Chr (13), "", 1,-1, 1)
Fn_chk_to_script = Str
End Function
%>
<%
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service