Accade spesso che durante la scrittura delle nostre pagine non si tenga conto delle varie problematiche relative alla sicurezza. Uno dei modi per ottenere delle informazioni sulle pagine è quello di riuscire a mandarle in errore con la speranza di, attraverso la descrizione a video dell'errore, avere ulteriori informazioni utili per un attacco più deciso al sito. Uno dei modi che potrebbero aiutare a contrastare questi primi tentativi, consiste nell'utilizzare delle funzioni che controllino i valori passati alle pagine. Qui sotto sono riportati alcuni esempi che possono essere utilizzati per recuperare sia valori numerici che valori alfanumerici. I valori restituiti dovrebbero essere depurati da sequenze di caratteri che potrebbero corrompere le nostre query o altre elaborazioni lato server. Queste funzioni non garantiscono la sicurezza ma possono essere utilizzate come punto di partenza per affrontare il problema.
function requestNumber (argName, defaultValue, minValue, maxValue)
dim sResult, sValue
sValue = Request(argName)
if not IsNumeric(defaultValue) then defaultValue = 0
if not IsNumeric(sValue) then
sResult = defaultValue
else
if CDbl(sValue) >= CDbl(minValue) and CDbl(sValue) <= CDbl(maxValue) then
sResult = sValue
else
sResult = defaultValue
end if
end if
requestNumber = Server.HTMLEncode(clearParameter(sResult))
end function
function requestString (argName, defaultValue, minLength, maxLength)
dim sResult, sValue
sValue = Request(argName)
sResult = ""
if Trim(minLength) = "" then minLength = 0
if Trim(maxLength) = "" then maxLength = 0
if Trim(sValue) = "" then
sResult = defaultValue
else
if Len(sValue) >= minLength and Len(sValue) <= maxLength then
sResult = Trim(sValue)
else
sResult = Trim(left(defaultValue,1,maxLength))
end if
end if
requestString = Server.HTMLEncode(clearParameter(sResult))
end function
Function clearParameter(inputStr)
outStr=replace(inputStr,"'","''")
outStr=replace(outStr, """", "")
outStr=replace(outStr, ")", "" )
outStr=replace(outStr, "(", "" )
outStr=replace(outStr, ";", "" )
outStr=replace(outStr, "--", "" )
outStr=replace(outStr, "|", "" )
outStr=replace(outStr, ">", "" )
outStr=replace(outStr, "<", "" )
outStr=replace(outStr, "`", "")
outStr=replace(outStr, ",", "")
PurgeInputParam = outStr
End Function